exec: release the replaced file with do_close_execat()

When the format search stages an interpreter exec_binprm() swaps it
in and releases the file it replaces. Dropping the write denial the
open took is done manually ahead of both release paths. The one path
that keeps the file silently relies on it not being called.

Let's just use do_close_execat() on the two paths that release the file
and drop the denial explicitly on the one that does not.

No functional change.

Link: https://patch.msgid.link/20260721-work-bpf-binfmt_misc-ptinterp-v2-6-e57866e4ae0f@kernel.org
Reviewed-by: Farid Zakaria <farid.m.zakaria@gmail.com>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2026-07-21 16:13:48 +02:00
parent c41b9cd8cf
commit 9c50e37ca7
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2

View File

@ -1735,15 +1735,17 @@ static int exec_binprm(struct linux_binprm *bprm)
bprm->file = bprm->interpreter;
bprm->interpreter = NULL;
exe_file_allow_write_access(exec);
if (unlikely(bprm->have_execfd)) {
if (bprm->executable) {
fput(exec);
do_close_execat(exec);
return -ENOEXEC;
}
/* Only the reference is kept, for AT_EXECFD. */
exe_file_allow_write_access(exec);
bprm->executable = exec;
} else
fput(exec);
} else {
do_close_execat(exec);
}
}
audit_bprm(bprm);