1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ 3 #include <vmlinux.h> 4 #include <bpf/bpf_helpers.h> 5 #include "bpf_misc.h" 6 7 #if __clang_major__ >= 21 && 0 8 SEC("socket") 9 __description("__builtin_trap with simple c code") 10 __failure __msg("unexpected __bpf_trap() due to uninitialized variable?") 11 void bpf_builtin_trap_with_simple_c(void) 12 { 13 __builtin_trap(); 14 } 15 #endif 16 17 SEC("socket") 18 __description("__bpf_trap with simple c code") 19 __failure __msg("unexpected __bpf_trap() due to uninitialized variable?") 20 void bpf_trap_with_simple_c(void) 21 { 22 __bpf_trap(); 23 } 24 25 SEC("socket") 26 __description("__bpf_trap as the second-from-last insn") 27 __failure __msg("unexpected __bpf_trap() due to uninitialized variable?") 28 __naked void bpf_trap_at_func_end(void) 29 { 30 asm volatile ( 31 "r0 = 0;" 32 "call %[__bpf_trap];" 33 "exit;" 34 : 35 : __imm(__bpf_trap) 36 : __clobber_all); 37 } 38 39 SEC("socket") 40 __description("dead code __bpf_trap in the middle of code") 41 __success 42 __naked void dead_bpf_trap_in_middle(void) 43 { 44 asm volatile ( 45 "r0 = 0;" 46 "if r0 == 0 goto +1;" 47 "call %[__bpf_trap];" 48 "r0 = 2;" 49 "exit;" 50 : 51 : __imm(__bpf_trap) 52 : __clobber_all); 53 } 54 55 SEC("socket") 56 __description("reachable __bpf_trap in the middle of code") 57 __failure __msg("unexpected __bpf_trap() due to uninitialized variable?") 58 __naked void live_bpf_trap_in_middle(void) 59 { 60 asm volatile ( 61 "r0 = 0;" 62 "if r0 == 1 goto +1;" 63 "call %[__bpf_trap];" 64 "r0 = 2;" 65 "exit;" 66 : 67 : __imm(__bpf_trap) 68 : __clobber_all); 69 } 70 71 char _license[] SEC("license") = "GPL"; 72