* [PATCH] ext4: restore the old mode if the ACL update fails
@ 2026-12-02 15:14 Alan
2026-12-02 15:37 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Alan @ 2026-12-02 15:14 UTC (permalink / raw)
To: tytso
Cc: adilger.kernel, libaokun, jack, ojaswin, ritesh.list, yi.zhang,
linux-ext4, linux-kernel, stable
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ext4: restore the old mode if the ACL update fails
2026-12-02 15:14 [PATCH] ext4: restore the old mode if the ACL update fails Alan
@ 2026-12-02 15:37 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02 15:37 UTC (permalink / raw)
To: Alan; +Cc: linux-ext4, tytso
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] ext4: restoring old_mode in ext4_setattr() re-enables
S_ISUID/S_ISGID
--
commit 25d855847832145fc418799835c609dfdd478477
Author: Alan <3164729207@qq.com>
ext4: restore the old mode if the ACL update fails
This commit saves the previous inode->i_mode in ext4_setattr() and restores
it if posix_acl_chmod() fails after setattr_copy() has already dirtied the
new mode.
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index b4d581aa5ee1a..9de412540ddef 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);
> + }
> + }
[Severity: High]
Can restoring the full old_mode re-enable S_ISUID or S_ISGID after the file
has already been truncated or chowned?
During truncate() or chown() on a setuid or setgid file, notify_change()
translates ATTR_KILL_SUID and ATTR_KILL_SGID into ATTR_MODE with those bits
cleared in attr->ia_mode. ext4_setattr() commits UID/GID updates and
performs truncation before calling setattr_copy() and posix_acl_chmod().
If posix_acl_chmod() then fails (for example with -ENOSPC when unsharing a
shared xattr block), writing back old_mode restores S_ISUID and S_ISGID on
an inode whose ownership or contents have already been modified on disk.
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_9246D288C7818FCDAA2F130315D73AFDEE05@qq.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 15:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 15:14 [PATCH] ext4: restore the old mode if the ACL update fails Alan
2026-12-02 15:37 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox