OSDN Git Service

selftests/bpf: Add a test for ptr_to_map_value on stack for helper access
authorYonghong Song <yhs@fb.com>
Thu, 10 Dec 2020 01:33:50 +0000 (17:33 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 14 Dec 2020 20:50:10 +0000 (21:50 +0100)
Change bpf_iter_task.c such that pointer to map_value may appear
on the stack for bpf_seq_printf() to access. Without previous
verifier patch, the bpf_iter test will fail.

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20201210013350.943985-1-yhs@fb.com
tools/testing/selftests/bpf/progs/bpf_iter_task.c
tools/testing/selftests/bpf/verifier/unpriv.c

index 4983087..b7f32c1 100644 (file)
@@ -11,9 +11,10 @@ int dump_task(struct bpf_iter__task *ctx)
 {
        struct seq_file *seq = ctx->meta->seq;
        struct task_struct *task = ctx->task;
+       static char info[] = "    === END ===";
 
        if (task == (void *)0) {
-               BPF_SEQ_PRINTF(seq, "    === END ===\n");
+               BPF_SEQ_PRINTF(seq, "%s\n", info);
                return 0;
        }
 
index 91bb77c..a3fe0fb 100644 (file)
        BPF_EXIT_INSN(),
        },
        .fixup_map_hash_8b = { 3 },
-       .errstr = "invalid indirect read from stack off -8+0 size 8",
-       .result = REJECT,
+       .errstr_unpriv = "invalid indirect read from stack off -8+0 size 8",
+       .result_unpriv = REJECT,
+       .result = ACCEPT,
 },
 {
        "unpriv: mangle pointer on stack 1",