150472Speter// SPDX-License-Identifier: GPL-2.0 238738Sbrian/* Converted from tools/testing/selftests/bpf/verifier/const_or.c */ 337Srgrimes 437Srgrimes#include <linux/bpf.h> 537Srgrimes#include <bpf/bpf_helpers.h> 67356Sjoerg#include "bpf_misc.h" 718689Sache 818689SacheSEC("tracepoint") 918689Sache__description("constant register |= constant should keep constant type") 1045232Sbrian__success 1145232Sbrian__naked void constant_should_keep_constant_type(void) 1218689Sache{ 1318689Sache asm volatile (" \ 1418689Sache r1 = r10; \ 1598978Smaxim r1 += -48; \ 1645232Sbrian r2 = 34; \ 1737Srgrimes r2 |= 13; \ 1818689Sache r3 = 0; \ 1945232Sbrian call %[bpf_probe_read_kernel]; \ 2096156Smaxim exit; \ 2118689Sache" : 2290185Ssheldonh : __imm(bpf_probe_read_kernel) 2390185Ssheldonh : __clobber_all); 24} 25 26SEC("tracepoint") 27__description("constant register |= constant should not bypass stack boundary checks") 28__failure __msg("invalid indirect access to stack R1 off=-48 size=58") 29__naked void not_bypass_stack_boundary_checks_1(void) 30{ 31 asm volatile (" \ 32 r1 = r10; \ 33 r1 += -48; \ 34 r2 = 34; \ 35 r2 |= 24; \ 36 r3 = 0; \ 37 call %[bpf_probe_read_kernel]; \ 38 exit; \ 39" : 40 : __imm(bpf_probe_read_kernel) 41 : __clobber_all); 42} 43 44SEC("tracepoint") 45__description("constant register |= constant register should keep constant type") 46__success 47__naked void register_should_keep_constant_type(void) 48{ 49 asm volatile (" \ 50 r1 = r10; \ 51 r1 += -48; \ 52 r2 = 34; \ 53 r4 = 13; \ 54 r2 |= r4; \ 55 r3 = 0; \ 56 call %[bpf_probe_read_kernel]; \ 57 exit; \ 58" : 59 : __imm(bpf_probe_read_kernel) 60 : __clobber_all); 61} 62 63SEC("tracepoint") 64__description("constant register |= constant register should not bypass stack boundary checks") 65__failure __msg("invalid indirect access to stack R1 off=-48 size=58") 66__naked void not_bypass_stack_boundary_checks_2(void) 67{ 68 asm volatile (" \ 69 r1 = r10; \ 70 r1 += -48; \ 71 r2 = 34; \ 72 r4 = 24; \ 73 r2 |= r4; \ 74 r3 = 0; \ 75 call %[bpf_probe_read_kernel]; \ 76 exit; \ 77" : 78 : __imm(bpf_probe_read_kernel) 79 : __clobber_all); 80} 81 82char _license[] SEC("license") = "GPL"; 83