From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=162.62.57.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796224503; b=yq4EsmWrGr06kB5ew7noUEy8IMmlsdjPxMTCLPkuzYWpVSKGClkch+tjXsJ/FvPum6C9 IAXSkaSNS8b4niZ8Tkk9lZOG7WCQPn1V9RMjIIbROV+P0wuUwMAHygBmmftwK7djdkfI2 sesjhyVsDjafhZGqOiCFMgV+dSychJGPP8eHcxGJ1ZpMP6maKCiY/QArWwf6KI9g32QCs ec+OzVHSjXKRafYeZdda8N+gBKCafdPu4GAIDo/pJzu4vkvHmIDngTYYOSe4Ws7qp2Mlf Z6VAxPhd0GRxJEQP6ukFy+IqqVUg4WEkxyo69yNZhRFE36X/V1eYPrrLLCJtzZo+fnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796224503; h=DMARC-Filter:DKIM-Signature:Received:X-QQ-mid:Message-ID: X-QQ-XMAILINFO:X-QQ-XMRINFO:From:To:Cc:Subject:Date:X-OQ-MSGID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=byeYkmOqsUOmQzNGQrm897jexEWL9t6oJ2DZonTj6a4=; b=nts6usnk5fnxlDklfLetRTXOQNIssYAQtpfjY3NtNrg0S46+PJU0L4N7yJ50eDNqiOxZ MFsrMh5lJvJeSxKSDpO15Al2Cxb4L2h9fAilAqhmd3+PkmYSwSNeWi6ZLrTdAlxbdcVk0 a1EYjM+kkvyow77vFYWq59uSjaN7lbrmfnXXruJmwaiWOT31EuzRhAlKKBFl55F7SeT88 Ngwfslb/AlORZ+6kYFHqRfIR3ES3vjbO4qlp/Ps9+dtUR+UZy04ubM6oryGhXjxG6BESd R3q4UpJCI2xcoQV7uNqu9EuNZhLXd3EMB/Kh5iKhD751rXDX/2i8PtBgb95Y6uSFjTg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=LhwID97x; arc=none smtp.remote-ip=162.62.57.49 Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C24A606A327; Wed, 2 Dec 2026 15:14:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5C24A606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=LhwID97x DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1796224495; bh=byeYkmOqsUOmQzNGQrm897jexEWL9t6oJ2DZonTj6a4=; h=From:To:Cc:Subject:Date; b=LhwID97xIKhXdwe9pApEuhw2J8HkYYzgNt/V3EqG5gPt3dh9TzfLwEml8ZllR4/hS 3nmOKWEf2lfar54gSLrH2g/oMB6SF3EKN1R5LugrYn7CTpcBaGbAaMB2xyBt79dedD xpJwtA4NANt0gU5vpMfgp1LXR9eqHouKLA6Q4fjE= Received: from ikun.localdomain ([221.176.157.242]) by newxmesmtplogicsvrsza73-0.qq.com (NewEsmtp) with SMTP id 3AB3FCCD; Wed, 02 Dec 2026 23:14:43 +0800 X-QQ-mid: xmsmtpt1796224483tmfb4udkn Message-ID: X-QQ-XMAILINFO: MRMtjO3A6C9XOn9nIv5MPQmy6L9WTjvB/YphB1YhoWmmmK7jOzCujowoU+C1vM 47y2wOfILGQv6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164729207@qq.com> To: tytso@mit.edu Cc: adilger.kernel@dilger.ca, libaokun@linux.alibaba.com, jack@suse.cz, ojaswin@linux.ibm.com, ritesh.list@gmail.com, yi.zhang@huawei.com, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] ext4: restore the old mode if the ACL update fails Date: Wed, 2 Dec 2026 23:14:40 +0800 X-OQ-MSGID: <20261202151441.148824-1-3164729207@qq.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ext4_setattr() applies setattr_copy() and mark_inode_dirty() before posix_acl_chmod(). When chmod() only changes the mode, the new mode is already dirty when the ACL update fails (for example with ENOSPC). The syscall returns an error, but the inode mode is persisted while the access ACL still describes the old mode, violating the ACL/mode invariant. Save the old mode and restore it (and mark the inode dirty again) when posix_acl_chmod() fails, so a failed chmod() leaves both the mode and the ACL at their old values. Tested on Linux 6.12.1 and 7.4-rc3 with two files sharing an access ACL on a full filesystem. chmod(A, 0700) returns ENOSPC. Before the change A's mode was 0700 while the ACL mask remained r-x; after the change A's mode remains 0650 with the same ACL. The control file B is unchanged and e2fsck -fn passes in both cases. Fixes: 64e178a7118b ("ext2/3/4: use generic posix ACL infrastructure") Cc: stable@vger.kernel.org Signed-off-by: Alan <3164729207@qq.com> --- fs/ext4/inode.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index b4d581aa5ee1ae..9de412540ddef1 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -7029,6 +7029,7 @@ int ext4_setattr(const struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr) { struct inode *inode = d_inode(dentry); + umode_t old_mode = inode->i_mode; int error, rc = 0; int orphan = 0; const unsigned int ia_valid = attr->ia_valid; @@ -7173,8 +7174,19 @@ int ext4_setattr(const struct mnt_idmap *idmap, struct dentry *dentry, if (orphan && inode->i_nlink) ext4_orphan_del(NULL, inode); - if (!error && (ia_valid & ATTR_MODE)) + if (!error && (ia_valid & ATTR_MODE)) { rc = posix_acl_chmod(idmap, dentry, inode->i_mode); + if (rc) { + /* + * The mode was already copied into the inode and marked + * dirty. If the ACL update failed, chmod() returns an + * error but the new mode must not remain on disk while + * the ACL still describes the old mode. + */ + inode->i_mode = old_mode; + mark_inode_dirty(inode); + } + } err_out: if (error) base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e -- 2.53.0