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 8SEC("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 24SEC("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 40SEC("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 56char _license[] SEC("license") = "GPL"; 57