1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* Converted from tools/testing/selftests/bpf/verifier/direct_stack_access_wraparound.c */ |
3 | |
4 | #include <linux/bpf.h> |
5 | #include <bpf/bpf_helpers.h> |
6 | #include "bpf_misc.h" |
7 | |
8 | SEC("socket" ) |
9 | __description("direct stack access with 32-bit wraparound. test1" ) |
10 | __failure __msg("fp pointer and 2147483647" ) |
11 | __failure_unpriv |
12 | __naked void with_32_bit_wraparound_test1(void) |
13 | { |
14 | asm volatile (" \ |
15 | r1 = r10; \ |
16 | r1 += 0x7fffffff; \ |
17 | r1 += 0x7fffffff; \ |
18 | w0 = 0; \ |
19 | *(u8*)(r1 + 0) = r0; \ |
20 | exit; \ |
21 | " ::: __clobber_all); |
22 | } |
23 | |
24 | SEC("socket" ) |
25 | __description("direct stack access with 32-bit wraparound. test2" ) |
26 | __failure __msg("fp pointer and 1073741823" ) |
27 | __failure_unpriv |
28 | __naked void with_32_bit_wraparound_test2(void) |
29 | { |
30 | asm volatile (" \ |
31 | r1 = r10; \ |
32 | r1 += 0x3fffffff; \ |
33 | r1 += 0x3fffffff; \ |
34 | w0 = 0; \ |
35 | *(u8*)(r1 + 0) = r0; \ |
36 | exit; \ |
37 | " ::: __clobber_all); |
38 | } |
39 | |
40 | SEC("socket" ) |
41 | __description("direct stack access with 32-bit wraparound. test3" ) |
42 | __failure __msg("fp pointer offset 1073741822" ) |
43 | __msg_unpriv("R1 stack pointer arithmetic goes out of range" ) |
44 | __naked void with_32_bit_wraparound_test3(void) |
45 | { |
46 | asm volatile (" \ |
47 | r1 = r10; \ |
48 | r1 += 0x1fffffff; \ |
49 | r1 += 0x1fffffff; \ |
50 | w0 = 0; \ |
51 | *(u8*)(r1 + 0) = r0; \ |
52 | exit; \ |
53 | " ::: __clobber_all); |
54 | } |
55 | |
56 | char _license[] SEC("license" ) = "GPL" ; |
57 | |