From: sashiko-bot@kernel.org
To: "Anastasios Papagiannis" <tasos.papagiannnis@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 3/7] exec: Clear bprm->mm before dropping its reference
Date: Mon, 31 Aug 2026 10:25:02 +0000 [thread overview]
Message-ID: <20260831102503.4CC8C1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260831092305.42062-4-tasos.papagiannnis@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free of `bprm->file` via eBPF kfuncs due to dangling trusted pointer.
--
commit ac94f9ff4f270354d3714d4162d6adfa946a8fdf
Author: Anastasios Papagiannis <tasos.papagiannnis@gmail.com>
exec: Clear bprm->mm before dropping its reference
This commit clears bprm->mm before calling mmput() in free_bprm().
This ensures that eBPF programs cannot access a dangling mm_struct
pointer when hooking into execution paths.
> 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 is a pre-existing issue, but since this patch addresses dangling
pointers in free_bprm() for eBPF, does bprm->file need similar handling?
Further down in free_bprm(), the code drops the file reference and then
calls a hookable function:
do_close_execat(bprm->file);
/* An unconsumed PT_INTERP substitute from a binfmt_misc loader entry. */
bprm_drop_loader(bprm);
When kernel_execve() fails in a kernel thread, free_bprm() is called.
The do_close_execat() call drops the final reference to the file.
Because this executes in a kernel thread (PF_KTHREAD), fput() queues
the file for asynchronous freeing via delayed_fput_work.
Right after this, bprm_drop_loader() is called. If an eBPF fentry program
is attached to bprm_drop_loader, it receives the bprm argument.
Because the BPF verifier defines the file pointer within linux_binprm as
BTF_TYPE_SAFE_TRUSTED, the verifier trusts the pointer. The eBPF program
can read bprm->file and pass it to a kfunc like bpf_get_file_xattr().
Could this result in a use-after-free if the kfunc dereferences the file
pointer concurrently while the workqueue frees it?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831092305.42062-1-tasos.papagiannnis@gmail.com?part=3
next prev parent reply other threads:[~2026-08-31 10:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 9:22 [PATCH bpf-next v3 0/7] bpf: Add user memory access kfuncs for mm_struct Anastasios Papagiannis
2026-08-31 9:22 ` [PATCH bpf-next v3 1/7] mm: Add copy_remote_mm_str() Anastasios Papagiannis
2026-08-31 9:23 ` [PATCH bpf-next v3 2/7] bpf: Add user memory access kfuncs for mm_struct Anastasios Papagiannis
2026-08-31 10:01 ` sashiko-bot
2026-08-31 10:43 ` bot+bpf-ci
2026-08-31 9:23 ` [PATCH bpf-next v3 3/7] exec: Clear bprm->mm before dropping its reference Anastasios Papagiannis
2026-08-31 10:25 ` sashiko-bot [this message]
2026-08-31 10:30 ` bot+bpf-ci
2026-09-01 3:19 ` sun jian
2026-09-01 8:56 ` sun jian
2026-08-31 9:23 ` [PATCH bpf-next v3 4/7] bpf: Allow reads through trusted-or-null BTF pointers Anastasios Papagiannis
2026-08-31 10:43 ` bot+bpf-ci
2026-08-31 9:23 ` [PATCH bpf-next v3 5/7] selftests/bpf: Cover trusted-or-null BTF pointer reads Anastasios Papagiannis
2026-08-31 10:43 ` bot+bpf-ci
2026-08-31 10:55 ` sashiko-bot
2026-08-31 9:23 ` [PATCH bpf-next v3 6/7] bpf: Mark linux_binprm->mm as trusted-or-null Anastasios Papagiannis
2026-08-31 10:43 ` bot+bpf-ci
2026-09-01 3:50 ` sun jian
2026-08-31 9:23 ` [PATCH bpf-next v3 7/7] selftests/bpf: Test mm_struct user memory kfuncs with linux_binprm 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=20260831102503.4CC8C1F00A3D@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.