* [PATCH bpf-next] exec: Drop bprm loader before closing bprm->file
@ 2026-09-01 11:40 Sun Jian
2026-09-03 7:24 ` Christian Brauner
0 siblings, 1 reply; 2+ messages in thread
From: Sun Jian @ 2026-09-01 11:40 UTC (permalink / raw)
To: kees, viro, brauner
Cc: jack, linux-mm, linux-fsdevel, linux-kernel, bpf,
tasos.papagiannnis, Sun Jian
free_bprm() currently drops what may be the final reference to
bprm->file before calling bprm_drop_loader(). Since
bprm_drop_loader() is attachable via BPF fentry and bprm->file is
exposed as a BTF_TYPE_SAFE_TRUSTED pointer, the file can be observed
after its reference has been released.
Move bprm_drop_loader() before do_close_execat(bprm->file), keeping
the file reference held while the hook runs. This preserves the
existing trusted BTF contract without changing verifier behavior.
The loader file and bprm->file have independent references, so this
reordering does not change their required teardown ordering.
Link: https://sashiko.dev/#/patchset/20260831092305.42062-1-tasos.papagiannnis@gmail.com?part=3
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
fs/exec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/exec.c b/fs/exec.c
index a14f28b15607..263b1f67f1f8 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1469,9 +1469,9 @@ static void free_bprm(struct linux_binprm *bprm)
/* exec swapped the mm but failed before setup_new_exec() freed it */
if (bprm->old_mm)
exec_mm_put_old(bprm->old_mm);
- do_close_execat(bprm->file);
/* An unconsumed PT_INTERP substitute from a binfmt_misc loader entry. */
bprm_drop_loader(bprm);
+ do_close_execat(bprm->file);
do_close_execat(bprm->executable);
/* If a binfmt changed the interp, free it. */
if (bprm->interp != bprm->filename)
base-commit: d761934c9483ecde93fe99d8705282f716dfee50
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next] exec: Drop bprm loader before closing bprm->file
2026-09-01 11:40 [PATCH bpf-next] exec: Drop bprm loader before closing bprm->file Sun Jian
@ 2026-09-03 7:24 ` Christian Brauner
0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2026-09-03 7:24 UTC (permalink / raw)
To: Sun Jian
Cc: Christian Brauner, jack, linux-mm, linux-fsdevel, linux-kernel,
bpf, tasos.papagiannnis, kees, viro
On Tue, 01 Sep 2026 04:40:11 -0700, Sun Jian wrote:
> free_bprm() currently drops what may be the final reference to
> bprm->file before calling bprm_drop_loader(). Since
> bprm_drop_loader() is attachable via BPF fentry and bprm->file is
> exposed as a BTF_TYPE_SAFE_TRUSTED pointer, the file can be observed
> after its reference has been released.
>
> Move bprm_drop_loader() before do_close_execat(bprm->file), keeping
> the file reference held while the hook runs. This preserves the
> existing trusted BTF contract without changing verifier behavior.
>
> [...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes
[1/1] exec: Drop bprm loader before closing bprm->file
https://git.kernel.org/vfs/vfs/c/115bf3e51538
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-03 7:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-01 11:40 [PATCH bpf-next] exec: Drop bprm loader before closing bprm->file Sun Jian
2026-09-03 7:24 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox