bpf: Don't mark arguments to fentry/fexit programs as trusted.
authorAlexei Starovoitov <ast@kernel.org>
Thu, 24 Nov 2022 21:53:14 +0000 (13:53 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 24 Nov 2022 22:47:09 +0000 (23:47 +0100)
commitc6b0337f01205decb31ed5e90e5aa760ac2d5b41
tree96f3d431dcf81055a62e168ae8b241893132a77a
parent6099754a1493467d2db15a20756e32e9a69c2cec
bpf: Don't mark arguments to fentry/fexit programs as trusted.

The PTR_TRUSTED flag should only be applied to pointers where the verifier can
guarantee that such pointers are valid.
The fentry/fexit/fmod_ret programs are not in this category.
Only arguments of SEC("tp_btf") and SEC("iter") programs are trusted
(which have BPF_TRACE_RAW_TP and BPF_TRACE_ITER attach_type correspondingly)

This bug was masked because convert_ctx_accesses() was converting trusted
loads into BPF_PROBE_MEM loads. Fix it as well.
The loads from trusted pointers don't need exception handling.

Fixes: 3f00c5239344 ("bpf: Allow trusted pointers to be passed to KF_TRUSTED_ARGS kfuncs")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20221124215314.55890-1-alexei.starovoitov@gmail.com
kernel/bpf/btf.c
kernel/bpf/verifier.c