From: sashiko-bot@kernel.org
To: Alan <3164729207@qq.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH v3] ext4: restore mode precisely when ACL chmod fails
Date: Thu, 03 Dec 2026 09:03:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-247412@kernel.org> (raw)
In-Reply-To: <tencent_9DB0E32EA413DD3419E9397CB335F565620A@qq.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] ext4: speculative i_mode write before posix_acl_chmod()
persists failed mode
- [Medium] ext4: failed posix_acl_chmod() leaves bumped i_version and
ctime unpersisted
- [Medium] ext4: ext4_setattr() skips mark_inode_dirty() after chown on
ACL failure
- [Medium] ext4: setattr_copy() after posix_acl_chmod() rewinds ctime on
ext2/ext3
- [Low] ext4: generic_fillattr() can tear transient new_mode with
post-restore ctime
--
commit 10d9436fd4de4b1a7b1d93757679541afdb6d7d4
Author: Alan <3164729207@qq.com>
ext4: restore mode precisely when ACL chmod fails
This commit moves posix_acl_chmod() ahead of setattr_copy() and
mark_inode_dirty() in ext4_setattr() so a failed ACL update restores the
old mode (while preserving setid drops) and advances i_version and ctime.
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index b4d581aa5ee1a..24d04ee94a37b 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
[ ... ]
> @@ -7173,8 +7178,54 @@ 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))
> - rc = posix_acl_chmod(idmap, dentry, inode->i_mode);
> + if (!error && (ia_valid & ATTR_MODE)) {
> + umode_t new_mode = attr->ia_mode;
> +
> + if (!in_group_or_capable(idmap, inode,
> + i_gid_into_vfsgid(idmap, inode)))
> + new_mode &= ~S_ISGID;
> +
> + /*
> + * Update the ACL before dirtying the new mode. If the ACL
> + * update fails, the old mode is still the one on disk, so we
> + * only need to restore the in-memory mode and invalidate any
> + * cached attributes.
> + */
> + inode->i_mode = new_mode;
> + rc = posix_acl_chmod(idmap, dentry, new_mode);
[Severity: High]
Can writing inode->i_mode before posix_acl_chmod() persist the rejected
new_mode on disk when the ACL update fails?
Inside posix_acl_chmod(), ext4_xattr_block_set() calls dquot_alloc_block(),
whose dquot_alloc_space() unconditionally calls mark_inode_dirty() even with
quotas disabled. That runs ext4_dirty_inode() -> ext4_fill_raw_inode() and
copies new_mode into raw_inode->i_mode.
If block allocation or journaling then fails (for example with -ENOSPC or
-EIO), ext4_setattr() restores old_mode in memory and skips
mark_inode_dirty() when restore == old_mode. After inode eviction or
remount, the inode reloads with new_mode disagreeing with the old ACL.
Concurrent paths that dirty the inode without inode->i_rwsem, such as
touch_atime() or writeback, can also flush new_mode while posix_acl_chmod()
sleeps. During that window, lockless acl_permission_check() also evaluates
permissions against the unapproved new_mode.
Separately, when restore != old_mode, rollback calls void mark_inode_dirty(),
which silently drops ext4_journal_start() failures in ext4_dirty_inode() and
can leave stale setid bits on disk. Updating the ACL xattr before changing
inode->i_mode avoids these issues.
[ ... ]
> + inode->i_mode = restore;
> + inode_inc_iversion(inode);
> + inode_set_ctime_current(inode);
[Severity: Low]
Is advancing i_version and ctime after restoring inode->i_mode enough to stop
concurrent statx() or NFSv4 GETATTR readers from caching new_mode?
ext4_getattr() calls generic_fillattr() without inode->i_rwsem, and
generic_fillattr() reads inode->i_mode before reading ctime and
change_cookie:
CPU0 (ext4_setattr) CPU1 (ext4_getattr)
inode->i_mode = new_mode
posix_acl_chmod() -> error
generic_fillattr()
stat->mode = inode->i_mode
inode->i_mode = restore
inode_inc_iversion(inode)
inode_set_ctime_current(inode)
read ctime, change_cookie <-- torn
Because the steady-state inode now has that same ctime and change_cookie,
later revalidations see no change and keep the rejected new_mode cached.
> + /*
> + * A failed mode-only chmod leaves the on-disk mode
> + * untouched. If VFS nevertheless required setid bits
> + * to be dropped (chown/truncate), persist that part.
> + */
> + if (restore != old_mode)
> + mark_inode_dirty(inode);
> + }
> + }
[Severity: Medium]
Does skipping mark_inode_dirty() when restore == old_mode leave the bumped
i_version and ctime unpersisted on disk?
On a failed mode-only chmod(), clean inode eviction or reboot reloads the
older on-disk i_version and ctime in __ext4_iget(), rolling both backwards.
That breaks i_version monotonicity and lets NFSv4 or statx() readers that
saw the transient new_mode revalidate and keep it cached.
Advancing st_ctime on a failed mode-only chmod() also violates POSIX chmod()
semantics.
> +
> + if (!error && !rc) {
> + if (inc_ivers)
> + inode_inc_iversion(inode);
[Severity: Medium]
What happens on a compound chown + chmod when posix_acl_chmod() fails on a
non-setid file or a directory?
Callers such as __nfsd_setattr() and ksmbd's set_info_sec() submit ATTR_UID
or ATTR_GID together with ATTR_MODE in one notify_change() call. Earlier in
ext4_setattr(), i_uid_update() and i_gid_update() already committed the new
ownership to disk with the old ctime and i_version.
Because restore == old_mode skips mark_inode_dirty() above and this block
now skips setattr_copy() and mark_inode_dirty() when rc is non-zero, the
updated ctime and i_version are never written to disk and roll backwards on
eviction while the ownership change remains persisted.
> + setattr_copy(idmap, inode, attr);
> + mark_inode_dirty(inode);
> + }
[Severity: Medium]
Can calling setattr_copy() after posix_acl_chmod() rewind i_ctime on ext2
and ext3 mounts handled by ext4?
notify_change() snapshots attr->ia_ctime before calling ext4_setattr(), and
posix_acl_chmod() -> ext4_xattr_set_handle() then advances i_ctime to a
newer timestamp via inode_set_ctime_current(). Because ext2_fs_type and
ext3_fs_type do not set FS_MGTIME, is_mgtime(inode) is false.
setattr_copy() therefore overwrites i_ctime with the earlier attr->ia_ctime
and mark_inode_dirty() persists it, breaking ctime monotonicity whenever the
clock advances while posix_acl_chmod() runs.
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_9DB0E32EA413DD3419E9397CB335F565620A@qq.com?part=1
prev parent reply other threads:[~2026-12-03 9:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 15:14 [PATCH] ext4: restore the old mode if the ACL update fails Alan
2026-12-02 15:37 ` sashiko-bot
2026-12-03 4:32 ` [PATCH v2] ext4: restore mode precisely when ACL chmod fails Alan
2026-12-03 4:57 ` sashiko-bot
2026-12-03 8:33 ` [PATCH v3] " Alan
2026-12-03 9:03 ` sashiko-bot [this message]
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=sashiko-outbox-247412@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=3164729207@qq.com \
--cc=linux-ext4@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
/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