diff options
| author | Kumar Kartikeya Dwivedi <memxor@gmail.com> | 2024-11-04 09:19:59 -0800 |
|---|---|---|
| committer | Alexei Starovoitov <ast@kernel.org> | 2024-11-04 11:37:36 -0800 |
| commit | d798ce3f4cab1b0d886b19ec5cc8e6b3d7e35081 (patch) | |
| tree | b956b98fc4eb826326bb8e321144ce40e4bc63ab /tools/testing/selftests/bpf/progs/raw_tp_null.c | |
| parent | selftests/bpf: Clean up open-coded gettid syscall invocations (diff) | |
| download | linux-d798ce3f4cab1b0d886b19ec5cc8e6b3d7e35081.tar.gz linux-d798ce3f4cab1b0d886b19ec5cc8e6b3d7e35081.zip | |
selftests/bpf: Add tests for raw_tp null handling
Ensure that trusted PTR_TO_BTF_ID accesses perform PROBE_MEM handling in
raw_tp program. Without the previous fix, this selftest crashes the
kernel due to a NULL-pointer dereference. Also ensure that dead code
elimination does not kick in for checks on the pointer.
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20241104171959.2938862-4-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/raw_tp_null.c')
| -rw-r--r-- | tools/testing/selftests/bpf/progs/raw_tp_null.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/raw_tp_null.c b/tools/testing/selftests/bpf/progs/raw_tp_null.c new file mode 100644 index 000000000000..457f34c151e3 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/raw_tp_null.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */ + +#include <vmlinux.h> +#include <bpf/bpf_tracing.h> + +char _license[] SEC("license") = "GPL"; + +int tid; +int i; + +SEC("tp_btf/bpf_testmod_test_raw_tp_null") +int BPF_PROG(test_raw_tp_null, struct sk_buff *skb) +{ + struct task_struct *task = bpf_get_current_task_btf(); + + if (task->pid != tid) + return 0; + + i = i + skb->mark + 1; + /* The compiler may move the NULL check before this deref, which causes + * the load to fail as deref of scalar. Prevent that by using a barrier. + */ + barrier(); + /* If dead code elimination kicks in, the increment below will + * be removed. For raw_tp programs, we mark input arguments as + * PTR_MAYBE_NULL, so branch prediction should never kick in. + */ + if (!skb) + i += 2; + return 0; +} |
