Skip to content

Commit 211bf9c

Browse files
borkmannAlexei Starovoitov
authored andcommitted
selftests/bpf: Add a test case to write mtu result into .rodata
Add a test which attempts to call bpf_check_mtu() and writes the MTU into .rodata section of the BPF program, and for comparison this adds test cases also for .bss and .data section again. The bpf_check_mtu() is a bit more special in that the passed mtu argument is read and written by the helper (instead of just written to). Assert that writes into .rodata remain rejected by the verifier. # ./vmtest.sh -- ./test_progs -t verifier_const [...] ./test_progs -t verifier_const [ 1.657367] bpf_testmod: loading out-of-tree module taints kernel. [ 1.657773] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel torvalds#473/1 verifier_const/rodata/strtol: write rejected:OK torvalds#473/2 verifier_const/bss/strtol: write accepted:OK torvalds#473/3 verifier_const/data/strtol: write accepted:OK torvalds#473/4 verifier_const/rodata/mtu: write rejected:OK torvalds#473/5 verifier_const/bss/mtu: write accepted:OK torvalds#473/6 verifier_const/data/mtu: write accepted:OK torvalds#473 verifier_const:OK [...] Summary: 2/10 PASSED, 0 SKIPPED, 0 FAILED For comparison, without the MEM_UNINIT on bpf_check_mtu's proto: # ./vmtest.sh -- ./test_progs -t verifier_const [...] torvalds#473/3 verifier_const/data/strtol: write accepted:OK run_subtest:PASS:obj_open_mem 0 nsec run_subtest:FAIL:unexpected_load_success unexpected success: 0 torvalds#473/4 verifier_const/rodata/mtu: write rejected:FAIL torvalds#473/5 verifier_const/bss/mtu: write accepted:OK torvalds#473/6 verifier_const/data/mtu: write accepted:OK torvalds#473 verifier_const:FAIL [...] Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/r/20240913191754.13290-9-daniel@iogearbox.net Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 2e3f066 commit 211bf9c

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

tools/testing/selftests/bpf/progs/verifier_const.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ long bar;
1010
long bart = 96;
1111

1212
SEC("tc/ingress")
13-
__description("rodata: write rejected")
13+
__description("rodata/strtol: write rejected")
1414
__failure __msg("write into map forbidden")
1515
int tcx1(struct __sk_buff *skb)
1616
{
@@ -20,7 +20,7 @@ int tcx1(struct __sk_buff *skb)
2020
}
2121

2222
SEC("tc/ingress")
23-
__description("bss: write accepted")
23+
__description("bss/strtol: write accepted")
2424
__success
2525
int tcx2(struct __sk_buff *skb)
2626
{
@@ -30,7 +30,7 @@ int tcx2(struct __sk_buff *skb)
3030
}
3131

3232
SEC("tc/ingress")
33-
__description("data: write accepted")
33+
__description("data/strtol: write accepted")
3434
__success
3535
int tcx3(struct __sk_buff *skb)
3636
{
@@ -39,4 +39,31 @@ int tcx3(struct __sk_buff *skb)
3939
return TCX_PASS;
4040
}
4141

42+
SEC("tc/ingress")
43+
__description("rodata/mtu: write rejected")
44+
__failure __msg("write into map forbidden")
45+
int tcx4(struct __sk_buff *skb)
46+
{
47+
bpf_check_mtu(skb, skb->ifindex, (__u32 *)&foo, 0, 0);
48+
return TCX_PASS;
49+
}
50+
51+
SEC("tc/ingress")
52+
__description("bss/mtu: write accepted")
53+
__success
54+
int tcx5(struct __sk_buff *skb)
55+
{
56+
bpf_check_mtu(skb, skb->ifindex, (__u32 *)&bar, 0, 0);
57+
return TCX_PASS;
58+
}
59+
60+
SEC("tc/ingress")
61+
__description("data/mtu: write accepted")
62+
__success
63+
int tcx6(struct __sk_buff *skb)
64+
{
65+
bpf_check_mtu(skb, skb->ifindex, (__u32 *)&bart, 0, 0);
66+
return TCX_PASS;
67+
}
68+
4269
char LICENSE[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)