From nobody Wed Apr 8 04:42:29 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4943140DFBA; Wed, 11 Mar 2026 02:07:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773194849; cv=none; b=iBUZyWAuibMu8+F6Pn3EO7ComnVtnZpRkwvJ17TjjLL1ACSUBzbiWpezjQpZkSlwgoAn2lBIs1yyq5KG5WHN4RX4bGZsWABdwuA5hELffVSwYBoFE+WQfnwzGYLEQguRdsCQ475lAvp5vnZwqVrVpznasZoj54I2uZp0FThYPtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773194849; c=relaxed/simple; bh=cw6tn8wxCm/8u7e7FCxBfpmxOiaI7cPaaWPioe1QVv0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=WgdLhARqIpThdg+14W8iVp53hL9hKfjuQ9Cy0mAwGE/RDAy35nKjvt9oxqxu7vgQdOIpT1qMHOkZnUUyfC9dpGqUrXuUtPfc4xvGbyejDodPOuRYXXvE4+N4EftD7iD3NKNIc/HRTomA0HNHvW0IS+WOTDcTljJ8ABWMfo2uOLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=GFawb3gi; arc=none smtp.client-ip=117.135.210.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="GFawb3gi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=11 rxilNzodvuvzCLO3MeHRDznxrP0FHOC7bmEuqJ1b8=; b=GFawb3gikhiyWsj5on PJquTZ2rs7aDllf5iGz3f3JX0tjcgLPoclScVyPz84iKOWkZ575hVjGRtKa+1fmZ hYcxy+zRAB9xlXpcJfuPFV5OgEJGj7+LCCoDAX93ZmzNYjgmwSdVLpLhBjKxMy3u lImlppAKKWayCknO2mUtsCL7g= Received: from pek-lpg-core5.wrs.com (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wAHRmQlzrBpECQpAQ--.39464S2; Wed, 11 Mar 2026 10:06:30 +0800 (CST) From: Robert Garcia To: stable@vger.kernel.org, Zilin Guan Cc: Christian Brauner , Alexander Viro , Robert Garcia , Jan Kara , Eric Biederman , Kees Cook , Andrew Morton , Helge Deller , Lior Ribak , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 6.1.y] binfmt_misc: restore write access before closing files opened by open_exec() Date: Wed, 11 Mar 2026 10:06:29 +0800 Message-Id: <20260311020629.465757-1-rob_garcia@163.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wAHRmQlzrBpECQpAQ--.39464S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kw4fGF48tw1UurW8AF1DWrg_yoW8WF4Dpr W5K34UtrZIqryj9ayvyas8XF15G3Z7Gr12vr4kWw1xXF1rXrs0gFZ2g3yj93W0y397A3yF qF4rC3sYyryUAFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UoCJQUUUUU= X-CM-SenderInfo: 5uresw5dufxti6rwjhhfrp/xtbC5QZDrmmwziZAtAAA3L Content-Type: text/plain; charset="utf-8" From: Zilin Guan [ Upstream commit 90f601b497d76f40fa66795c3ecf625b6aced9fd ] bm_register_write() opens an executable file using open_exec(), which internally calls do_open_execat() and denies write access on the file to avoid modification while it is being executed. However, when an error occurs, bm_register_write() closes the file using filp_close() directly. This does not restore the write permission, which may cause subsequent write operations on the same file to fail. Fix this by calling exe_file_allow_write_access() before filp_close() to restore the write permission properly. Fixes: e7850f4d844e ("binfmt_misc: fix possible deadlock in bm_register_wri= te") Signed-off-by: Zilin Guan Link: https://patch.msgid.link/20251105022923.1813587-1-zilin@seu.edu.cn Signed-off-by: Christian Brauner [ Use allow_write_access() instead of exe_file_allow_write_access() according to commit 0357ef03c94ef ("fs: don't block write during exec on pre-content watched files"). ] Signed-off-by: Robert Garcia --- 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 740dac1012ae..05c235309421 100644 --- a/fs/binfmt_misc.c +++ b/fs/binfmt_misc.c @@ -816,8 +816,10 @@ static ssize_t bm_register_write(struct file *file, co= nst char __user *buffer, inode_unlock(d_inode(root)); =20 if (err) { - if (f) + if (f) { + allow_write_access(f); filp_close(f, NULL); + } kfree(e); return err; } --=20 2.34.1