File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed
tools/testing/selftests/bpf Expand file tree Collapse file tree 2 files changed +63
-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_unreachable.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_unreachable (void ) { RUN (verifier_bpf_unreachable ); }
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
+ SEC ("socket" )
8
+ __description ("bpf_unreachable with simple c code" )
9
+ __failure __msg ("unexpected bpf_unreachable() due to uninitialized variable?" )
10
+ void bpf_unreachable_with_simple_c (void )
11
+ {
12
+ bpf_unreachable ();
13
+ }
14
+
15
+ SEC ("socket" )
16
+ __description ("bpf_unreachable as the second-from-last insn" )
17
+ __failure __msg ("unexpected bpf_unreachable() due to uninitialized variable?" )
18
+ __naked void bpf_unreachable_at_func_end (void )
19
+ {
20
+ asm volatile (
21
+ "r0 = 0;"
22
+ "call %[bpf_unreachable];"
23
+ "exit;"
24
+ :
25
+ : __imm (bpf_unreachable )
26
+ : __clobber_all );
27
+ }
28
+
29
+ SEC ("socket" )
30
+ __description ("dead code bpf_unreachable() in the middle of code" )
31
+ __success
32
+ __naked void dead_bpf_unreachable_in_middle (void )
33
+ {
34
+ asm volatile (
35
+ "r0 = 0;"
36
+ "if r0 == 0 goto +1;"
37
+ "call %[bpf_unreachable];"
38
+ "r0 = 2;"
39
+ "exit;"
40
+ :
41
+ : __imm (bpf_unreachable )
42
+ : __clobber_all );
43
+ }
44
+
45
+ SEC ("socket" )
46
+ __description ("reachable bpf_unreachable() in the middle of code" )
47
+ __failure __msg ("unexpected bpf_unreachable() due to uninitialized variable?" )
48
+ __naked void live_bpf_unreachable_in_middle (void )
49
+ {
50
+ asm volatile (
51
+ "r0 = 0;"
52
+ "if r0 == 1 goto +1;"
53
+ "call %[bpf_unreachable];"
54
+ "r0 = 2;"
55
+ "exit;"
56
+ :
57
+ : __imm (bpf_unreachable )
58
+ : __clobber_all );
59
+ }
60
+
61
+ char _license [] SEC ("license" ) = "GPL" ;
You can’t perform that action at this time.
0 commit comments