Skip to content

Commit cf66c29

Browse files
jrfastabAlexei Starovoitov
authored andcommitted
bpf, selftests: Add a verifier test for assigning 32bit reg states to 64bit ones
Added a verifier test for assigning 32bit reg states to 64bit where 32bit reg holds a constant value of 0. Without previous kernel verifier.c fix, the test in this patch will fail. Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: John Fastabend <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/159077335867.6014.2075350327073125374.stgit@john-Precision-5820-Tower
1 parent e3effcd commit cf66c29

File tree

1 file changed

+22
-0
lines changed
  • tools/testing/selftests/bpf/verifier

1 file changed

+22
-0
lines changed

tools/testing/selftests/bpf/verifier/bounds.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,3 +535,25 @@
535535
},
536536
.result = ACCEPT
537537
},
538+
{
539+
"assigning 32bit bounds to 64bit for wA = 0, wB = wA",
540+
.insns = {
541+
BPF_LDX_MEM(BPF_W, BPF_REG_8, BPF_REG_1,
542+
offsetof(struct __sk_buff, data_end)),
543+
BPF_LDX_MEM(BPF_W, BPF_REG_7, BPF_REG_1,
544+
offsetof(struct __sk_buff, data)),
545+
BPF_MOV32_IMM(BPF_REG_9, 0),
546+
BPF_MOV32_REG(BPF_REG_2, BPF_REG_9),
547+
BPF_MOV64_REG(BPF_REG_6, BPF_REG_7),
548+
BPF_ALU64_REG(BPF_ADD, BPF_REG_6, BPF_REG_2),
549+
BPF_MOV64_REG(BPF_REG_3, BPF_REG_6),
550+
BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, 8),
551+
BPF_JMP_REG(BPF_JGT, BPF_REG_3, BPF_REG_8, 1),
552+
BPF_LDX_MEM(BPF_W, BPF_REG_5, BPF_REG_6, 0),
553+
BPF_MOV64_IMM(BPF_REG_0, 0),
554+
BPF_EXIT_INSN(),
555+
},
556+
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
557+
.result = ACCEPT,
558+
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
559+
},

0 commit comments

Comments
 (0)