Skip to content

Commit f0b5b3d

Browse files
pchaignoAlexei Starovoitov
authored andcommitted
selftests/bpf: Test access from RO map from xdp_store_bytes
This new test simply checks that helper bpf_xdp_store_bytes can successfully read from a read-only map. Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com> Link: https://lore.kernel.org/r/4fdb934a713b2d7cf133288c77f6cfefe9856440.1769875479.git.paul.chaignon@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 6557f15 commit f0b5b3d

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
#include <bpf/bpf_helpers.h>
66
#include "bpf_misc.h"
77

8+
struct {
9+
__uint(type, BPF_MAP_TYPE_ARRAY);
10+
__uint(max_entries, 1);
11+
__type(key, int);
12+
__type(value, __u64);
13+
__uint(map_flags, BPF_F_RDONLY_PROG);
14+
} map_array_ro SEC(".maps");
15+
816
SEC("xdp")
917
__description("XDP, using ifindex from netdev")
1018
__success __retval(1)
@@ -21,4 +29,31 @@ l0_%=: exit; \
2129
: __clobber_all);
2230
}
2331

32+
SEC("xdp")
33+
__description("XDP, using xdp_store_bytes from RO map")
34+
__success __retval(0)
35+
__naked void xdp_store_bytes_from_ro_map(void)
36+
{
37+
asm volatile (" \
38+
r6 = r1; \
39+
r1 = 0; \
40+
*(u64*)(r10 - 8) = r1; \
41+
r2 = r10; \
42+
r2 += -8; \
43+
r1 = %[map_array_ro] ll; \
44+
call %[bpf_map_lookup_elem]; \
45+
if r0 == 0 goto l0_%=; \
46+
r1 = r6; \
47+
r2 = 0; \
48+
r3 = r0; \
49+
r4 = 8; \
50+
call %[bpf_xdp_store_bytes]; \
51+
l0_%=: exit; \
52+
" :
53+
: __imm(bpf_map_lookup_elem),
54+
__imm(bpf_xdp_store_bytes),
55+
__imm_addr(map_array_ro)
56+
: __clobber_all);
57+
}
58+
2459
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)