Skip to content

Commit 79b4d1b

Browse files
yonghong-songtsipa
authored andcommitted
change selftest map_ptr_kern.c which will fail without previous
verifier change. Also added to verifier test for both "map_ptr += scalar" and "scalar += map_ptr" arithmetic. Signed-off-by: Yonghong Song <[email protected]> --- .../selftests/bpf/progs/map_ptr_kern.c | 4 +-- .../testing/selftests/bpf/verifier/map_ptr.c | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-)
1 parent fc03d36 commit 79b4d1b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

tools/testing/selftests/bpf/progs/map_ptr_kern.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ static inline int check(struct bpf_map *indirect, struct bpf_map *direct,
7474
return 1;
7575
}
7676

77-
static inline int check_default(struct bpf_map *indirect,
78-
struct bpf_map *direct)
77+
static __attribute__ ((noinline)) int
78+
check_default(struct bpf_map *indirect, struct bpf_map *direct)
7979
{
8080
VERIFY(check(indirect, direct, sizeof(__u32), sizeof(__u32),
8181
MAX_ENTRIES));

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,35 @@
6060
.result = ACCEPT,
6161
.retval = 1,
6262
},
63+
{
64+
"bpf_map_ptr: r = 0, map_ptr = map_ptr + r",
65+
.insns = {
66+
BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
67+
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
68+
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
69+
BPF_MOV64_IMM(BPF_REG_0, 0),
70+
BPF_LD_MAP_FD(BPF_REG_1, 0),
71+
BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
72+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
73+
BPF_MOV64_IMM(BPF_REG_0, 0),
74+
BPF_EXIT_INSN(),
75+
},
76+
.fixup_map_hash_16b = { 4 },
77+
.result = ACCEPT,
78+
},
79+
{
80+
"bpf_map_ptr: r = 0, r = r + map_ptr",
81+
.insns = {
82+
BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
83+
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
84+
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
85+
BPF_MOV64_IMM(BPF_REG_1, 0),
86+
BPF_LD_MAP_FD(BPF_REG_0, 0),
87+
BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_0),
88+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
89+
BPF_MOV64_IMM(BPF_REG_0, 0),
90+
BPF_EXIT_INSN(),
91+
},
92+
.fixup_map_hash_16b = { 4 },
93+
.result = ACCEPT,
94+
},

0 commit comments

Comments
 (0)