1*a2777eaaSEduard Zingerman // SPDX-License-Identifier: GPL-2.0 2*a2777eaaSEduard Zingerman /* Converted from tools/testing/selftests/bpf/verifier/const_or.c */ 3*a2777eaaSEduard Zingerman 4*a2777eaaSEduard Zingerman #include <linux/bpf.h> 5*a2777eaaSEduard Zingerman #include <bpf/bpf_helpers.h> 6*a2777eaaSEduard Zingerman #include "bpf_misc.h" 7*a2777eaaSEduard Zingerman 8*a2777eaaSEduard Zingerman SEC("tracepoint") 9*a2777eaaSEduard Zingerman __description("constant register |= constant should keep constant type") 10*a2777eaaSEduard Zingerman __success constant_should_keep_constant_type(void)11*a2777eaaSEduard Zingerman__naked void constant_should_keep_constant_type(void) 12*a2777eaaSEduard Zingerman { 13*a2777eaaSEduard Zingerman asm volatile (" \ 14*a2777eaaSEduard Zingerman r1 = r10; \ 15*a2777eaaSEduard Zingerman r1 += -48; \ 16*a2777eaaSEduard Zingerman r2 = 34; \ 17*a2777eaaSEduard Zingerman r2 |= 13; \ 18*a2777eaaSEduard Zingerman r3 = 0; \ 19*a2777eaaSEduard Zingerman call %[bpf_probe_read_kernel]; \ 20*a2777eaaSEduard Zingerman exit; \ 21*a2777eaaSEduard Zingerman " : 22*a2777eaaSEduard Zingerman : __imm(bpf_probe_read_kernel) 23*a2777eaaSEduard Zingerman : __clobber_all); 24*a2777eaaSEduard Zingerman } 25*a2777eaaSEduard Zingerman 26*a2777eaaSEduard Zingerman SEC("tracepoint") 27*a2777eaaSEduard Zingerman __description("constant register |= constant should not bypass stack boundary checks") 28*a2777eaaSEduard Zingerman __failure __msg("invalid indirect access to stack R1 off=-48 size=58") not_bypass_stack_boundary_checks_1(void)29*a2777eaaSEduard Zingerman__naked void not_bypass_stack_boundary_checks_1(void) 30*a2777eaaSEduard Zingerman { 31*a2777eaaSEduard Zingerman asm volatile (" \ 32*a2777eaaSEduard Zingerman r1 = r10; \ 33*a2777eaaSEduard Zingerman r1 += -48; \ 34*a2777eaaSEduard Zingerman r2 = 34; \ 35*a2777eaaSEduard Zingerman r2 |= 24; \ 36*a2777eaaSEduard Zingerman r3 = 0; \ 37*a2777eaaSEduard Zingerman call %[bpf_probe_read_kernel]; \ 38*a2777eaaSEduard Zingerman exit; \ 39*a2777eaaSEduard Zingerman " : 40*a2777eaaSEduard Zingerman : __imm(bpf_probe_read_kernel) 41*a2777eaaSEduard Zingerman : __clobber_all); 42*a2777eaaSEduard Zingerman } 43*a2777eaaSEduard Zingerman 44*a2777eaaSEduard Zingerman SEC("tracepoint") 45*a2777eaaSEduard Zingerman __description("constant register |= constant register should keep constant type") 46*a2777eaaSEduard Zingerman __success register_should_keep_constant_type(void)47*a2777eaaSEduard Zingerman__naked void register_should_keep_constant_type(void) 48*a2777eaaSEduard Zingerman { 49*a2777eaaSEduard Zingerman asm volatile (" \ 50*a2777eaaSEduard Zingerman r1 = r10; \ 51*a2777eaaSEduard Zingerman r1 += -48; \ 52*a2777eaaSEduard Zingerman r2 = 34; \ 53*a2777eaaSEduard Zingerman r4 = 13; \ 54*a2777eaaSEduard Zingerman r2 |= r4; \ 55*a2777eaaSEduard Zingerman r3 = 0; \ 56*a2777eaaSEduard Zingerman call %[bpf_probe_read_kernel]; \ 57*a2777eaaSEduard Zingerman exit; \ 58*a2777eaaSEduard Zingerman " : 59*a2777eaaSEduard Zingerman : __imm(bpf_probe_read_kernel) 60*a2777eaaSEduard Zingerman : __clobber_all); 61*a2777eaaSEduard Zingerman } 62*a2777eaaSEduard Zingerman 63*a2777eaaSEduard Zingerman SEC("tracepoint") 64*a2777eaaSEduard Zingerman __description("constant register |= constant register should not bypass stack boundary checks") 65*a2777eaaSEduard Zingerman __failure __msg("invalid indirect access to stack R1 off=-48 size=58") not_bypass_stack_boundary_checks_2(void)66*a2777eaaSEduard Zingerman__naked void not_bypass_stack_boundary_checks_2(void) 67*a2777eaaSEduard Zingerman { 68*a2777eaaSEduard Zingerman asm volatile (" \ 69*a2777eaaSEduard Zingerman r1 = r10; \ 70*a2777eaaSEduard Zingerman r1 += -48; \ 71*a2777eaaSEduard Zingerman r2 = 34; \ 72*a2777eaaSEduard Zingerman r4 = 24; \ 73*a2777eaaSEduard Zingerman r2 |= r4; \ 74*a2777eaaSEduard Zingerman r3 = 0; \ 75*a2777eaaSEduard Zingerman call %[bpf_probe_read_kernel]; \ 76*a2777eaaSEduard Zingerman exit; \ 77*a2777eaaSEduard Zingerman " : 78*a2777eaaSEduard Zingerman : __imm(bpf_probe_read_kernel) 79*a2777eaaSEduard Zingerman : __clobber_all); 80*a2777eaaSEduard Zingerman } 81*a2777eaaSEduard Zingerman 82*a2777eaaSEduard Zingerman char _license[] SEC("license") = "GPL"; 83