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=1796273865; b=EnSRXEaoQj6jkCBu9mSCKeMgMk25SaVfDM3JdUGx67FQ0xpdSxrDQzewZZF2bQmCyBYM nIiyI3v5kGNSTzR5XLoY3EP6wyZjMszmHmsEhxEYZmsrWM1GW2IvjScMAY5QKL4ZTBq8F IZms5bg1OdGUUn2S4OuqNn4Hydd9QZSW3sBctRu+oKPSC0p9OtXx92kR5uFsFuibwjj/h S+c90H4hCqV6koBTYxmuL/ac24lOi8ydQBfeKhuqNCVy7ioI3TfccSJqRB0bCvcTS+FL0 XxCfhQtJa4mwYcZsosg4IX0zCZoGVDX/LXWfgqNO8k5IXU1ILNFITgajNCiOVb6JOgw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796273865; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=eJl0BPjmsuXSbEhDfEX66kG3q7efggRTYHX5ydY5AOk=; b=JwZICaDZQZFwQfc9P9gjj5YIuhb/8I/A4gHN3438nN1VJJ6ltptBJ3P9k2ONh/8fjcE5 vwflHlgZL6iy/D/7czCZ7JAPIp3OS3QMXV0qFikqzVsLLKttEwkVEPpzv7Bt7mG9XVcyf NhYXmWVaVq36f5sDYEhcZMZEbw/QrbUolUxTnqOBOSFAId6zSOBBPenz6zMmjEz864io4 kvtvJxGG/I5up8qkTlhCs/lQt3rsPZSZi0VZOhje/e6BrbYB2fKQOc6C9B3jnBP6BqfJ7 Ox1x8vy+BXpK65YR2oloGqaRKUXMqrxM+1fAVfqnE3FvkliYAw+Y8JfHk+SSNyOVpYQ== 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=gG6+OWri; 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 C19BA606A322 for ; Thu, 3 Dec 2026 04:57:45 +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=gG6+OWri Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BFF41F000C1; Thu, 3 Dec 2026 04:57:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796273865; bh=eJl0BPjmsuXSbEhDfEX66kG3q7efggRTYHX5ydY5AOk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=gG6+OWrijIZXwuUJvLjZDesi88ZUtNOfdhxBHo7Ir8r4m6b4eBF58pqvpfMMuzVBW llHD9ooUZnkqrhEg7DReVH0PTH4/0d5IZXMrvdcG8KhIJRD8k5t3GE2VZZ+g0BmkpD rjYv89wwY33IFh5bbY7FSoWp7N/Td+TVAx5nwNtYTosb/1eWaEZwby37EPV3Fb3nsw NTaquA0r1Tax26B/mrvE2+aEt+v7a3Lp9qqLUxAeE7tVtD8LmicZY6Yp95pJ5JVmRr mChhqQ1ObRFI31YietyjzQUKJlnv+x+ojMhamXT4Dz/v3uDf37Qo1EOg+r+gKaRkng GlygCHDPW2trw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] 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 04:57:44 +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: ext4_setattr() rollback can revive S_ISGID|S_IXGRP after chown - [Medium] ext4: ext4_setattr() rollback strips S_ISGID from directories on error - [Medium] ext4: ext4_setattr() rollback via mark_inode_dirty() drops journal errors - [Medium] ext4: mode rollback in ext4_setattr() skips i_version and ctime updates - [Medium] ext4: two-step i_mode store in ext4_setattr() exposes transient setid bits -- commit b94d8fab0f3cb4ea38b7c97bc032debd416caa17 Author: Alan <3164729207@qq.com> ext4: restore mode precisely when ACL chmod fails This commit saves inode->i_mode on entry to ext4_setattr() and restores it when posix_acl_chmod() fails, keeping S_ISUID and S_ISGID cleared if the setattr also changed ownership or carried ATTR_KILL_SUID or ATTR_KILL_SGID. > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > index b4d581aa5ee1a..ec5fb850c5d40 100644 > --- a/fs/ext4/inode.c > +++ b/fs/ext4/inode.c [ ... ] > @@ -7173,8 +7174,32 @@ 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 new_mode =3D inode->i_mode; [ ... ] > + inode->i_mode =3D old_mode; > + if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_KILL_SUID | > + ATTR_KILL_SGID)) > + inode->i_mode =3D (old_mode & ~(S_ISUID | S_ISGID)) | > + (old_mode & new_mode & > + (S_ISUID | S_ISGID)); [Severity: Medium] Can this rollback leave a regular file with both S_ISGID and S_IXGRP set after its owner or group has already been changed? nfsd_sanitize_attrs() clears S_ISGID on a combined owner and mode SETATTR only when ia_mode has S_IXGRP set: fs/nfsd/vfs.c:nfsd_sanitize_attrs() { ... if (!S_ISDIR(inode->i_mode) && ((iap->ia_valid & ATTR_UID) || (iap->ia_valid & ATTR_GID))) { iap->ia_valid |=3D ATTR_KILL_PRIV; if (iap->ia_valid & ATTR_MODE) { iap->ia_mode &=3D ~S_ISUID; if (iap->ia_mode & S_IXGRP) iap->ia_mode &=3D ~S_ISGID; } ... } If a 02755 file receives a combined owner and mode SETATTR with ia_mode 02644, nfsd_sanitize_attrs() leaves S_ISGID set because S_IXGRP is cleared. ext4_setattr() commits the new UID/GID first via i_uid_update() and i_gid_update(), and if posix_acl_chmod() then fails, this rollback restores S_IXGRP from old_mode while keeping S_ISGID from new_mode. That leaves an executable setgid file (02755) under the new ownership, which bprm_fill_uid() honors on execve(). Evaluating setid stripping against the restored mode (clearing S_ISUID and checking setattr_should_drop_sgid() for non-directories on ATTR_UID/ATTR_GID, plus honoring ATTR_KILL_SUID/ATTR_KILL_SGID) instead of intersecting with new_mode avoids this regression. [Severity: Medium] Does this strip S_ISGID from directories when a combined ownership and mode setattr fails? Under VFS rules (chown_common() and nfsd_sanitize_attrs()), ownership changes on directories do not drop S_ISUID or S_ISGID, because S_ISGID on a directory controls group inheritance rather than execution privilege. If a combined ATTR_UID/ATTR_GID and ATTR_MODE setattr from NFSD or ksmbd tries to change a 02755 directory to 00755 and posix_acl_chmod() fails, this branch clears S_ISGID from the restored mode, silently breaking group inheritance even though chmod failed. The same check also strips S_ISGID from non-executable regular files when ATTR_UID/ATTR_GID is set without checking !S_ISDIR(inode->i_mode) and setattr_should_drop_sgid(). [Severity: Medium] Does writing unmasked old_mode directly to inode->i_mode before masking S_ISUID and S_ISGID open a race with concurrent inode readers and writers? CPU0 CPU1 ext4_setattr() inode->i_mode =3D old_mode touch_atime() -> ext4_dirty_inode() ext4_do_update_inode() ext4_fill_raw_inode() raw_inode->i_mode =3D inode->i_mode <-- snapshots unmasked setid bits inode->i_mode =3D masked_mode mark_inode_dirty(inode) ext4_fill_raw_inode() runs under ei->i_raw_lock without inode->i_rwsem, so a concurrent atime update can journal the transient unmasked setid bits. If the following mark_inode_dirty() silently fails in ext4_dirty_inode() or a crash occurs before it commits, those setid bits persist on disk alongside the already-applied chown or truncate; lockless readers like generic_fillattr() can also observe the intermediate mode. Computing the target mode in a local variable first and only updating inode->i_mode and calling mark_inode_dirty() when it differs from new_mode avoids the transient store and skips a redundant journal transaction when ATTR_KILL_SUID/ATTR_KILL_SGID already matched the masked mode. > + mark_inode_dirty(inode); [Severity: Medium] Can rolling back inode->i_mode via mark_inode_dirty() silently lose the on-disk update if ext4_journal_start() fails? ext4_dirty_inode() starts a new transaction and returns silently if ext4_journal_start() fails (for example with -ENOMEM under the same memory pressure that failed posix_acl_chmod()). Because ext4_write_inode() does not re-copy inode->i_mode into raw_inode, the on-disk buffer keeps new_mode while in-memory inode->i_mode holds old_mode, so the failed mode reappears after eviction or remount. On -ENOSPC, ext4_set_acl() calls ext4_should_retry_alloc() -> jbd2_journal_force_commit_nested(), which can commit the earlier transaction containing new_mode before rollback runs, breaking crash atomicity. While posix_acl_chmod() sleeps, lockless acl_permission_check() can also evaluate permissions against the unvalidated new_mode, and i_ctime and i_version remain mutated after a failed mode-only chmod. Updating the ACL before dirtying the mode change, or performing both in a single JBD2 transaction, avoids split transactions and silent rollback failures. [Severity: Medium] Does reverting inode->i_mode without advancing i_version or ctime leave concurrent statx() and NFSv4 caches stuck on new_mode? CPU0 CPU1 ext4_setattr() inode_inc_iversion() (V -> V+1) setattr_copy() (new_mode, T1) posix_acl_chmod() (sleeps) ext4_getattr() -> generic_fillattr() caches (new_mode, V+1, T1) inode->i_mode =3D old_mode mark_inode_dirty(inode) revalidates: sees (V+1, T1) unchanged <-- keeps stale new_mode cached ext4_getattr() reads inode->i_mode, ctime, and inode_query_iversion() without inode->i_rwsem. Because the rollback does not call inode_maybe_inc_iversion() or update ctime, a reader that observed new_mode during posix_acl_chmod() sees the same change cookie and ctime afterward and retains new_mode until an unrelated modification updates the inode. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_16875A36A63= E6B8C6DDCD274A49B38A37D07@qq.com?part=3D1