mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aayush7352 <aayushdixit924@gmail.com>
To: linux-fsdevel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>,
	Kees Cook <kees@kernel.org>,
	linux-kernel@vger.kernel.org,
	Aayush Dixit <aayushdixit924@gmail.com>
Subject: [PATCH] binfmt_misc: fix leaked write-access denial on F-flag interpreter inode
Date: Tue, 21 Jul 2026 15:26:59 +0530	[thread overview]
Message-ID: <20260721095659.80690-1-aayushdixit924@gmail.com> (raw)

From: Aayush Dixit <aayushdixit924@gmail.com>

put_binfmt_handler() closes an F-flag (MISC_FMT_OPEN_FILE) entry's
interpreter file without restoring the write access that open_exec()
denied at registration.  Every register/delete cycle of an F entry
leaks one i_writecount denial on the interpreter's inode, so that
inode returns -ETXTBSY to all writers until it is evicted from the
inode cache or the machine reboots.

The registration error path (add_entry failure) correctly calls
exe_file_allow_write_access() before filp_close(), but the normal
teardown path in put_binfmt_handler() was missing it.

Fix by adding exe_file_allow_write_access() before filp_close() in
put_binfmt_handler().  exe_file_allow_write_access() is NULL-safe
and skips FMODE_FSNOTIFY_HSM files, so no imbalance is possible.

Fixes: 948b701a607f ("binfmt_misc: add persistent opened binary handler for containers")
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Aayush7352 <aayushdixit924@gmail.com>
---
 fs/binfmt_misc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index 84349fcb9..de50a7468 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -162,8 +162,10 @@ static Node *get_binfmt_handler(struct binfmt_misc *misc,
 static void put_binfmt_handler(Node *e)
 {
 	if (refcount_dec_and_test(&e->users)) {
-		if (e->flags & MISC_FMT_OPEN_FILE)
+		if (e->flags & MISC_FMT_OPEN_FILE) {
+			exe_file_allow_write_access(e->interp_file);
 			filp_close(e->interp_file, NULL);
+		}
 		kfree(e);
 	}
 }
-- 
2.55.0


             reply	other threads:[~2026-07-21  9:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21  9:56 Aayush7352 [this message]
2026-07-22 14:05 ` Christian Brauner
  -- strict thread matches above, loose matches on Subject: below --
2026-07-21  8:47 Aayush7352

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=20260721095659.80690-1-aayushdixit924@gmail.com \
    --to=aayushdixit924@gmail.com \
    --cc=brauner@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®