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