selftests/bpf: Add a test for ptr_to_map_value on stack for helper access
authorYonghong Song <yhs@fb.com>
Wed, 4 Aug 2021 17:09:12 +0000 (20:09 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 8 Aug 2021 07:05:24 +0000 (09:05 +0200)
commit b4b638c36b7e7acd847b9c4b9c80f268e45ea30c upstream

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
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/testing/selftests/bpf/progs/bpf_iter_task.c
tools/testing/selftests/bpf/verifier/unpriv.c

index 4983087852a09aff8120c5f0e1f3901284731276..b7f32c160f4e22978cb8a3aad1c520208dfb3aa5 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 0d621c841db143d12f36ef2c5eb7a3a48463c51c..2df9871b169d48521df9c57a356c25518318fd5a 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",