Skip to content

Commit 991e555

Browse files
ameryhungMartin KaFai Lau
authored andcommitted
selftests/bpf: Test changing packet data from kfunc
bpf_xdp_pull_data() is the first kfunc that changes packet data. Make sure the verifier clear all packet pointers after calling packet data changing kfunc. Signed-off-by: Amery Hung <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent d43029f commit 991e555

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,20 @@ int invalidate_xdp_pkt_pointers_from_global_func(struct xdp_md *x)
10961096
return XDP_PASS;
10971097
}
10981098

1099+
/* XDP packet changing kfunc calls invalidate packet pointers */
1100+
SEC("xdp")
1101+
__failure __msg("invalid mem access")
1102+
int invalidate_xdp_pkt_pointers(struct xdp_md *x)
1103+
{
1104+
int *p = (void *)(long)x->data;
1105+
1106+
if ((void *)(p + 1) > (void *)(long)x->data_end)
1107+
return XDP_DROP;
1108+
bpf_xdp_pull_data(x, 0);
1109+
*p = 42; /* this is unsafe */
1110+
return XDP_PASS;
1111+
}
1112+
10991113
__noinline
11001114
int tail_call(struct __sk_buff *sk)
11011115
{

0 commit comments

Comments
 (0)