File tree 2 files changed +43
-0
lines changed
tools/testing/selftests/bpf
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 6
6
#include <bpf/btf.h>
7
7
#include "test_ksyms_btf.skel.h"
8
8
#include "test_ksyms_btf_null_check.skel.h"
9
+ #include "test_ksyms_btf_write_check.skel.h"
9
10
10
11
static int duration ;
11
12
@@ -81,6 +82,16 @@ static void test_null_check(void)
81
82
test_ksyms_btf_null_check__destroy (skel );
82
83
}
83
84
85
+ static void test_write_check (void )
86
+ {
87
+ struct test_ksyms_btf_write_check * skel ;
88
+
89
+ skel = test_ksyms_btf_write_check__open_and_load ();
90
+ ASSERT_ERR_PTR (skel , "unexpected load of a prog writing to ksym memory\n" );
91
+
92
+ test_ksyms_btf_write_check__destroy (skel );
93
+ }
94
+
84
95
void test_ksyms_btf (void )
85
96
{
86
97
int percpu_datasec ;
@@ -105,4 +116,7 @@ void test_ksyms_btf(void)
105
116
106
117
if (test__start_subtest ("null_check" ))
107
118
test_null_check ();
119
+
120
+ if (test__start_subtest ("write_check" ))
121
+ test_write_check ();
108
122
}
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: GPL-2.0
2
+ /* Copyright (c) 2021 Google */
3
+
4
+ #include "vmlinux.h"
5
+
6
+ #include <bpf/bpf_helpers.h>
7
+
8
+ extern const int bpf_prog_active __ksym ; /* int type global var. */
9
+
10
+ SEC ("raw_tp/sys_enter" )
11
+ int handler (const void * ctx )
12
+ {
13
+ int * active ;
14
+ __u32 cpu ;
15
+
16
+ cpu = bpf_get_smp_processor_id ();
17
+ active = (int * )bpf_per_cpu_ptr (& bpf_prog_active , cpu );
18
+ if (active ) {
19
+ /* Kernel memory obtained from bpf_{per,this}_cpu_ptr
20
+ * is read-only, should _not_ pass verification.
21
+ */
22
+ /* WRITE_ONCE */
23
+ * (volatile int * )active = -1 ;
24
+ }
25
+
26
+ return 0 ;
27
+ }
28
+
29
+ char _license [] SEC ("license" ) = "GPL" ;
You can’t perform that action at this time.
0 commit comments