]> git.dujemihanovic.xyz Git - linux.git/commitdiff
bpf: Set run context for rawtp test_run callback
authorJiri Olsa <jolsa@kernel.org>
Tue, 4 Jun 2024 15:00:24 +0000 (17:00 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 5 Jun 2024 07:41:33 +0000 (09:41 +0200)
syzbot reported crash when rawtp program executed through the
test_run interface calls bpf_get_attach_cookie helper or any
other helper that touches task->bpf_ctx pointer.

Setting the run context (task->bpf_ctx pointer) for test_run
callback.

Fixes: 7adfc6c9b315 ("bpf: Add bpf_get_attach_cookie() BPF helper to access bpf_cookie value")
Reported-by: syzbot+3ab78ff125b7979e45f9@syzkaller.appspotmail.com
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Closes: https://syzkaller.appspot.com/bug?extid=3ab78ff125b7979e45f9
Link: https://lore.kernel.org/bpf/20240604150024.359247-1-jolsa@kernel.org
net/bpf/test_run.c

index f6aad4ed2ab2f6b09ad2f6442cde26b39949871a..36ae54f57bf5743b37c5c785baa7c4aa8e871024 100644 (file)
@@ -727,10 +727,16 @@ static void
 __bpf_prog_test_run_raw_tp(void *data)
 {
        struct bpf_raw_tp_test_run_info *info = data;
+       struct bpf_trace_run_ctx run_ctx = {};
+       struct bpf_run_ctx *old_run_ctx;
+
+       old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx);
 
        rcu_read_lock();
        info->retval = bpf_prog_run(info->prog, info->ctx);
        rcu_read_unlock();
+
+       bpf_reset_run_ctx(old_run_ctx);
 }
 
 int bpf_prog_test_run_raw_tp(struct bpf_prog *prog,