History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf

Daniel Borkmann says: ==================== pull-request: bpf 2021-07-29 The following pull-request contains BPF updates for your *net* tree. We've added 9 non-merge commits during the last 14 day(s) which contain a total of 20 files changed, 446 insertions(+), 138 deletions(-). The main changes are: 1) Fix UBSAN out-of-bounds splat for showing XDP link fdinfo, from Lorenz Bauer. 2) Fix insufficient Spectre v4 mitigation in BPF runtime, from Daniel Borkmann, Piotr Krysiuk and Benedict Schlueter. 3) Batch of fixes for BPF sockmap found under stress testing, from John Fastabend. ====================

David S. Miller committed 5 years ago

Commit fc16a532 parents 89fb62f 2039f2620 files · +446 −138Browse files

Unified · Split

20 files
  1. arch/arm/net/bpf_jit_32.c +3 −0
  2. arch/arm64/net/bpf_jit_comp.c +13 −0
  3. arch/mips/net/ebpf_jit.c +3 −0
  4. arch/powerpc/net/bpf_jit_comp32.c +6 −0
  5. arch/powerpc/net/bpf_jit_comp64.c +6 −0
  6. arch/riscv/net/bpf_jit_comp32.c +4 −0
  7. arch/riscv/net/bpf_jit_comp64.c +4 −0
  8. arch/s390/net/bpf_jit_comp.c +5 −0
  9. arch/sparc/net/bpf_jit_comp_64.c +3 −0
  10. arch/x86/net/bpf_jit_comp.c +7 −0
  11. arch/x86/net/bpf_jit_comp32.c +6 −0
  12. include/linux/bpf_types.h +1 −0
  13. include/linux/bpf_verifier.h +2 −1
  14. include/linux/filter.h +15 −0
  15. include/linux/skmsg.h +35 −19
  16. kernel/bpf/core.c +18 −1
  17. kernel/bpf/disasm.c +9 −7
  18. kernel/bpf/verifier.c +49 −99
  19. net/core/skmsg.c +28 −11
  20. tools/testing/selftests/bpf/verifier/value_ptr_arith.c +229 −0
arch/arm/net/bpf_jit_32.c+3−0
@@ -1602,6 +1602,9 @@ exit: · 1601 unmodified lines
1602 rn = arm_bpf_get_reg32(src_lo, tmp2[1], ctx);1602 rn = arm_bpf_get_reg32(src_lo, tmp2[1], ctx);
1603 emit_ldx_r(dst, rn, off, ctx, BPF_SIZE(code));1603 emit_ldx_r(dst, rn, off, ctx, BPF_SIZE(code));
1604 break;1604 break;
1605 /* speculation barrier */
1606 case BPF_ST | BPF_NOSPEC:
1607 break;
1605 /* ST: *(size *)(dst + off) = imm */1608 /* ST: *(size *)(dst + off) = imm */
1606 case BPF_ST | BPF_MEM | BPF_W:1609 case BPF_ST | BPF_MEM | BPF_W:
1607 case BPF_ST | BPF_MEM | BPF_H:1610 case BPF_ST | BPF_MEM | BPF_H:
arch/arm64/net/bpf_jit_comp.c+13−0
@@ -823,6 +823,19 @@ emit_cond_jmp: · 822 unmodified lines
823 return ret;823 return ret;
824 break;824 break;
825 825
826 /* speculation barrier */
827 case BPF_ST | BPF_NOSPEC:
828 /*
829 * Nothing required here.
830 *
831 * In case of arm64, we rely on the firmware mitigation of
832 * Speculative Store Bypass as controlled via the ssbd kernel
833 * parameter. Whenever the mitigation is enabled, it works
834 * for all of the kernel code with no need to provide any
835 * additional instructions.
836 */
837 break;
838
826 /* ST: *(size *)(dst + off) = imm */839 /* ST: *(size *)(dst + off) = imm */
827 case BPF_ST | BPF_MEM | BPF_W:840 case BPF_ST | BPF_MEM | BPF_W:
828 case BPF_ST | BPF_MEM | BPF_H:841 case BPF_ST | BPF_MEM | BPF_H:
arch/mips/net/ebpf_jit.c+3−0
@@ -1355,6 +1355,9 @@ jeq_common: · 1354 unmodified lines
1355 }1355 }
1356 break;1356 break;
1357 1357
1358 case BPF_ST | BPF_NOSPEC: /* speculation barrier */
1359 break;
1360
1358 case BPF_ST | BPF_B | BPF_MEM:1361 case BPF_ST | BPF_B | BPF_MEM:
1359 case BPF_ST | BPF_H | BPF_MEM:1362 case BPF_ST | BPF_H | BPF_MEM:
1360 case BPF_ST | BPF_W | BPF_MEM:1363 case BPF_ST | BPF_W | BPF_MEM:
arch/powerpc/net/bpf_jit_comp32.c+6−0
@@ -737,6 +737,12 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context * · 736 unmodified lines
737 }737 }
738 break;738 break;
739 739
740 /*
741 * BPF_ST NOSPEC (speculation barrier)
742 */
743 case BPF_ST | BPF_NOSPEC:
744 break;
745
740 /*746 /*
741 * BPF_ST(X)747 * BPF_ST(X)
742 */748 */
arch/powerpc/net/bpf_jit_comp64.c+6−0
@@ -627,6 +627,12 @@ emit_clear: · 626 unmodified lines
627 }627 }
628 break;628 break;
629 629
630 /*
631 * BPF_ST NOSPEC (speculation barrier)
632 */
633 case BPF_ST | BPF_NOSPEC:
634 break;
635
630 /*636 /*
631 * BPF_ST(X)637 * BPF_ST(X)
632 */638 */
arch/riscv/net/bpf_jit_comp32.c+4−0
@@ -1251,6 +1251,10 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx, · 1250 unmodified lines
1251 return -1;1251 return -1;
1252 break;1252 break;
1253 1253
1254 /* speculation barrier */
1255 case BPF_ST | BPF_NOSPEC:
1256 break;
1257
1254 case BPF_ST | BPF_MEM | BPF_B:1258 case BPF_ST | BPF_MEM | BPF_B:
1255 case BPF_ST | BPF_MEM | BPF_H:1259 case BPF_ST | BPF_MEM | BPF_H:
1256 case BPF_ST | BPF_MEM | BPF_W:1260 case BPF_ST | BPF_MEM | BPF_W:
arch/riscv/net/bpf_jit_comp64.c+4−0
@@ -939,6 +939,10 @@ out_be: · 938 unmodified lines
939 emit_ld(rd, 0, RV_REG_T1, ctx);939 emit_ld(rd, 0, RV_REG_T1, ctx);
940 break;940 break;
941 941
942 /* speculation barrier */
943 case BPF_ST | BPF_NOSPEC:
944 break;
945
942 /* ST: *(size *)(dst + off) = imm */946 /* ST: *(size *)(dst + off) = imm */
943 case BPF_ST | BPF_MEM | BPF_B:947 case BPF_ST | BPF_MEM | BPF_B:
944 emit_imm(RV_REG_T1, imm, ctx);948 emit_imm(RV_REG_T1, imm, ctx);
arch/s390/net/bpf_jit_comp.c+5−0
@@ -1153,6 +1153,11 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, · 1152 unmodified lines
1153 break;1153 break;
1154 }1154 }
1155 break;1155 break;
1156 /*
1157 * BPF_NOSPEC (speculation barrier)
1158 */
1159 case BPF_ST | BPF_NOSPEC:
1160 break;
1156 /*1161 /*
1157 * BPF_ST(X)1162 * BPF_ST(X)
1158 */1163 */
arch/sparc/net/bpf_jit_comp_64.c+3−0
@@ -1287,6 +1287,9 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx) · 1286 unmodified lines
1287 return 1;1287 return 1;
1288 break;1288 break;
1289 }1289 }
1290 /* speculation barrier */
1291 case BPF_ST | BPF_NOSPEC:
1292 break;
1290 /* ST: *(size *)(dst + off) = imm */1293 /* ST: *(size *)(dst + off) = imm */
1291 case BPF_ST | BPF_MEM | BPF_W:1294 case BPF_ST | BPF_MEM | BPF_W:
1292 case BPF_ST | BPF_MEM | BPF_H:1295 case BPF_ST | BPF_MEM | BPF_H:
arch/x86/net/bpf_jit_comp.c+7−0
@@ -1219,6 +1219,13 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, · 1218 unmodified lines
1219 }1219 }
1220 break;1220 break;
1221 1221
1222 /* speculation barrier */
1223 case BPF_ST | BPF_NOSPEC:
1224 if (boot_cpu_has(X86_FEATURE_XMM2))
1225 /* Emit 'lfence' */
1226 EMIT3(0x0F, 0xAE, 0xE8);
1227 break;
1228
1222 /* ST: *(u8*)(dst_reg + off) = imm */1229 /* ST: *(u8*)(dst_reg + off) = imm */
1223 case BPF_ST | BPF_MEM | BPF_B:1230 case BPF_ST | BPF_MEM | BPF_B:
1224 if (is_ereg(dst_reg))1231 if (is_ereg(dst_reg))
arch/x86/net/bpf_jit_comp32.c+6−0
@@ -1886,6 +1886,12 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, · 1885 unmodified lines
1886 i++;1886 i++;
1887 break;1887 break;
1888 }1888 }
1889 /* speculation barrier */
1890 case BPF_ST | BPF_NOSPEC:
1891 if (boot_cpu_has(X86_FEATURE_XMM2))
1892 /* Emit 'lfence' */
1893 EMIT3(0x0F, 0xAE, 0xE8);
1894 break;
1889 /* ST: *(u8*)(dst_reg + off) = imm */1895 /* ST: *(u8*)(dst_reg + off) = imm */
1890 case BPF_ST | BPF_MEM | BPF_H:1896 case BPF_ST | BPF_MEM | BPF_H:
1891 case BPF_ST | BPF_MEM | BPF_B:1897 case BPF_ST | BPF_MEM | BPF_B:
include/linux/bpf_types.h+1−0
@@ -134,4 +134,5 @@ BPF_LINK_TYPE(BPF_LINK_TYPE_CGROUP, cgroup) · 133 unmodified lines
134BPF_LINK_TYPE(BPF_LINK_TYPE_ITER, iter)134BPF_LINK_TYPE(BPF_LINK_TYPE_ITER, iter)
135#ifdef CONFIG_NET135#ifdef CONFIG_NET
136BPF_LINK_TYPE(BPF_LINK_TYPE_NETNS, netns)136BPF_LINK_TYPE(BPF_LINK_TYPE_NETNS, netns)
137BPF_LINK_TYPE(BPF_LINK_TYPE_XDP, xdp)
137#endif138#endif
include/linux/bpf_verifier.h+2−1
@@ -340,8 +340,8 @@ struct bpf_insn_aux_data { · 339 unmodified lines
340 };340 };
341 u64 map_key_state; /* constant (32 bit) key tracking for maps */341 u64 map_key_state; /* constant (32 bit) key tracking for maps */
342 int ctx_field_size; /* the ctx field size for load insn, maybe 0 */342 int ctx_field_size; /* the ctx field size for load insn, maybe 0 */
343 int sanitize_stack_off; /* stack slot to be cleared */
344 u32 seen; /* this insn was processed by the verifier at env->pass_cnt */343 u32 seen; /* this insn was processed by the verifier at env->pass_cnt */
344 bool sanitize_stack_spill; /* subject to Spectre v4 sanitation */
345 bool zext_dst; /* this insn zero extends dst reg */345 bool zext_dst; /* this insn zero extends dst reg */
346 u8 alu_state; /* used in combination with alu_limit */346 u8 alu_state; /* used in combination with alu_limit */
347 347
@@ -414,6 +414,7 @@ struct bpf_verifier_env { · 66 unmodified lines
414 u32 used_map_cnt; /* number of used maps */414 u32 used_map_cnt; /* number of used maps */
415 u32 used_btf_cnt; /* number of used BTF objects */415 u32 used_btf_cnt; /* number of used BTF objects */
416 u32 id_gen; /* used to generate unique reg IDs */416 u32 id_gen; /* used to generate unique reg IDs */
417 bool explore_alu_limits;
417 bool allow_ptr_leaks;418 bool allow_ptr_leaks;
418 bool allow_uninit_stack;419 bool allow_uninit_stack;
419 bool allow_ptr_to_map_access;420 bool allow_ptr_to_map_access;
include/linux/filter.h+15−0
@@ -73,6 +73,11 @@ struct ctl_table_header; · 72 unmodified lines
73/* unused opcode to mark call to interpreter with arguments */73/* unused opcode to mark call to interpreter with arguments */
74#define BPF_CALL_ARGS 0xe074#define BPF_CALL_ARGS 0xe0
75 75
76/* unused opcode to mark speculation barrier for mitigating
77 * Speculative Store Bypass
78 */
79#define BPF_NOSPEC 0xc0
80
76/* As per nm, we expose JITed images as text (code) section for81/* As per nm, we expose JITed images as text (code) section for
77 * kallsyms. That way, tools like perf can find it to match82 * kallsyms. That way, tools like perf can find it to match
78 * addresses.83 * addresses.
@@ -390,6 +395,16 @@ static inline bool insn_is_zext(const struct bpf_insn *insn) · 311 unmodified lines
390 .off = 0, \395 .off = 0, \
391 .imm = 0 })396 .imm = 0 })
392 397
398/* Speculation barrier */
399
400#define BPF_ST_NOSPEC() \
401 ((struct bpf_insn) { \
402 .code = BPF_ST | BPF_NOSPEC, \
403 .dst_reg = 0, \
404 .src_reg = 0, \
405 .off = 0, \
406 .imm = 0 })
407
393/* Internal classic blocks for direct assignment */408/* Internal classic blocks for direct assignment */
394 409
395#define __BPF_STMT(CODE, K) \410#define __BPF_STMT(CODE, K) \
include/linux/skmsg.h+35−19
@@ -285,11 +285,45 @@ static inline struct sk_psock *sk_psock(const struct sock *sk) · 284 unmodified lines
285 return rcu_dereference_sk_user_data(sk);285 return rcu_dereference_sk_user_data(sk);
286}286}
287 287
288static inline void sk_psock_set_state(struct sk_psock *psock,
289 enum sk_psock_state_bits bit)
290{
291 set_bit(bit, &psock->state);
292}
293
294static inline void sk_psock_clear_state(struct sk_psock *psock,
295 enum sk_psock_state_bits bit)
296{
297 clear_bit(bit, &psock->state);
298}
299
300static inline bool sk_psock_test_state(const struct sk_psock *psock,
301 enum sk_psock_state_bits bit)
302{
303 return test_bit(bit, &psock->state);
304}
305
306static inline void sock_drop(struct sock *sk, struct sk_buff *skb)
307{
308 sk_drops_add(sk, skb);
309 kfree_skb(skb);
310}
311
312static inline void drop_sk_msg(struct sk_psock *psock, struct sk_msg *msg)
313{
314 if (msg->skb)
315 sock_drop(psock->sk, msg->skb);
316 kfree(msg);
317}
318
288static inline void sk_psock_queue_msg(struct sk_psock *psock,319static inline void sk_psock_queue_msg(struct sk_psock *psock,
289 struct sk_msg *msg)320 struct sk_msg *msg)
290{321{
291 spin_lock_bh(&psock->ingress_lock);322 spin_lock_bh(&psock->ingress_lock);
292 list_add_tail(&msg->list, &psock->ingress_msg);323 if (sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED))
324 list_add_tail(&msg->list, &psock->ingress_msg);
325 else
326 drop_sk_msg(psock, msg);
293 spin_unlock_bh(&psock->ingress_lock);327 spin_unlock_bh(&psock->ingress_lock);
294}328}
295 329
@@ -406,24 +440,6 @@ static inline void sk_psock_restore_proto(struct sock *sk, · 110 unmodified lines
406 psock->psock_update_sk_prot(sk, psock, true);440 psock->psock_update_sk_prot(sk, psock, true);
407}441}
408 442
409static inline void sk_psock_set_state(struct sk_psock *psock,
410 enum sk_psock_state_bits bit)
411{
412 set_bit(bit, &psock->state);
413}
414
415static inline void sk_psock_clear_state(struct sk_psock *psock,
416 enum sk_psock_state_bits bit)
417{
418 clear_bit(bit, &psock->state);
419}
420
421static inline bool sk_psock_test_state(const struct sk_psock *psock,
422 enum sk_psock_state_bits bit)
423{
424 return test_bit(bit, &psock->state);
425}
426
427static inline struct sk_psock *sk_psock_get(struct sock *sk)443static inline struct sk_psock *sk_psock_get(struct sock *sk)
428{444{
429 struct sk_psock *psock;445 struct sk_psock *psock;
kernel/bpf/core.c+18−1
@@ -32,6 +32,8 @@ · 31 unmodified lines
32#include <linux/perf_event.h>32#include <linux/perf_event.h>
33#include <linux/extable.h>33#include <linux/extable.h>
34#include <linux/log2.h>34#include <linux/log2.h>
35
36#include <asm/barrier.h>
35#include <asm/unaligned.h>37#include <asm/unaligned.h>
36 38
37/* Registers */39/* Registers */
@@ -1377,6 +1379,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn) · 1339 unmodified lines
1377 /* Non-UAPI available opcodes. */1379 /* Non-UAPI available opcodes. */
1378 [BPF_JMP | BPF_CALL_ARGS] = &&JMP_CALL_ARGS,1380 [BPF_JMP | BPF_CALL_ARGS] = &&JMP_CALL_ARGS,
1379 [BPF_JMP | BPF_TAIL_CALL] = &&JMP_TAIL_CALL,1381 [BPF_JMP | BPF_TAIL_CALL] = &&JMP_TAIL_CALL,
1382 [BPF_ST | BPF_NOSPEC] = &&ST_NOSPEC,
1380 [BPF_LDX | BPF_PROBE_MEM | BPF_B] = &&LDX_PROBE_MEM_B,1383 [BPF_LDX | BPF_PROBE_MEM | BPF_B] = &&LDX_PROBE_MEM_B,
1381 [BPF_LDX | BPF_PROBE_MEM | BPF_H] = &&LDX_PROBE_MEM_H,1384 [BPF_LDX | BPF_PROBE_MEM | BPF_H] = &&LDX_PROBE_MEM_H,
1382 [BPF_LDX | BPF_PROBE_MEM | BPF_W] = &&LDX_PROBE_MEM_W,1385 [BPF_LDX | BPF_PROBE_MEM | BPF_W] = &&LDX_PROBE_MEM_W,
@@ -1621,7 +1624,21 @@ out: · 238 unmodified lines
1621 COND_JMP(s, JSGE, >=)1624 COND_JMP(s, JSGE, >=)
1622 COND_JMP(s, JSLE, <=)1625 COND_JMP(s, JSLE, <=)
1623#undef COND_JMP1626#undef COND_JMP
1624 /* STX and ST and LDX*/1627 /* ST, STX and LDX*/
1628 ST_NOSPEC:
1629 /* Speculation barrier for mitigating Speculative Store Bypass.
1630 * In case of arm64, we rely on the firmware mitigation as
1631 * controlled via the ssbd kernel parameter. Whenever the
1632 * mitigation is enabled, it works for all of the kernel code
1633 * with no need to provide any additional instructions here.
1634 * In case of x86, we use 'lfence' insn for mitigation. We
1635 * reuse preexisting logic from Spectre v1 mitigation that
1636 * happens to produce the required code on x86 for v4 as well.
1637 */
1638#ifdef CONFIG_X86
1639 barrier_nospec();
1640#endif
1641 CONT;
1625#define LDST(SIZEOP, SIZE) \1642#define LDST(SIZEOP, SIZE) \
1626 STX_MEM_##SIZEOP: \1643 STX_MEM_##SIZEOP: \
1627 *(SIZE *)(unsigned long) (DST + insn->off) = SRC; \1644 *(SIZE *)(unsigned long) (DST + insn->off) = SRC; \
kernel/bpf/disasm.c+9−7
@@ -206,15 +206,17 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs, · 205 unmodified lines
206 verbose(cbs->private_data, "BUG_%02x\n", insn->code);206 verbose(cbs->private_data, "BUG_%02x\n", insn->code);
207 }207 }
208 } else if (class == BPF_ST) {208 } else if (class == BPF_ST) {
209 if (BPF_MODE(insn->code) != BPF_MEM) {209 if (BPF_MODE(insn->code) == BPF_MEM) {
210 verbose(cbs->private_data, "(%02x) *(%s *)(r%d %+d) = %d\n",
211 insn->code,
212 bpf_ldst_string[BPF_SIZE(insn->code) >> 3],
213 insn->dst_reg,
214 insn->off, insn->imm);
215 } else if (BPF_MODE(insn->code) == 0xc0 /* BPF_NOSPEC, no UAPI */) {
216 verbose(cbs->private_data, "(%02x) nospec\n", insn->code);
217 } else {
210 verbose(cbs->private_data, "BUG_st_%02x\n", insn->code);218 verbose(cbs->private_data, "BUG_st_%02x\n", insn->code);
211 return;
212 }219 }
213 verbose(cbs->private_data, "(%02x) *(%s *)(r%d %+d) = %d\n",
214 insn->code,
215 bpf_ldst_string[BPF_SIZE(insn->code) >> 3],
216 insn->dst_reg,
217 insn->off, insn->imm);
218 } else if (class == BPF_LDX) {220 } else if (class == BPF_LDX) {
219 if (BPF_MODE(insn->code) != BPF_MEM) {221 if (BPF_MODE(insn->code) != BPF_MEM) {
220 verbose(cbs->private_data, "BUG_ldx_%02x\n", insn->code);222 verbose(cbs->private_data, "BUG_ldx_%02x\n", insn->code);
kernel/bpf/verifier.c+49−99
@@ -2610,6 +2610,19 @@ static int check_stack_write_fixed_off(struct bpf_verifier_env *env, · 2609 unmodified lines
2610 cur = env->cur_state->frame[env->cur_state->curframe];2610 cur = env->cur_state->frame[env->cur_state->curframe];
2611 if (value_regno >= 0)2611 if (value_regno >= 0)
2612 reg = &cur->regs[value_regno];2612 reg = &cur->regs[value_regno];
2613 if (!env->bypass_spec_v4) {
2614 bool sanitize = reg && is_spillable_regtype(reg->type);
2615
2616 for (i = 0; i < size; i++) {
2617 if (state->stack[spi].slot_type[i] == STACK_INVALID) {
2618 sanitize = true;
2619 break;
2620 }
2621 }
2622
2623 if (sanitize)
2624 env->insn_aux_data[insn_idx].sanitize_stack_spill = true;
2625 }
2613 2626
2614 if (reg && size == BPF_REG_SIZE && register_is_bounded(reg) &&2627 if (reg && size == BPF_REG_SIZE && register_is_bounded(reg) &&
2615 !register_is_null(reg) && env->bpf_capable) {2628 !register_is_null(reg) && env->bpf_capable) {
@@ -2632,47 +2645,10 @@ static int check_stack_write_fixed_off(struct bpf_verifier_env *env, · 16 unmodified lines
2632 verbose(env, "invalid size of register spill\n");2645 verbose(env, "invalid size of register spill\n");
2633 return -EACCES;2646 return -EACCES;
2634 }2647 }
2635
2636 if (state != cur && reg->type == PTR_TO_STACK) {2648 if (state != cur && reg->type == PTR_TO_STACK) {
2637 verbose(env, "cannot spill pointers to stack into stack frame of the caller\n");2649 verbose(env, "cannot spill pointers to stack into stack frame of the caller\n");
2638 return -EINVAL;2650 return -EINVAL;
2639 }2651 }
2640
2641 if (!env->bypass_spec_v4) {
2642 bool sanitize = false;
2643
2644 if (state->stack[spi].slot_type[0] == STACK_SPILL &&
2645 register_is_const(&state->stack[spi].spilled_ptr))
2646 sanitize = true;
2647 for (i = 0; i < BPF_REG_SIZE; i++)
2648 if (state->stack[spi].slot_type[i] == STACK_MISC) {
2649 sanitize = true;
2650 break;
2651 }
2652 if (sanitize) {
2653 int *poff = &env->insn_aux_data[insn_idx].sanitize_stack_off;
2654 int soff = (-spi - 1) * BPF_REG_SIZE;
2655
2656 /* detected reuse of integer stack slot with a pointer
2657 * which means either llvm is reusing stack slot or
2658 * an attacker is trying to exploit CVE-2018-3639
2659 * (speculative store bypass)
2660 * Have to sanitize that slot with preemptive
2661 * store of zero.
2662 */
2663 if (*poff && *poff != soff) {
2664 /* disallow programs where single insn stores
2665 * into two different stack slots, since verifier
2666 * cannot sanitize them
2667 */
2668 verbose(env,
2669 "insn %d cannot access two stack slots fp%d and fp%d",
2670 insn_idx, *poff, soff);
2671 return -EINVAL;
2672 }
2673 *poff = soff;
2674 }
2675 }
2676 save_register_state(state, spi, reg);2652 save_register_state(state, spi, reg);
2677 } else {2653 } else {
2678 u8 type = STACK_MISC;2654 u8 type = STACK_MISC;
@@ -6561,6 +6537,12 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env, · 3882 unmodified lines
6561 alu_state |= off_is_imm ? BPF_ALU_IMMEDIATE : 0;6537 alu_state |= off_is_imm ? BPF_ALU_IMMEDIATE : 0;
6562 alu_state |= ptr_is_dst_reg ?6538 alu_state |= ptr_is_dst_reg ?
6563 BPF_ALU_SANITIZE_SRC : BPF_ALU_SANITIZE_DST;6539 BPF_ALU_SANITIZE_SRC : BPF_ALU_SANITIZE_DST;
6540
6541 /* Limit pruning on unknown scalars to enable deep search for
6542 * potential masking differences from other program paths.
6543 */
6544 if (!off_is_imm)
6545 env->explore_alu_limits = true;
6564 }6546 }
6565 6547
6566 err = update_alu_sanitation_state(aux, alu_state, alu_limit);6548 err = update_alu_sanitation_state(aux, alu_state, alu_limit);
@@ -9936,8 +9918,8 @@ next: · 3369 unmodified lines
9936}9918}
9937 9919
9938/* Returns true if (rold safe implies rcur safe) */9920/* Returns true if (rold safe implies rcur safe) */
9939static bool regsafe(struct bpf_reg_state *rold, struct bpf_reg_state *rcur,9921static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
9940 struct bpf_id_pair *idmap)9922 struct bpf_reg_state *rcur, struct bpf_id_pair *idmap)
9941{9923{
9942 bool equal;9924 bool equal;
9943 9925
@@ -9963,6 +9945,8 @@ static bool regsafe(struct bpf_reg_state *rold, struct bpf_reg_state *rcur, · 19 unmodified lines
9963 return false;9945 return false;
9964 switch (rold->type) {9946 switch (rold->type) {
9965 case SCALAR_VALUE:9947 case SCALAR_VALUE:
9948 if (env->explore_alu_limits)
9949 return false;
9966 if (rcur->type == SCALAR_VALUE) {9950 if (rcur->type == SCALAR_VALUE) {
9967 if (!rold->precise && !rcur->precise)9951 if (!rold->precise && !rcur->precise)
9968 return true;9952 return true;
@@ -10053,9 +10037,8 @@ static bool regsafe(struct bpf_reg_state *rold, struct bpf_reg_state *rcur, · 84 unmodified lines
10053 return false;10037 return false;
10054}10038}
10055 10039
10056static bool stacksafe(struct bpf_func_state *old,10040static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old,
10057 struct bpf_func_state *cur,10041 struct bpf_func_state *cur, struct bpf_id_pair *idmap)
10058 struct bpf_id_pair *idmap)
10059{10042{
10060 int i, spi;10043 int i, spi;
10061 10044
@@ -10100,9 +10083,8 @@ static bool stacksafe(struct bpf_func_state *old, · 38 unmodified lines
10100 continue;10083 continue;
10101 if (old->stack[spi].slot_type[0] != STACK_SPILL)10084 if (old->stack[spi].slot_type[0] != STACK_SPILL)
10102 continue;10085 continue;
10103 if (!regsafe(&old->stack[spi].spilled_ptr,10086 if (!regsafe(env, &old->stack[spi].spilled_ptr,
10104 &cur->stack[spi].spilled_ptr,10087 &cur->stack[spi].spilled_ptr, idmap))
10105 idmap))
10106 /* when explored and current stack slot are both storing10088 /* when explored and current stack slot are both storing
10107 * spilled registers, check that stored pointers types10089 * spilled registers, check that stored pointers types
10108 * are the same as well.10090 * are the same as well.
@@ -10159,10 +10141,11 @@ static bool func_states_equal(struct bpf_verifier_env *env, struct bpf_func_stat · 50 unmodified lines
10159 10141
10160 memset(env->idmap_scratch, 0, sizeof(env->idmap_scratch));10142 memset(env->idmap_scratch, 0, sizeof(env->idmap_scratch));
10161 for (i = 0; i < MAX_BPF_REG; i++)10143 for (i = 0; i < MAX_BPF_REG; i++)
10162 if (!regsafe(&old->regs[i], &cur->regs[i], env->idmap_scratch))10144 if (!regsafe(env, &old->regs[i], &cur->regs[i],
10145 env->idmap_scratch))
10163 return false;10146 return false;
10164 10147
10165 if (!stacksafe(old, cur, env->idmap_scratch))10148 if (!stacksafe(env, old, cur, env->idmap_scratch))
10166 return false;10149 return false;
10167 10150
10168 if (!refsafe(old, cur))10151 if (!refsafe(old, cur))
@@ -11906,35 +11889,33 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env) · 1737 unmodified lines
11906 11889
11907 for (i = 0; i < insn_cnt; i++, insn++) {11890 for (i = 0; i < insn_cnt; i++, insn++) {
11908 bpf_convert_ctx_access_t convert_ctx_access;11891 bpf_convert_ctx_access_t convert_ctx_access;
11892 bool ctx_access;
11909 11893
11910 if (insn->code == (BPF_LDX | BPF_MEM | BPF_B) ||11894 if (insn->code == (BPF_LDX | BPF_MEM | BPF_B) ||
11911 insn->code == (BPF_LDX | BPF_MEM | BPF_H) ||11895 insn->code == (BPF_LDX | BPF_MEM | BPF_H) ||
11912 insn->code == (BPF_LDX | BPF_MEM | BPF_W) ||11896 insn->code == (BPF_LDX | BPF_MEM | BPF_W) ||
11913 insn->code == (BPF_LDX | BPF_MEM | BPF_DW))11897 insn->code == (BPF_LDX | BPF_MEM | BPF_DW)) {
11914 type = BPF_READ;11898 type = BPF_READ;
11915 else if (insn->code == (BPF_STX | BPF_MEM | BPF_B) ||11899 ctx_access = true;
11916 insn->code == (BPF_STX | BPF_MEM | BPF_H) ||11900 } else if (insn->code == (BPF_STX | BPF_MEM | BPF_B) ||
11917 insn->code == (BPF_STX | BPF_MEM | BPF_W) ||11901 insn->code == (BPF_STX | BPF_MEM | BPF_H) ||
11918 insn->code == (BPF_STX | BPF_MEM | BPF_DW))11902 insn->code == (BPF_STX | BPF_MEM | BPF_W) ||
11903 insn->code == (BPF_STX | BPF_MEM | BPF_DW) ||
11904 insn->code == (BPF_ST | BPF_MEM | BPF_B) ||
11905 insn->code == (BPF_ST | BPF_MEM | BPF_H) ||
11906 insn->code == (BPF_ST | BPF_MEM | BPF_W) ||
11907 insn->code == (BPF_ST | BPF_MEM | BPF_DW)) {
11919 type = BPF_WRITE;11908 type = BPF_WRITE;
11920 else11909 ctx_access = BPF_CLASS(insn->code) == BPF_STX;
11910 } else {
11921 continue;11911 continue;
11912 }
11922 11913
11923 if (type == BPF_WRITE &&11914 if (type == BPF_WRITE &&
11924 env->insn_aux_data[i + delta].sanitize_stack_off) {11915 env->insn_aux_data[i + delta].sanitize_stack_spill) {
11925 struct bpf_insn patch[] = {11916 struct bpf_insn patch[] = {
11926 /* Sanitize suspicious stack slot with zero.
11927 * There are no memory dependencies for this store,
11928 * since it's only using frame pointer and immediate
11929 * constant of zero
11930 */
11931 BPF_ST_MEM(BPF_DW, BPF_REG_FP,
11932 env->insn_aux_data[i + delta].sanitize_stack_off,
11933 0),
11934 /* the original STX instruction will immediately
11935 * overwrite the same stack slot with appropriate value
11936 */
11937 *insn,11917 *insn,
11918 BPF_ST_NOSPEC(),
11938 };11919 };
11939 11920
11940 cnt = ARRAY_SIZE(patch);11921 cnt = ARRAY_SIZE(patch);
@@ -11948,6 +11929,9 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env) · 7 unmodified lines
11948 continue;11929 continue;
11949 }11930 }
11950 11931
11932 if (!ctx_access)
11933 continue;
11934
11951 switch (env->insn_aux_data[i + delta].ptr_type) {11935 switch (env->insn_aux_data[i + delta].ptr_type) {
11952 case PTR_TO_CTX:11936 case PTR_TO_CTX:
11953 if (!ops->convert_ctx_access)11937 if (!ops->convert_ctx_access)
@@ -12752,37 +12736,6 @@ static void free_states(struct bpf_verifier_env *env) · 798 unmodified lines
12752 }12736 }
12753}12737}
12754 12738
12755/* The verifier is using insn_aux_data[] to store temporary data during
12756 * verification and to store information for passes that run after the
12757 * verification like dead code sanitization. do_check_common() for subprogram N
12758 * may analyze many other subprograms. sanitize_insn_aux_data() clears all
12759 * temporary data after do_check_common() finds that subprogram N cannot be
12760 * verified independently. pass_cnt counts the number of times
12761 * do_check_common() was run and insn->aux->seen tells the pass number
12762 * insn_aux_data was touched. These variables are compared to clear temporary
12763 * data from failed pass. For testing and experiments do_check_common() can be
12764 * run multiple times even when prior attempt to verify is unsuccessful.
12765 *
12766 * Note that special handling is needed on !env->bypass_spec_v1 if this is
12767 * ever called outside of error path with subsequent program rejection.
12768 */
12769static void sanitize_insn_aux_data(struct bpf_verifier_env *env)
12770{
12771 struct bpf_insn *insn = env->prog->insnsi;
12772 struct bpf_insn_aux_data *aux;
12773 int i, class;
12774
12775 for (i = 0; i < env->prog->len; i++) {
12776 class = BPF_CLASS(insn[i].code);
12777 if (class != BPF_LDX && class != BPF_STX)
12778 continue;
12779 aux = &env->insn_aux_data[i];
12780 if (aux->seen != env->pass_cnt)
12781 continue;
12782 memset(aux, 0, offsetof(typeof(*aux), orig_idx));
12783 }
12784}
12785
12786static int do_check_common(struct bpf_verifier_env *env, int subprog)12739static int do_check_common(struct bpf_verifier_env *env, int subprog)
12787{12740{
12788 bool pop_log = !(env->log.level & BPF_LOG_LEVEL2);12741 bool pop_log = !(env->log.level & BPF_LOG_LEVEL2);
@@ -12859,9 +12812,6 @@ out: · 70 unmodified lines
12859 if (!ret && pop_log)12812 if (!ret && pop_log)
12860 bpf_vlog_reset(&env->log, 0);12813 bpf_vlog_reset(&env->log, 0);
12861 free_states(env);12814 free_states(env);
12862 if (ret)
12863 /* clean aux data in case subprog was rejected */
12864 sanitize_insn_aux_data(env);
12865 return ret;12815 return ret;
12866}12816}
12867 12817
net/core/skmsg.c+28−11
@@ -584,29 +584,42 @@ static int sk_psock_handle_skb(struct sk_psock *psock, struct sk_buff *skb, · 583 unmodified lines
584 return sk_psock_skb_ingress(psock, skb);584 return sk_psock_skb_ingress(psock, skb);
585}585}
586 586
587static void sock_drop(struct sock *sk, struct sk_buff *skb)587static void sk_psock_skb_state(struct sk_psock *psock,
588 struct sk_psock_work_state *state,
589 struct sk_buff *skb,
590 int len, int off)
588{591{
589 sk_drops_add(sk, skb);592 spin_lock_bh(&psock->ingress_lock);
590 kfree_skb(skb);593 if (sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED)) {
594 state->skb = skb;
595 state->len = len;
596 state->off = off;
597 } else {
598 sock_drop(psock->sk, skb);
599 }
600 spin_unlock_bh(&psock->ingress_lock);
591}601}
592 602
593static void sk_psock_backlog(struct work_struct *work)603static void sk_psock_backlog(struct work_struct *work)
594{604{
595 struct sk_psock *psock = container_of(work, struct sk_psock, work);605 struct sk_psock *psock = container_of(work, struct sk_psock, work);
596 struct sk_psock_work_state *state = &psock->work_state;606 struct sk_psock_work_state *state = &psock->work_state;
597 struct sk_buff *skb;607 struct sk_buff *skb = NULL;
598 bool ingress;608 bool ingress;
599 u32 len, off;609 u32 len, off;
600 int ret;610 int ret;
601 611
602 mutex_lock(&psock->work_mutex);612 mutex_lock(&psock->work_mutex);
603 if (state->skb) {613 if (unlikely(state->skb)) {
614 spin_lock_bh(&psock->ingress_lock);
604 skb = state->skb;615 skb = state->skb;
605 len = state->len;616 len = state->len;
606 off = state->off;617 off = state->off;
607 state->skb = NULL;618 state->skb = NULL;
608 goto start;619 spin_unlock_bh(&psock->ingress_lock);
609 }620 }
621 if (skb)
622 goto start;
610 623
611 while ((skb = skb_dequeue(&psock->ingress_skb))) {624 while ((skb = skb_dequeue(&psock->ingress_skb))) {
612 len = skb->len;625 len = skb->len;
@@ -621,9 +634,8 @@ start: · 8 unmodified lines
621 len, ingress);634 len, ingress);
622 if (ret <= 0) {635 if (ret <= 0) {
623 if (ret == -EAGAIN) {636 if (ret == -EAGAIN) {
624 state->skb = skb;637 sk_psock_skb_state(psock, state, skb,
625 state->len = len;638 len, off);
626 state->off = off;
627 goto end;639 goto end;
628 }640 }
629 /* Hard errors break pipe and stop xmit. */641 /* Hard errors break pipe and stop xmit. */
@@ -722,6 +734,11 @@ static void __sk_psock_zap_ingress(struct sk_psock *psock) · 92 unmodified lines
722 skb_bpf_redirect_clear(skb);734 skb_bpf_redirect_clear(skb);
723 sock_drop(psock->sk, skb);735 sock_drop(psock->sk, skb);
724 }736 }
737 kfree_skb(psock->work_state.skb);
738 /* We null the skb here to ensure that calls to sk_psock_backlog
739 * do not pick up the free'd skb.
740 */
741 psock->work_state.skb = NULL;
725 __sk_psock_purge_ingress_msg(psock);742 __sk_psock_purge_ingress_msg(psock);
726}743}
727 744
@@ -773,8 +790,6 @@ static void sk_psock_destroy(struct work_struct *work) · 45 unmodified lines
773 790
774void sk_psock_drop(struct sock *sk, struct sk_psock *psock)791void sk_psock_drop(struct sock *sk, struct sk_psock *psock)
775{792{
776 sk_psock_stop(psock, false);
777
778 write_lock_bh(&sk->sk_callback_lock);793 write_lock_bh(&sk->sk_callback_lock);
779 sk_psock_restore_proto(sk, psock);794 sk_psock_restore_proto(sk, psock);
780 rcu_assign_sk_user_data(sk, NULL);795 rcu_assign_sk_user_data(sk, NULL);
@@ -784,6 +799,8 @@ void sk_psock_drop(struct sock *sk, struct sk_psock *psock) · 3 unmodified lines
784 sk_psock_stop_verdict(sk, psock);799 sk_psock_stop_verdict(sk, psock);
785 write_unlock_bh(&sk->sk_callback_lock);800 write_unlock_bh(&sk->sk_callback_lock);
786 801
802 sk_psock_stop(psock, false);
803
787 INIT_RCU_WORK(&psock->rwork, sk_psock_destroy);804 INIT_RCU_WORK(&psock->rwork, sk_psock_destroy);
788 queue_rcu_work(system_wq, &psock->rwork);805 queue_rcu_work(system_wq, &psock->rwork);
789}806}
tools/testing/selftests/bpf/verifier/value_ptr_arith.c+229−0
@@ -1,3 +1,232 @@
1{
2 "map access: known scalar += value_ptr unknown vs const",
3 .insns = {
4 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
5 offsetof(struct __sk_buff, len)),
6 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
7 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
8 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
9 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 1, 3),
10 BPF_LD_MAP_FD(BPF_REG_1, 0),
11 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 1, 2),
12 BPF_LD_MAP_FD(BPF_REG_1, 0),
13 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
14 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 9),
15 BPF_LDX_MEM(BPF_B, BPF_REG_4, BPF_REG_0, 0),
16 BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 1, 4),
17 BPF_MOV64_IMM(BPF_REG_1, 6),
18 BPF_ALU64_IMM(BPF_NEG, BPF_REG_1, 0),
19 BPF_ALU64_IMM(BPF_AND, BPF_REG_1, 0x7),
20 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
21 BPF_MOV64_IMM(BPF_REG_1, 3),
22 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
23 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, 0),
24 BPF_MOV64_IMM(BPF_REG_0, 1),
25 BPF_EXIT_INSN(),
26 },
27 .fixup_map_hash_16b = { 5 },
28 .fixup_map_array_48b = { 8 },
29 .result_unpriv = REJECT,
30 .errstr_unpriv = "R1 tried to add from different maps, paths or scalars",
31 .result = ACCEPT,
32 .retval = 1,
33},
34{
35 "map access: known scalar += value_ptr const vs unknown",
36 .insns = {
37 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
38 offsetof(struct __sk_buff, len)),
39 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
40 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
41 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
42 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 1, 3),
43 BPF_LD_MAP_FD(BPF_REG_1, 0),
44 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 1, 2),
45 BPF_LD_MAP_FD(BPF_REG_1, 0),
46 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
47 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 9),
48 BPF_LDX_MEM(BPF_B, BPF_REG_4, BPF_REG_0, 0),
49 BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 1, 2),
50 BPF_MOV64_IMM(BPF_REG_1, 3),
51 BPF_JMP_IMM(BPF_JA, 0, 0, 3),
52 BPF_MOV64_IMM(BPF_REG_1, 6),
53 BPF_ALU64_IMM(BPF_NEG, BPF_REG_1, 0),
54 BPF_ALU64_IMM(BPF_AND, BPF_REG_1, 0x7),
55 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
56 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, 0),
57 BPF_MOV64_IMM(BPF_REG_0, 1),
58 BPF_EXIT_INSN(),
59 },
60 .fixup_map_hash_16b = { 5 },
61 .fixup_map_array_48b = { 8 },
62 .result_unpriv = REJECT,
63 .errstr_unpriv = "R1 tried to add from different maps, paths or scalars",
64 .result = ACCEPT,
65 .retval = 1,
66},
67{
68 "map access: known scalar += value_ptr const vs const (ne)",
69 .insns = {
70 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
71 offsetof(struct __sk_buff, len)),
72 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
73 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
74 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
75 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 1, 3),
76 BPF_LD_MAP_FD(BPF_REG_1, 0),
77 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 1, 2),
78 BPF_LD_MAP_FD(BPF_REG_1, 0),
79 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
80 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7),
81 BPF_LDX_MEM(BPF_B, BPF_REG_4, BPF_REG_0, 0),
82 BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 1, 2),
83 BPF_MOV64_IMM(BPF_REG_1, 3),
84 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
85 BPF_MOV64_IMM(BPF_REG_1, 5),
86 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
87 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, 0),
88 BPF_MOV64_IMM(BPF_REG_0, 1),
89 BPF_EXIT_INSN(),
90 },
91 .fixup_map_hash_16b = { 5 },
92 .fixup_map_array_48b = { 8 },
93 .result_unpriv = REJECT,
94 .errstr_unpriv = "R1 tried to add from different maps, paths or scalars",
95 .result = ACCEPT,
96 .retval = 1,
97},
98{
99 "map access: known scalar += value_ptr const vs const (eq)",
100 .insns = {
101 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
102 offsetof(struct __sk_buff, len)),
103 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
104 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
105 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
106 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 1, 3),
107 BPF_LD_MAP_FD(BPF_REG_1, 0),
108 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 1, 2),
109 BPF_LD_MAP_FD(BPF_REG_1, 0),
110 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
111 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7),
112 BPF_LDX_MEM(BPF_B, BPF_REG_4, BPF_REG_0, 0),
113 BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 1, 2),
114 BPF_MOV64_IMM(BPF_REG_1, 5),
115 BPF_JMP_IMM(BPF_JA, 0, 0, 1),
116 BPF_MOV64_IMM(BPF_REG_1, 5),
117 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
118 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, 0),
119 BPF_MOV64_IMM(BPF_REG_0, 1),
120 BPF_EXIT_INSN(),
121 },
122 .fixup_map_hash_16b = { 5 },
123 .fixup_map_array_48b = { 8 },
124 .result = ACCEPT,
125 .retval = 1,
126},
127{
128 "map access: known scalar += value_ptr unknown vs unknown (eq)",
129 .insns = {
130 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
131 offsetof(struct __sk_buff, len)),
132 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
133 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
134 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
135 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 1, 3),
136 BPF_LD_MAP_FD(BPF_REG_1, 0),
137 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 1, 2),
138 BPF_LD_MAP_FD(BPF_REG_1, 0),
139 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
140 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 11),
141 BPF_LDX_MEM(BPF_B, BPF_REG_4, BPF_REG_0, 0),
142 BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 1, 4),
143 BPF_MOV64_IMM(BPF_REG_1, 6),
144 BPF_ALU64_IMM(BPF_NEG, BPF_REG_1, 0),
145 BPF_ALU64_IMM(BPF_AND, BPF_REG_1, 0x7),
146 BPF_JMP_IMM(BPF_JA, 0, 0, 3),
147 BPF_MOV64_IMM(BPF_REG_1, 6),
148 BPF_ALU64_IMM(BPF_NEG, BPF_REG_1, 0),
149 BPF_ALU64_IMM(BPF_AND, BPF_REG_1, 0x7),
150 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
151 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, 0),
152 BPF_MOV64_IMM(BPF_REG_0, 1),
153 BPF_EXIT_INSN(),
154 },
155 .fixup_map_hash_16b = { 5 },
156 .fixup_map_array_48b = { 8 },
157 .result = ACCEPT,
158 .retval = 1,
159},
160{
161 "map access: known scalar += value_ptr unknown vs unknown (lt)",
162 .insns = {
163 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
164 offsetof(struct __sk_buff, len)),
165 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
166 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
167 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
168 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 1, 3),
169 BPF_LD_MAP_FD(BPF_REG_1, 0),
170 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 1, 2),
171 BPF_LD_MAP_FD(BPF_REG_1, 0),
172 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
173 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 11),
174 BPF_LDX_MEM(BPF_B, BPF_REG_4, BPF_REG_0, 0),
175 BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 1, 4),
176 BPF_MOV64_IMM(BPF_REG_1, 6),
177 BPF_ALU64_IMM(BPF_NEG, BPF_REG_1, 0),
178 BPF_ALU64_IMM(BPF_AND, BPF_REG_1, 0x3),
179 BPF_JMP_IMM(BPF_JA, 0, 0, 3),
180 BPF_MOV64_IMM(BPF_REG_1, 6),
181 BPF_ALU64_IMM(BPF_NEG, BPF_REG_1, 0),
182 BPF_ALU64_IMM(BPF_AND, BPF_REG_1, 0x7),
183 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
184 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, 0),
185 BPF_MOV64_IMM(BPF_REG_0, 1),
186 BPF_EXIT_INSN(),
187 },
188 .fixup_map_hash_16b = { 5 },
189 .fixup_map_array_48b = { 8 },
190 .result_unpriv = REJECT,
191 .errstr_unpriv = "R1 tried to add from different maps, paths or scalars",
192 .result = ACCEPT,
193 .retval = 1,
194},
195{
196 "map access: known scalar += value_ptr unknown vs unknown (gt)",
197 .insns = {
198 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1,
199 offsetof(struct __sk_buff, len)),
200 BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
201 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
202 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
203 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 1, 3),
204 BPF_LD_MAP_FD(BPF_REG_1, 0),
205 BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 1, 2),
206 BPF_LD_MAP_FD(BPF_REG_1, 0),
207 BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
208 BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 11),
209 BPF_LDX_MEM(BPF_B, BPF_REG_4, BPF_REG_0, 0),
210 BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 1, 4),
211 BPF_MOV64_IMM(BPF_REG_1, 6),
212 BPF_ALU64_IMM(BPF_NEG, BPF_REG_1, 0),
213 BPF_ALU64_IMM(BPF_AND, BPF_REG_1, 0x7),
214 BPF_JMP_IMM(BPF_JA, 0, 0, 3),
215 BPF_MOV64_IMM(BPF_REG_1, 6),
216 BPF_ALU64_IMM(BPF_NEG, BPF_REG_1, 0),
217 BPF_ALU64_IMM(BPF_AND, BPF_REG_1, 0x3),
218 BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
219 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, 0),
220 BPF_MOV64_IMM(BPF_REG_0, 1),
221 BPF_EXIT_INSN(),
222 },
223 .fixup_map_hash_16b = { 5 },
224 .fixup_map_array_48b = { 8 },
225 .result_unpriv = REJECT,
226 .errstr_unpriv = "R1 tried to add from different maps, paths or scalars",
227 .result = ACCEPT,
228 .retval = 1,
229},
1{230{
2 "map access: known scalar += value_ptr from different maps",231 "map access: known scalar += value_ptr from different maps",
3 .insns = {232 .insns = {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t