Skip to content

Commit 2995bc3

Browse files
borkmannintel-lab-lkp
authored andcommitted
selftests/bpf: Add a test case to write into .rodata
Add a test case which attempts to write into .rodata section of the BPF program, and for comparison this adds test cases also for .bss and .data section. Before fix: # ./vmtest.sh -- ./test_progs -t verifier_const [...] ./test_progs -t verifier_const tester_init:PASS:tester_log_buf 0 nsec process_subtest:PASS:obj_open_mem 0 nsec process_subtest:PASS:specs_alloc 0 nsec run_subtest:PASS:obj_open_mem 0 nsec run_subtest:FAIL:unexpected_load_success unexpected success: 0 torvalds#465/1 verifier_const/rodata: write rejected:FAIL torvalds#465/2 verifier_const/bss: write accepted:OK torvalds#465/3 verifier_const/data: write accepted:OK torvalds#465 verifier_const:FAIL [...] After fix: # ./vmtest.sh -- ./test_progs -t verifier_const [...] ./test_progs -t verifier_const torvalds#465/1 verifier_const/rodata: write rejected:OK torvalds#465/2 verifier_const/bss: write accepted:OK torvalds#465/3 verifier_const/data: write accepted:OK torvalds#465 verifier_const:OK [...] Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 7621896 commit 2995bc3

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

tools/testing/selftests/bpf/prog_tests/tc_links.c

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define ping_cmd "ping -q -c1 -w1 127.0.0.1 > /dev/null"
1010

1111
#include "test_tc_link.skel.h"
12+
#include "test_const.skel.h"
1213

1314
#include "netlink_helpers.h"
1415
#include "tc_helpers.h"

tools/testing/selftests/bpf/prog_tests/verifier.c

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "verifier_cgroup_inv_retcode.skel.h"
2222
#include "verifier_cgroup_skb.skel.h"
2323
#include "verifier_cgroup_storage.skel.h"
24+
#include "verifier_const.skel.h"
2425
#include "verifier_const_or.skel.h"
2526
#include "verifier_ctx.skel.h"
2627
#include "verifier_ctx_sk_msg.skel.h"
@@ -140,6 +141,7 @@ void test_verifier_cfg(void) { RUN(verifier_cfg); }
140141
void test_verifier_cgroup_inv_retcode(void) { RUN(verifier_cgroup_inv_retcode); }
141142
void test_verifier_cgroup_skb(void) { RUN(verifier_cgroup_skb); }
142143
void test_verifier_cgroup_storage(void) { RUN(verifier_cgroup_storage); }
144+
void test_verifier_const(void) { RUN(verifier_const); }
143145
void test_verifier_const_or(void) { RUN(verifier_const_or); }
144146
void test_verifier_ctx(void) { RUN(verifier_ctx); }
145147
void test_verifier_ctx_sk_msg(void) { RUN(verifier_ctx_sk_msg); }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2024 Isovalent */
3+
4+
#include <linux/bpf.h>
5+
#include <bpf/bpf_helpers.h>
6+
#include "bpf_misc.h"
7+
8+
const long foo = 42;
9+
long bar;
10+
long bart = 96;
11+
12+
SEC("tc/ingress")
13+
__description("rodata: write rejected")
14+
__failure __msg("write into map forbidden")
15+
int tcx1(struct __sk_buff *skb)
16+
{
17+
char buff[] = { '8', '4', '\0' };
18+
bpf_strtol(buff, sizeof(buff), 0, (long *)&foo);
19+
return TCX_PASS;
20+
}
21+
22+
SEC("tc/ingress")
23+
__description("bss: write accepted")
24+
__success
25+
int tcx2(struct __sk_buff *skb)
26+
{
27+
char buff[] = { '8', '4', '\0' };
28+
bpf_strtol(buff, sizeof(buff), 0, &bar);
29+
return TCX_PASS;
30+
}
31+
32+
SEC("tc/ingress")
33+
__description("data: write accepted")
34+
__success
35+
int tcx3(struct __sk_buff *skb)
36+
{
37+
char buff[] = { '8', '4', '\0' };
38+
bpf_strtol(buff, sizeof(buff), 0, &bart);
39+
return TCX_PASS;
40+
}
41+
42+
char LICENSE[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)