]> www.infradead.org Git - users/jedix/linux-maple.git/commit
bpf: Support __nullable argument suffix for tp_btf
authorPhilo Lu <lulie@linux.alibaba.com>
Wed, 11 Sep 2024 03:37:15 +0000 (11:37 +0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Wed, 11 Sep 2024 15:56:37 +0000 (08:56 -0700)
commit8aeaed21befc90f27f4fca6dd190850d97d2e9e3
treee56c73aacde63828784d60bf03d78c246f509b12
parent23dc9867329c72b48e5039ac93fbf50d9099cdb3
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>
kernel/bpf/btf.c
kernel/bpf/verifier.c