From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796298563; b=svGHCdfC4wA6ZQsIHQWa0oxXuKRmLjZmegKMnkDxi+Wxysg87OO9l3q353XLQpYVyu+q S5uqHZmHFHnLN/S4CdEzPVzQhswh8T8sCYT1taohHqnXZuRibfKXmfhujrbMHak9ITVtZ 333Xl3kQtTHs2uz0tyxeuKM+mPNFzwRTupy/p9iwTkLSmxSQN5spVPkUnZ3FqfJlQ8Rlt 7IvJZBK8tNzTuvwVUeKy7IkkiHiFx9nk3vzYqYqfACH+jQmXMHsXugg2L4A4ZCXa/0xB0 slRQQubtvP6nKENw1JU+a61MO3zyFI8yZyOSOP1Mr0hR9f306XX16UG6mbQbaUaWAog== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796298563; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=7X/+iG2aaFXBIW+x8uC75J/kIwebSyB2eYPyjQfi1Pw=; b=HO8GRS5vQbDaSLq2/edV1T6PUaImSMWO1GHEzkFY3GPxJYcqnVAMF8muG6zxY0/qaNea 8ZHZYzrVCWNscK+EFtUBQqeTtTxukcxFfDPUkRxItAMkl+Uq9FKxm5Bk5RQYUYMpgdw2P PWWryNx5PJPb++QCdlkD6SIOJ1oTJfjUM8bCl9B1IdqMQWAMJZsGMbF1FXJXCtpRZH/04 V3QHOmv/rMWzsqTXeoyCyXNOCQ20Og21RYVKVkAAOLrlesDSr2ICgwe2r84Z/ACOEiT7x KCmP11FqAFKMVaYFBLRjXG4reUER+eiw/y9fulBV+76/47qQ8mTzoEk5p/E2LYH2/Rw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="X7j1/cqP"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A8F9606A322 for ; Thu, 3 Dec 2026 11:49:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=X7j1/cqP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1173D1F00896; Thu, 3 Dec 2026 11:49:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796298563; bh=7X/+iG2aaFXBIW+x8uC75J/kIwebSyB2eYPyjQfi1Pw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=X7j1/cqPb5GBx3tdpsHmi0cOwZ8Id+3xz8r/ixlbUd9EDLPBkJl8xTpqsIaqvLVgb f/OLPCaAsij3EhUGHbrIdwsHRsbtx6PRoBBfYgvX+RgA+6uiDRBJA3NEvUcw/VRXG7 ndpQoNI1ZUP2pwDtcpAVyhDkLDhLGn/UMsw0Ij/phxv0DiQoZyEv9Lse2vO8wPU+gu /yVFvppoudSspMmoucPycS3T98ySIJX/zw5jpaOO0LyDTwtkMijJjFLf6IXvmMOE0m rjtUsx4sukerCwK96n5Ro6XBUWDm2Y78soSr8MZ/tQoqG2ReQDcZFMvZoRtGsEZW5Z 7rVg3d/REOXlw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5] ext4: restore mode precisely when ACL chmod fails Reply-To: sashiko-reviews@lists.linux.dev To: Alan <3164729207@qq.com> Cc: linux-ext4@vger.kernel.org, tytso@mit.edu In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 11:49:22 +0000 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Medium] ext4: two-transaction mode rollback in ext4_setattr() loses crash and EIO safety - [Medium] ext4: mode rollback in ext4_setattr() does not advance i_version or ctime - [Medium] ext4: eager setattr_should_drop_sgid() on chown causes spurious CAP_FSETID audit - [Low] ext4: incomplete rollback leaves ctime dirty and unconditionally dirties inode - [Low] ext4: duplicate uid/gid update check in ext4_setattr() -- commit 8c15ed51ea25d79a5b8e6c0f2df051e00ee6e8c4 Author: Alan <3164729207@qq.com> ext4: restore mode precisely when ACL chmod fails This commit saves the original inode mode and ownership-change state in ext4_setattr() and restores the old permission bits (while keeping setid bits cleared for chown or truncate) if posix_acl_chmod() fails. > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > index b4d581aa5ee1a..76f23c8be5291 100644 > --- a/fs/ext4/inode.c > +++ b/fs/ext4/inode.c [ ... ] > @@ -7050,6 +7053,9 @@ int ext4_setattr(const struct mnt_idmap *idmap, str= uct dentry *dentry, > if (error) > return error; > =20 > + owner_changed =3D i_uid_needs_update(idmap, attr, inode) || > + i_gid_needs_update(idmap, attr, inode); > + > error =3D fscrypt_prepare_setattr(dentry, attr); > if (error) > return error; [Severity: Low] This duplicates the i_uid_needs_update() || i_gid_needs_update() check right after dquot_initialize(), and evaluates it before early error returns from fscrypt_prepare_setattr() and dquot_initialize(). Could the existing ownership-update block simply reuse owner_changed (or set it)? > @@ -7096,6 +7102,9 @@ int ext4_setattr(const struct mnt_idmap *idmap, str= uct dentry *dentry, > } > } > =20 > + if (owner_changed && !S_ISDIR(inode->i_mode)) > + kill_sgid =3D setattr_should_drop_sgid(idmap, inode); > + > if (attr->ia_valid & ATTR_SIZE) { > loff_t oldsize =3D inode->i_size; > int shrink =3D (attr->ia_size < inode->i_size); [Severity: Medium] Can calling setattr_should_drop_sgid() unconditionally here trigger spurious CAP_FSETID capability audits on normal chown() calls? For a 02644 regular file (S_ISGID set, S_IXGRP clear) chowned from a group the caller belongs to into one it does not, chown_common() checks the old group without needing CAP_FSETID and leaves ATTR_MODE clear. After i_gid_update() switches inode->i_gid to the new group, this call reaches in_group_or_capable() -> capable_wrt_inode_uidgid() -> ns_capable(CAP_FSETID), emitting false LSM audit denials or setting PF_SUPERPRIV even though kill_sgid is never used. Since inode->i_uid and inode->i_gid are not changed again before the posix_acl_chmod() failure block, deferring this check into that error path (using old_mode) avoids both the spurious capability check and the extra work on the common chown() path. > @@ -7173,8 +7182,31 @@ int ext4_setattr(const struct mnt_idmap *idmap, st= ruct dentry *dentry, > if (orphan && inode->i_nlink) > ext4_orphan_del(NULL, inode); > =20 > - if (!error && (ia_valid & ATTR_MODE)) > + if (!error && (ia_valid & ATTR_MODE)) { > rc =3D posix_acl_chmod(idmap, dentry, inode->i_mode); > + if (rc) { > + umode_t restore =3D old_mode; > + > + /* > + * The mode was already copied into the inode and marked > + * dirty. If the ACL update failed, restore the old > + * permission bits, but do not revive setid bits that > + * VFS cleared for chown or truncate. > + */ > + if (ia_valid & ATTR_KILL_SUID) > + restore &=3D ~S_ISUID; > + if (ia_valid & ATTR_KILL_SGID) > + restore &=3D ~S_ISGID; > + if (owner_changed && !S_ISDIR(old_mode)) { > + restore &=3D ~S_ISUID; > + if (kill_sgid) > + restore &=3D ~S_ISGID; > + } > + > + inode->i_mode =3D restore; > + mark_inode_dirty(inode); > + } > + } [Severity: Medium] Can this two-transaction rollback still leave the failed new mode on disk after a crash or EIO? setattr_copy() and mark_inode_dirty() journal the new inode->i_mode into the raw inode buffer before posix_acl_chmod() runs. When ext4_set_acl() hits -ENOSPC, ext4_should_retry_alloc() calls jbd2_journal_force_commit_nested() whenever s_mb_free_pending is non-zero, committing that first transaction to disk before returning -ENOSPC. A crash or power loss before the rollback transaction commits recovers the on-disk mode and ACL mismatch. In addition, if posix_acl_chmod() fails due to an xattr EIO or corruption that puts the filesystem into emergency read-only or aborts the journal, mark_inode_dirty() -> ext4_dirty_inode() fails in ext4_journal_start() and silently returns, leaving the raw inode buffer with the failed new mode while in-memory inode->i_mode is reverted. Deferring the mode update until posix_acl_chmod() succeeds (or updating both in one transaction) would avoid both failure modes. [Severity: Medium] Can concurrent lockless getattr readers permanently cache the transient failed mode? CPU0 (chmod) CPU1 (getattr / nfsd) ext4_setattr() inode_inc_iversion() (V -> V+1) setattr_copy() (mode=3Dnew, ctime=3DT1) mark_inode_dirty() posix_acl_chmod() ... blocks vfs_getattr() -> generic_fillattr() reads mode=3Dnew, ctime=3DT1, change_cookie=3DV+1 <-- caches new mode posix_acl_chmod() fails inode->i_mode =3D restore mark_inode_dirty() <-- V+1 and T1 unchanged ext4_getattr() calls generic_fillattr() without inode->i_rwsem, so a client such as nfsd can observe the transient new mode paired with the bumped change_cookie and ctime. Because the rollback does not call inode_inc_iversion() or inode_set_ctime_current(), later revalidations see unchanged validators and keep serving the stale failed mode until an unrelated metadata update occurs. [Severity: Low] Does this rollback leave st_ctime updated on disk after a failed mode-only chmod()? chmod_common() sets ATTR_MODE | ATTR_CTIME, so setattr_copy() updates i_ctime before posix_acl_chmod() runs, and only inode->i_mode is restored on failure. Also, when posix_acl_chmod() fails during a truncate() or chown() where notify_change() added ATTR_MODE only to clear setid bits, inode->i_mode already equals restore; guarding the rollback with if (inode->i_mode !=3D restore) avoids starting a redundant journal transaction. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_A4888D4A1C8= 8D882FA54300E719FD3396E09@qq.com?part=3D1