diff options
| author | Philo Lu <lulie@linux.alibaba.com> | 2024-09-11 11:37:15 +0800 |
|---|---|---|
| committer | Martin KaFai Lau <martin.lau@kernel.org> | 2024-09-11 08:56:37 -0700 |
| commit | 8aeaed21befc90f27f4fca6dd190850d97d2e9e3 (patch) | |
| tree | e56c73aacde63828784d60bf03d78c246f509b12 /kernel/bpf/btf.c | |
| parent | bpf, cpumap: Move xdp:xdp_cpumap_kthread tracepoint before rcv (diff) | |
| download | linux-8aeaed21befc90f27f4fca6dd190850d97d2e9e3.tar.gz linux-8aeaed21befc90f27f4fca6dd190850d97d2e9e3.zip | |
bpf: Support __nullable argument suffix for tp_btf
Pointers passed to tp_btf were trusted to be valid, but some tracepoints
do take NULL pointer as input, such as trace_tcp_send_reset(). Then the
invalid memory access cannot be detected by verifier.
This patch fix it by add a suffix "__nullable" to the unreliable
argument. The suffix is shown in btf, and PTR_MAYBE_NULL will be added
to nullable arguments. Then users must check the pointer before use it.
A problem here is that we use "btf_trace_##call" to search func_proto.
As it is a typedef, argument names as well as the suffix are not
recorded. To solve this, I use bpf_raw_event_map to find
"__bpf_trace##template" from "btf_trace_##call", and then we can see the
suffix.
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Philo Lu <lulie@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240911033719.91468-2-lulie@linux.alibaba.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Diffstat (limited to 'kernel/bpf/btf.c')
| -rw-r--r-- | kernel/bpf/btf.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 520f49f422fe..7e03a98ccb7c 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -6523,6 +6523,9 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type, if (prog_args_trusted(prog)) info->reg_type |= PTR_TRUSTED; + if (btf_param_match_suffix(btf, &args[arg], "__nullable")) + info->reg_type |= PTR_MAYBE_NULL; + if (tgt_prog) { enum bpf_prog_type tgt_type; |
