selftests/bpf: Add test to access u32 ptr argument in tracing program
authorFeng Zhou <zhoufeng.zf@bytedance.com>
Mon, 10 Apr 2023 08:59:08 +0000 (16:59 +0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 11 Apr 2023 18:29:49 +0000 (20:29 +0200)
Adding verifier test for accessing u32 pointer argument in
tracing programs.

The test program loads 1nd argument of bpf_fentry_test9 function
which is u32 pointer and checks that verifier allows that.

Co-developed-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/bpf/20230410085908.98493-3-zhoufeng.zf@bytedance.com
net/bpf/test_run.c
tools/testing/selftests/bpf/verifier/btf_ctx_access.c

index f1652f5..68bdfc0 100644 (file)
@@ -541,6 +541,11 @@ int noinline bpf_fentry_test8(struct bpf_fentry_test_t *arg)
        return (long)arg->a;
 }
 
+__bpf_kfunc u32 bpf_fentry_test9(u32 *a)
+{
+       return *a;
+}
+
 __bpf_kfunc int bpf_modify_return_test(int a, int *b)
 {
        *b += 1;
@@ -855,7 +860,8 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
                    bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
                    bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 ||
                    bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
-                   bpf_fentry_test8(&arg) != 0)
+                   bpf_fentry_test8(&arg) != 0 ||
+                   bpf_fentry_test9(&retval) != 0)
                        goto out;
                break;
        case BPF_MODIFY_RETURN:
index 6340db6..0484d3d 100644 (file)
        .expected_attach_type = BPF_TRACE_FENTRY,
        .kfunc = "bpf_modify_return_test",
 },
+
+{
+       "btf_ctx_access u32 pointer accept",
+       .insns = {
+       BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, 0),    /* load 1nd argument value (u32 pointer) */
+       BPF_MOV64_IMM(BPF_REG_0, 0),
+       BPF_EXIT_INSN(),
+       },
+       .result = ACCEPT,
+       .prog_type = BPF_PROG_TYPE_TRACING,
+       .expected_attach_type = BPF_TRACE_FENTRY,
+       .kfunc = "bpf_fentry_test9",
+},