1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/map_in_map.c */
5 #include <bpf/bpf_helpers.h>
9 __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
10 __uint(max_entries, 1);
13 __array(values, struct {
14 __uint(type, BPF_MAP_TYPE_ARRAY);
15 __uint(max_entries, 1);
19 } map_in_map SEC(".maps");
22 __description("map in map access")
23 __success __success_unpriv __retval(0)
24 __naked void map_in_map_access(void)
28 *(u32*)(r10 - 4) = r1; \
31 r1 = %[map_in_map] ll; \
32 call %[bpf_map_lookup_elem]; \
33 if r0 == 0 goto l0_%=; \
35 *(u32*)(r10 - 4) = r1; \
39 call %[bpf_map_lookup_elem]; \
43 : __imm(bpf_map_lookup_elem),
44 __imm_addr(map_in_map)
49 __description("map in map state pruning")
50 __success __msg("processed 26 insns")
51 __log_level(2) __retval(0) __flag(BPF_F_TEST_STATE_FREQ)
52 __naked void map_in_map_state_pruning(void)
56 *(u32*)(r10 - 4) = r1; \
60 r1 = %[map_in_map] ll; \
61 call %[bpf_map_lookup_elem]; \
62 if r0 != 0 goto l0_%=; \
66 call %[bpf_map_lookup_elem]; \
67 if r0 != 0 goto l1_%=; \
69 r1 = %[map_in_map] ll; \
70 call %[bpf_map_lookup_elem]; \
71 if r0 != 0 goto l2_%=; \
75 call %[bpf_map_lookup_elem]; \
76 if r0 != 0 goto l1_%=; \
78 l1_%=: r0 = *(u32*)(r0 + 0); \
81 : __imm(bpf_map_lookup_elem),
82 __imm_addr(map_in_map)
87 __description("invalid inner map pointer")
88 __failure __msg("R1 pointer arithmetic on map_ptr prohibited")
90 __naked void invalid_inner_map_pointer(void)
94 *(u32*)(r10 - 4) = r1; \
97 r1 = %[map_in_map] ll; \
98 call %[bpf_map_lookup_elem]; \
99 if r0 == 0 goto l0_%=; \
101 *(u32*)(r10 - 4) = r1; \
106 call %[bpf_map_lookup_elem]; \
110 : __imm(bpf_map_lookup_elem),
111 __imm_addr(map_in_map)
116 __description("forgot null checking on the inner map pointer")
117 __failure __msg("R1 type=map_value_or_null expected=map_ptr")
119 __naked void on_the_inner_map_pointer(void)
123 *(u32*)(r10 - 4) = r1; \
126 r1 = %[map_in_map] ll; \
127 call %[bpf_map_lookup_elem]; \
129 *(u32*)(r10 - 4) = r1; \
133 call %[bpf_map_lookup_elem]; \
137 : __imm(bpf_map_lookup_elem),
138 __imm_addr(map_in_map)
142 char _license[] SEC("license") = "GPL";