Skip to content

Commit 59bf7b3

Browse files
pchaignoKernel Patches Daemon
authored andcommitted
selftests/bpf: Test direct packet access on non-linear skbs
This patch adds two new selftests in the direct packet access suite, to cover the non-linear case with BPF_F_TEST_SKB_NON_LINEAR. The first tests the behavior of the bounds check with a non-linear skb. The second extends the first with a call to bpf_skb_pull_data() to be able to access the packet. Signed-off-by: Paul Chaignon <[email protected]>
1 parent 711a6f3 commit 59bf7b3

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,4 +800,52 @@ l0_%=: /* exit(0) */ \
800800
: __clobber_all);
801801
}
802802

803+
SEC("tc")
804+
__description("direct packet access: test31 (non-linear, bad access)")
805+
__success __retval(1)
806+
__flag(BPF_F_TEST_SKB_NON_LINEAR)
807+
__naked void access_test31_non_linear_bad_access(void)
808+
{
809+
asm volatile (" \
810+
r2 = *(u32*)(r1 + %[__sk_buff_data]); \
811+
r3 = *(u32*)(r1 + %[__sk_buff_data_end]); \
812+
r0 = r2; \
813+
r0 += 22; \
814+
if r0 > r3 goto l0_%=; \
815+
r0 = *(u8*)(r0 - 1); \
816+
exit; \
817+
l0_%=: r0 = 1; \
818+
exit; \
819+
" :
820+
: __imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
821+
__imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end))
822+
: __clobber_all);
823+
}
824+
825+
SEC("tc")
826+
__description("direct packet access: test32 (non-linear, good access)")
827+
__success __retval(0)
828+
__flag(BPF_F_TEST_SKB_NON_LINEAR)
829+
__naked void access_test32_non_linear_good_access(void)
830+
{
831+
asm volatile (" \
832+
r6 = r1; \
833+
r2 = 22; \
834+
call %[bpf_skb_pull_data]; \
835+
r2 = *(u32*)(r6 + %[__sk_buff_data]); \
836+
r3 = *(u32*)(r6 + %[__sk_buff_data_end]); \
837+
r0 = r2; \
838+
r0 += 22; \
839+
if r0 > r3 goto l0_%=; \
840+
r0 = *(u8*)(r0 - 1); \
841+
exit; \
842+
l0_%=: r0 = 1; \
843+
exit; \
844+
" :
845+
: __imm(bpf_skb_pull_data),
846+
__imm_const(__sk_buff_data, offsetof(struct __sk_buff, data)),
847+
__imm_const(__sk_buff_data_end, offsetof(struct __sk_buff, data_end))
848+
: __clobber_all);
849+
}
850+
803851
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)