From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Matt Bobrowski <mattbobrowski@google.com>
Cc: 梅开彦 <kaiyanm@hust.edu.cn>,
"Daniel Borkmann" <daniel@iogearbox.net>,
bpf <bpf@vger.kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
hust-os-kernel-patches@googlegroups.com,
"Yinhao Hu" <dddddd@hust.edu.cn>,
dzm91@hust.edu.cn, "KP Singh" <kpsingh@kernel.org>
Subject: Re: bpf: mmap_file LSM hook allows NULL pointer dereference
Date: Wed, 3 Dec 2025 10:23:43 -0800 [thread overview]
Message-ID: <CAADnVQLf10J688CXFWg+=UaOv_zPTr3ViqNFcjbe5u4no2o_GA@mail.gmail.com> (raw)
In-Reply-To: <aS_5K_CJcB1rIEVj@google.com>
On Wed, Dec 3, 2025 at 12:47 AM Matt Bobrowski <mattbobrowski@google.com> wrote:
>
> > We can play tricks with __weak. Like:
> >
> > diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
> > index 7cb6e8d4282c..60d269a85bf1 100644
> > --- a/kernel/bpf/bpf_lsm.c
> > +++ b/kernel/bpf/bpf_lsm.c
> > @@ -21,7 +21,7 @@
> > * function where a BPF program can be attached.
> > */
> > #define LSM_HOOK(RET, DEFAULT, NAME, ...) \
> > -noinline RET bpf_lsm_##NAME(__VA_ARGS__) \
> > +__weak noinline RET bpf_lsm_##NAME(__VA_ARGS__) \
> >
> > diff kernel/bpf/bpf_lsm_proto.c
> >
> > +int bpf_lsm_mmap_file(struct file *file__nullable, unsigned long reqprot,
> > + unsigned long prot, unsigned long flags)
> > +{
> > + return 0;
> > +}
> >
> > and above one with __nullable will be in vmlinux BTF.
> >
> > afaik __weak functions are not removed by linker when in non-LTO,
> > but it's still better than
> > +#define bpf_lsm_mmap_file bpf_lsm_mmap_file__original
> > No need to change bpf_lsm.h either.
>
> Annotating with a weak attribute would be quite nice, but the compiler
> will complain about the redefinition of the symbol
> bpf_lsm_mmap_file. To avoid this, we'd still need to rely on the
> rename and ignore dance by using the aforementioned define, which at
> that point would still result in both symbols being exposed in both
> BTF and the .text section.
Not quite. You missed this part in the above:
> > diff kernel/bpf/bpf_lsm_proto.c
it's a different file.
next prev parent reply other threads:[~2025-12-03 18:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-02 7:09 bpf: mmap_file LSM hook allows NULL pointer dereference 梅开彦
2025-12-02 10:38 ` Matt Bobrowski
2025-12-02 14:54 ` Matt Bobrowski
2025-12-02 17:27 ` Alexei Starovoitov
2025-12-02 19:17 ` Matt Bobrowski
2025-12-02 21:40 ` Alexei Starovoitov
2025-12-03 8:47 ` Matt Bobrowski
2025-12-03 18:23 ` Alexei Starovoitov [this message]
2025-12-10 10:02 ` Matt Bobrowski
2025-12-11 21:39 ` Matt Bobrowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAADnVQLf10J688CXFWg+=UaOv_zPTr3ViqNFcjbe5u4no2o_GA@mail.gmail.com' \
--to=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dddddd@hust.edu.cn \
--cc=dzm91@hust.edu.cn \
--cc=hust-os-kernel-patches@googlegroups.com \
--cc=kaiyanm@hust.edu.cn \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mattbobrowski@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).