Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Alan <3164729207@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	[thread overview]
Message-ID: <tencent_9246D288C7818FCDAA2F130315D73AFDEE05@qq.com> (raw)

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


                 reply	other threads:[~2026-12-02 15:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=tencent_9246D288C7818FCDAA2F130315D73AFDEE05@qq.com \
    --to=3164729207@qq.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    /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