]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
binfmt_misc: use exe_file_deny_write_access() for the interpreter clone
authorChristian Brauner <brauner@kernel.org>
Fri, 10 Jul 2026 09:33:03 +0000 (11:33 +0200)
committerChristian Brauner <brauner@kernel.org>
Tue, 28 Jul 2026 13:50:26 +0000 (15:50 +0200)
For MISC_FMT_OPEN_FILE entries load_misc_binary() clones the
registered interpreter file and denies write access to the clone via
plain deny_write_access(). The clone is installed as
bprm->interpreter and later released by the exec machinery through
exe_file_allow_write_access() which skips the i_writecount increment
for files with FMODE_FSNOTIFY_HSM set.

The deny and allow side can therefore come to different conclusions
when pre-content watches are in play: if a pre-content watch is added
to the interpreter after registration every subsequent exec through
that entry takes a write denial on the clone that is never paired
with a write allowance, driving the interpreter inode's i_writecount
further down with each exec and leaving the interpreter unwritable
even after the entry and all its users are gone.

Take the write denial via exe_file_deny_write_access() so both sides
of the pairing base their decision on the same file mode, and
propagate failure instead of silently ignoring it: an interpreter
that is concurrently open for writing now fails the exec with
ETXTBSY, exactly like an interpreter freshly opened via open_exec()
would.

Link: https://patch.msgid.link/20260710-work-binfmt_misc-locking-v3-2-a162f7cb58d6@kernel.org
Fixes: 0357ef03c94e ("fs: don't block write during exec on pre-content watched files")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
fs/binfmt_misc.c

index adab06d18550998bca4372251ab23dd900ddb378..bf7d6b975825dc296ece7dcfb673de8f7f5ebfdb 100644 (file)
@@ -249,8 +249,14 @@ static int load_misc_binary(struct linux_binprm *bprm)
 
        if (fmt->flags & MISC_FMT_OPEN_FILE) {
                interp_file = file_clone_open(fmt->interp_file);
-               if (!IS_ERR(interp_file))
-                       deny_write_access(interp_file);
+               if (!IS_ERR(interp_file)) {
+                       int err = exe_file_deny_write_access(interp_file);
+
+                       if (err) {
+                               fput(interp_file);
+                               interp_file = ERR_PTR(err);
+                       }
+               }
        } else {
                interp_file = open_exec(fmt->interpreter);
        }