From: sashiko-bot@kernel.org
To: "Anastasios Papagiannis" <tasos.papagiannnis@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v4 2/7] exec: Clear bprm->mm before dropping its reference
Date: Fri, 04 Sep 2026 15:20:17 +0000 [thread overview]
Message-ID: <20260904152018.0B7B11F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260904145340.40212-3-tasos.papagiannnis@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Incomplete fix: `free_bprm` leaves `bprm->file` as a dangling pointer after dropping its reference, exposing a Use-After-Free to BPF programs because `bprm->file` is annotated as a trusted pointer.
--
commit 4cbe3f184f9ef608b904d3293b9a6181c4e399fa
Author: Anastasios Papagiannis <tasos.papagiannnis@gmail.com>
exec: Clear bprm->mm before dropping its reference
Once mmput() drops the final reference to bprm->mm, the pointer must no
longer remain accessible through struct linux_binprm. This is required for
BPF kfuncs where bprm->mm is either NULL or points to a live mm_struct to
ensure safe access.
> diff --git a/fs/exec.c b/fs/exec.c
> index a14f28b15607a..4b4d8f0627a7c 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -1453,9 +1453,12 @@ void bprm_drop_loader(struct linux_binprm *bprm)
>
> static void free_bprm(struct linux_binprm *bprm)
> {
> - if (bprm->mm) {
> + struct mm_struct *mm = bprm->mm;
> +
> + if (mm) {
> acct_arg_size(bprm, 0);
> - mmput(bprm->mm);
> + bprm->mm = NULL;
> + mmput(mm);
> }
> if (bprm->user_ns)
> put_user_ns(bprm->user_ns);
[Severity: High]
This isn't a bug introduced by this patch, but since this commit prevents a
use-after-free for bprm->mm, should we also clear bprm->file?
Looking slightly further down in free_bprm(), the reference to bprm->file is
dropped, but the pointer is not set to NULL:
do_close_execat(bprm->file);
/* An unconsumed PT_INTERP substitute from a binfmt_misc loader entry. */
bprm_drop_loader(bprm);
Immediately after, the global function bprm_drop_loader() is called. If a
BPF fentry program is attached to bprm_drop_loader(), it will receive the
bprm argument.
Because the BPF verifier explicitly annotates bprm->file as a trusted
pointer in kernel/bpf/verifier.c:
BTF_TYPE_SAFE_TRUSTED(struct linux_binprm) {
struct file *file;
};
Could this allow the BPF program to read the dangling bprm->file pointer as
a PTR_TRUSTED pointer and pass it to kfuncs requiring trusted arguments,
resulting in a use-after-free?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904145340.40212-1-tasos.papagiannnis@gmail.com?part=2
next prev parent reply other threads:[~2026-09-04 15:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 14:53 [PATCH bpf-next v4 0/7] bpf: Add user memory access kfuncs for mm_struct Anastasios Papagiannis
2026-09-04 14:53 ` [PATCH bpf-next v4 1/7] mm: Add copy_remote_mm_str() Anastasios Papagiannis
2026-09-07 10:59 ` David Hildenbrand (Arm)
2026-09-07 13:41 ` Anastasios Papagiannis
2026-09-07 14:01 ` Lorenzo Stoakes (ARM)
2026-09-07 14:04 ` David Hildenbrand (Arm)
2026-09-04 14:53 ` [PATCH bpf-next v4 2/7] exec: Clear bprm->mm before dropping its reference Anastasios Papagiannis
2026-09-04 15:20 ` sashiko-bot [this message]
2026-09-04 15:30 ` Anastasios Papagiannis
2026-09-04 14:53 ` [PATCH bpf-next v4 3/7] bpf: Add user memory access kfuncs for mm_struct Anastasios Papagiannis
2026-09-04 14:53 ` [PATCH bpf-next v4 4/7] bpf: Allow reads through trusted-or-null BTF pointers Anastasios Papagiannis
2026-09-04 14:53 ` [PATCH bpf-next v4 5/7] selftests/bpf: Cover trusted-or-null BTF pointer reads Anastasios Papagiannis
2026-09-04 14:53 ` [PATCH bpf-next v4 6/7] bpf: Mark linux_binprm->mm as trusted-or-null Anastasios Papagiannis
2026-09-04 14:53 ` [PATCH bpf-next v4 7/7] selftests/bpf: Test mm_struct user memory kfuncs with linux_binprm Anastasios Papagiannis
2026-09-04 18:26 ` [PATCH bpf-next v4 0/7] bpf: Add user memory access kfuncs for mm_struct Andrew Morton
2026-09-07 6:58 ` Anastasios Papagiannis
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=20260904152018.0B7B11F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tasos.papagiannnis@gmail.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