1// SPDX-License-Identifier: GPL-2.0 2 3#include <linux/bpf.h> 4#include <bpf/bpf_helpers.h> 5#include "bpf_misc.h" 6 7SEC("netfilter") 8__description("bpf_exit with invalid return code. test1") 9__failure __msg("R0 is not a known value") 10__naked void with_invalid_return_code_test1(void) 11{ 12 asm volatile (" \ 13 r0 = *(u64*)(r1 + 0); \ 14 exit; \ 15" ::: __clobber_all); 16} 17 18SEC("netfilter") 19__description("bpf_exit with valid return code. test2") 20__success 21__naked void with_valid_return_code_test2(void) 22{ 23 asm volatile (" \ 24 r0 = 0; \ 25 exit; \ 26" ::: __clobber_all); 27} 28 29SEC("netfilter") 30__description("bpf_exit with valid return code. test3") 31__success 32__naked void with_valid_return_code_test3(void) 33{ 34 asm volatile (" \ 35 r0 = 1; \ 36 exit; \ 37" ::: __clobber_all); 38} 39 40SEC("netfilter") 41__description("bpf_exit with invalid return code. test4") 42__failure __msg("R0 has smin=2 smax=2 should have been in [0, 1]") 43__naked void with_invalid_return_code_test4(void) 44{ 45 asm volatile (" \ 46 r0 = 2; \ 47 exit; \ 48" ::: __clobber_all); 49} 50