File tree Expand file tree Collapse file tree 2 files changed +73
-0
lines changed
tools/testing/selftests/bpf Expand file tree Collapse file tree 2 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 14
14
#include "verifier_bounds_deduction_non_const.skel.h"
15
15
#include "verifier_bounds_mix_sign_unsign.skel.h"
16
16
#include "verifier_bpf_get_stack.skel.h"
17
+ #include "verifier_bpf_trap.skel.h"
17
18
#include "verifier_bswap.skel.h"
18
19
#include "verifier_btf_ctx_access.skel.h"
19
20
#include "verifier_btf_unreliable_prog.skel.h"
@@ -148,6 +149,7 @@ void test_verifier_bounds_deduction(void) { RUN(verifier_bounds_deduction);
148
149
void test_verifier_bounds_deduction_non_const (void ) { RUN (verifier_bounds_deduction_non_const ); }
149
150
void test_verifier_bounds_mix_sign_unsign (void ) { RUN (verifier_bounds_mix_sign_unsign ); }
150
151
void test_verifier_bpf_get_stack (void ) { RUN (verifier_bpf_get_stack ); }
152
+ void test_verifier_bpf_trap (void ) { RUN (verifier_bpf_trap ); }
151
153
void test_verifier_bswap (void ) { RUN (verifier_bswap ); }
152
154
void test_verifier_btf_ctx_access (void ) { RUN (verifier_btf_ctx_access ); }
153
155
void test_verifier_btf_unreliable_prog (void ) { RUN (verifier_btf_unreliable_prog ); }
Original file line number Diff line number Diff line change
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
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" ;
You can’t perform that action at this time.
0 commit comments