Skip to content

Commit 1e15f4f

Browse files
AsphalttKernel Patches Daemon
authored andcommitted
selftests/bpf: Add test to access union argument in tracing program
Adding verifier test for accessing union argument in tracing programs. The test program loads 1st argument of bpf_fentry_test11 function which is union and checks that verifier allows that. cd tools/testing/selftests/bpf ./test_progs -t verifier_btf_ctx 501/7 verifier_btf_ctx_access/btf_ctx_access union arg accept:OK 501 verifier_btf_ctx_access:OK Summary: 1/7 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Leon Hwang <[email protected]>
1 parent cabff72 commit 1e15f4f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

net/bpf/test_run.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,16 @@ noinline int bpf_fentry_test10(const void *a)
574574
return (long)a;
575575
}
576576

577+
typedef union {
578+
void *arg0;
579+
int *arg1;
580+
} union_test_t;
581+
582+
noinline int bpf_fentry_test11(union_test_t t)
583+
{
584+
return (int)(long)t.arg0;
585+
}
586+
577587
noinline void bpf_fentry_test_sinfo(struct skb_shared_info *sinfo)
578588
{
579589
}
@@ -688,6 +698,7 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
688698
struct bpf_fentry_test_t arg = {};
689699
u16 side_effect = 0, ret = 0;
690700
int b = 2, err = -EFAULT;
701+
union_test_t utt = {};
691702
u32 retval = 0;
692703

693704
if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size)
@@ -705,7 +716,8 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
705716
bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
706717
bpf_fentry_test8(&arg) != 0 ||
707718
bpf_fentry_test9(&retval) != 0 ||
708-
bpf_fentry_test10((void *)0) != 0)
719+
bpf_fentry_test10((void *)0) != 0 ||
720+
bpf_fentry_test11(utt) != 0)
709721
goto out;
710722
break;
711723
case BPF_MODIFY_RETURN:

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,16 @@ __naked void ctx_access_const_void_pointer_accept(void)
7777
" ::: __clobber_all);
7878
}
7979

80+
SEC("fentry/bpf_fentry_test11")
81+
__description("btf_ctx_access union arg accept")
82+
__success __retval(0)
83+
__naked void ctx_access_union_arg_accept(void)
84+
{
85+
asm volatile (" \
86+
r2 = *(u64 *)(r1 + 0); /* load 1st argument value (union) */\
87+
r0 = 0; \
88+
exit; \
89+
" ::: __clobber_all);
90+
}
91+
8092
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)