1 // SPDX-License-Identifier: GPL-2.0
2 /* Converted from tools/testing/selftests/bpf/verifier/map_ret_val.c */
5 #include <bpf/bpf_helpers.h>
6 #include "../../../include/linux/filter.h"
10 __uint(type, BPF_MAP_TYPE_HASH);
11 __uint(max_entries, 1);
12 __type(key, long long);
13 __type(value, long long);
14 } map_hash_8b SEC(".maps");
17 __description("invalid map_fd for function call")
18 __failure __msg("fd 0 is not pointing to valid bpf_map")
20 __naked void map_fd_for_function_call(void)
24 *(u64*)(r10 - 8) = r2; \
27 .8byte %[ld_map_fd]; \
29 call %[bpf_map_delete_elem]; \
32 : __imm(bpf_map_delete_elem),
33 __imm_insn(ld_map_fd, BPF_RAW_INSN(BPF_LD | BPF_DW | BPF_IMM, BPF_REG_1, BPF_PSEUDO_MAP_FD, 0, 0))
38 __description("don't check return value before access")
39 __failure __msg("R0 invalid mem access 'map_value_or_null'")
41 __naked void check_return_value_before_access(void)
45 *(u64*)(r10 - 8) = r1; \
48 r1 = %[map_hash_8b] ll; \
49 call %[bpf_map_lookup_elem]; \
51 *(u64*)(r0 + 0) = r1; \
54 : __imm(bpf_map_lookup_elem),
55 __imm_addr(map_hash_8b)
60 __description("access memory with incorrect alignment")
61 __failure __msg("misaligned value access")
63 __flag(BPF_F_STRICT_ALIGNMENT)
64 __naked void access_memory_with_incorrect_alignment_1(void)
68 *(u64*)(r10 - 8) = r1; \
71 r1 = %[map_hash_8b] ll; \
72 call %[bpf_map_lookup_elem]; \
73 if r0 == 0 goto l0_%=; \
75 *(u64*)(r0 + 4) = r1; \
78 : __imm(bpf_map_lookup_elem),
79 __imm_addr(map_hash_8b)
84 __description("sometimes access memory with incorrect alignment")
85 __failure __msg("R0 invalid mem access")
86 __msg_unpriv("R0 leaks addr")
87 __flag(BPF_F_STRICT_ALIGNMENT)
88 __naked void access_memory_with_incorrect_alignment_2(void)
92 *(u64*)(r10 - 8) = r1; \
95 r1 = %[map_hash_8b] ll; \
96 call %[bpf_map_lookup_elem]; \
97 if r0 == 0 goto l0_%=; \
99 *(u64*)(r0 + 0) = r1; \
102 *(u64*)(r0 + 0) = r1; \
105 : __imm(bpf_map_lookup_elem),
106 __imm_addr(map_hash_8b)
110 char _license[] SEC("license") = "GPL";