1 // SPDX-License-Identifier: GPL-2.0 2 /* Converted from tools/testing/selftests/bpf/verifier/cgroup_inv_retcode.c */ 3 4 #include <linux/bpf.h> 5 #include <bpf/bpf_helpers.h> 6 #include "bpf_misc.h" 7 8 SEC("cgroup/sock") 9 __description("bpf_exit with invalid return code. test1") 10 __failure __msg("R0 has value (0x0; 0xffffffff)") with_invalid_return_code_test1(void)11__naked void with_invalid_return_code_test1(void) 12 { 13 asm volatile (" \ 14 r0 = *(u32*)(r1 + 0); \ 15 exit; \ 16 " ::: __clobber_all); 17 } 18 19 SEC("cgroup/sock") 20 __description("bpf_exit with invalid return code. test2") 21 __success with_invalid_return_code_test2(void)22__naked void with_invalid_return_code_test2(void) 23 { 24 asm volatile (" \ 25 r0 = *(u32*)(r1 + 0); \ 26 r0 &= 1; \ 27 exit; \ 28 " ::: __clobber_all); 29 } 30 31 SEC("cgroup/sock") 32 __description("bpf_exit with invalid return code. test3") 33 __failure __msg("R0 has value (0x0; 0x3)") with_invalid_return_code_test3(void)34__naked void with_invalid_return_code_test3(void) 35 { 36 asm volatile (" \ 37 r0 = *(u32*)(r1 + 0); \ 38 r0 &= 3; \ 39 exit; \ 40 " ::: __clobber_all); 41 } 42 43 SEC("cgroup/sock") 44 __description("bpf_exit with invalid return code. test4") 45 __success with_invalid_return_code_test4(void)46__naked void with_invalid_return_code_test4(void) 47 { 48 asm volatile (" \ 49 r0 = 1; \ 50 exit; \ 51 " ::: __clobber_all); 52 } 53 54 SEC("cgroup/sock") 55 __description("bpf_exit with invalid return code. test5") 56 __failure __msg("R0 has value (0x2; 0x0)") with_invalid_return_code_test5(void)57__naked void with_invalid_return_code_test5(void) 58 { 59 asm volatile (" \ 60 r0 = 2; \ 61 exit; \ 62 " ::: __clobber_all); 63 } 64 65 SEC("cgroup/sock") 66 __description("bpf_exit with invalid return code. test6") 67 __failure __msg("R0 is not a known value (ctx)") with_invalid_return_code_test6(void)68__naked void with_invalid_return_code_test6(void) 69 { 70 asm volatile (" \ 71 r0 = r1; \ 72 exit; \ 73 " ::: __clobber_all); 74 } 75 76 SEC("cgroup/sock") 77 __description("bpf_exit with invalid return code. test7") 78 __failure __msg("R0 has unknown scalar value") with_invalid_return_code_test7(void)79__naked void with_invalid_return_code_test7(void) 80 { 81 asm volatile (" \ 82 r0 = *(u32*)(r1 + 0); \ 83 r2 = *(u32*)(r1 + 4); \ 84 r0 *= r2; \ 85 exit; \ 86 " ::: __clobber_all); 87 } 88 89 char _license[] SEC("license") = "GPL"; 90