Re: [RFC PATCH bpf-next 2/2] bpf: Get fentry func addr from user when BTF info invalid
From: Alexei Starovoitov
Date: Wed Apr 30 2025 - 18:23:39 EST
On Wed, Apr 30, 2025 at 10:57 AM Alan Maguire <alan.maguire@xxxxxxxxxx> wrote:
> > +
> > + if (!addr && (prog->expected_attach_type == BPF_TRACE_FENTRY ||
> > + prog->expected_attach_type == BPF_TRACE_FEXIT)) {
> > + fname = kallsyms_lookup((unsigned long)prog->aux->fentry_func,
> > + NULL, NULL, NULL, trace_symbol);
> > + if (fname)
> > + addr = (long)prog->aux->fentry_func;
>
>
> We should do some validation that the fname we get back matches the BTF
> func name prefix (fname "foo.isra.0" matches "foo") I think?
I don't think that will be enough.
User space should not be able to pass a random kernel address
and convince the kernel that it matches a particular btf_id.
As discussed in the other thread matching based on name is
breaking apart.
pahole does all the safety check to make sure name/addr/btf_id
are consistent.
We shouldn't be adding workarounds like this because
pahole/btf/kernel build is not smart enough.
pw-bot: cr