Skip to content

Commit e142004

Browse files
ameryhungKernel Patches Daemon
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]>
1 parent 5111865 commit e142004

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
@@ -1110,6 +1110,20 @@ int invalidate_xdp_pkt_pointers(struct xdp_md *x)
11101110
return XDP_PASS;
11111111
}
11121112

1113+
/* XDP packet changing kfunc calls invalidate packet pointers */
1114+
SEC("xdp")
1115+
__failure __msg("invalid mem access")
1116+
int invalidate_xdp_pkt_pointers(struct xdp_md *x)
1117+
{
1118+
int *p = (void *)(long)x->data;
1119+
1120+
if ((void *)(p + 1) > (void *)(long)x->data_end)
1121+
return XDP_DROP;
1122+
bpf_xdp_pull_data(x, 0);
1123+
*p = 42; /* this is unsafe */
1124+
return XDP_PASS;
1125+
}
1126+
11131127
__noinline
11141128
int tail_call(struct __sk_buff *sk)
11151129
{

0 commit comments

Comments
 (0)