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=1796291292; b=PmExG/dvcfNCiaVrurPqZwRxsD/wOVkv5LuJD4WHQ1Pk5xAurcuuixvKvcW8ivbwgXjO dF0C6Pqjpf/bkcV4cWv86j5eeHrmq6OEiaYFGXxjMDPzGlBEtb81yIoUXBHOoJsteqVgu XbvEPrQglx8Wu0fsLIQXXi4a2lKTJpIWAfVHcArvkUHYIgaLxkV9ody103/26pAVpCxJv QudxMk3B8OcR5PL0ySboDRBtzxJiVEO41yTq7fk+/+aWyHFxDRgbPN3IWX5TbtZB1G6dB uxLYNEZLdX10yjhVLisuedCwpbXOiBsjqhG1bMiP4RarpKyJKxAYMRM2rJOioB8cktQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796291292; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=m4GV+14dFV9sesWVtpO6wwui0imEB80M/ETqwe+eG94=; b=rlMxxxnn+POqO4et08V+0Z/bp0cudhYC26LW0imTo5YwwH0mDZSrL5cH25tgWOeiPzSX cjkNkhVaJi8LexTPl3XrQAwK1LyEZdK5MrSBm8EjW4S6+RQJDpdNdRt4FuRAdUzk+Icfq 6qAM0DwcWzzYajBDWjRITpu350xdLEEIt9LM5+RtjDf29tcTlVs0LJD7dSonACj8VeoUK gCo+VrSRzvSTFa/zXjE0PRZ/jDPZH5BXu3aznmW3oVvGgqzXKol1CruSadXqeRB3d2Bay 1/sZbOpOWEyVwjcg+J8TI9Brew7bVKxFtDdZodAlGUC34K4bOJ854RDL954SbrPCFrA== 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=I5UR9nro; 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 5ABE8606A337 for ; Thu, 3 Dec 2026 09:48:12 +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=I5UR9nro Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20F4A1F00893; Thu, 3 Dec 2026 09:48:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796291292; bh=m4GV+14dFV9sesWVtpO6wwui0imEB80M/ETqwe+eG94=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=I5UR9nrocL4E/9cydp2eS/HplmXCrtmRp6v0o+owFDDitHGouoV1Uvr/HLHgCPRL2 I0hOHJYp77C8LG1BIUMADJ2e9nvLttcw3huQshRJW1epPKfxiWCt3anfXBLBWUv8W2 DtKdyIzio/CjNUNKSTZbC7nfmBgLSIJIUohx+T60XAdNCwiMh21XdQeLCbFX+6mnXg +PawQHe38IV1aTdnbCgDgEXn1IAXdmadGFqJvvbVJWkqa/o3lQVlaWpwC68+RnGqFJ PJoTlox3SGxD/vbDJbpTNhzazVxf1MnyMKVPVXoF77fT7r+N6ovbkbc0dwncirFTns ccu6hgeyZ1qOw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4] 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 09:48:11 +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 9 potential issues to consider: - [High] ext4: split ACL and i_mode updates across separate JBD2 transactions - [High] ext4: ext4_setattr() can persist uid/gid with uncleared setid bits on disk - [Medium] ext4: ext4_acl_chmod() ignores ext4_journal_stop() error return - [Medium] ext4: ext4_setattr() bypasses inode_set_ctime_deleg() for ATTR_CTIME_SET - [Medium] ext4: ext4_setattr() unconditionally stamps ctime after setattr_copy() - [Low] ext4: ext4_setattr() updates ctime on ATTR_MODE without ATTR_CTIME - [Low] ext4: ext4_acl_chmod() has unused params and duplicates ext4_set_acl() - [Low] ext4: ext4_setattr() dirties inode on failed setattr with unchanged uid/gid - [Low] ext4: ext4_setattr() runs redundant in_group_or_capable() before ACL chmod -- commit a1eb006c5ae5fa01330ebb5ffaa3d22edaa6640c Author: Alan <3164729207@qq.com> ext4: restore mode precisely when ACL chmod fails This commit adds ext4_acl_chmod() and reorders ext4_setattr() to update the access ACL before calling setattr_copy() and mark_inode_dirty(), with a recovery path to persist ownership or setid changes if the ACL update fails. > diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c > index 59fac55a24261..26ae3c60091d6 100644 > --- a/fs/ext4/acl.c > +++ b/fs/ext4/acl.c > @@ -269,6 +269,75 @@ ext4_set_acl(const struct mnt_idmap *idmap, struct d= entry *dentry, > return error; > } > =20 > +/* > + * Update the access ACL for a mode change without touching inode->i_mod= e. > + * ext4_setattr() uses this so a failed ACL update cannot persist the new > + * mode through an unrelated mark_inode_dirty() from the xattr path. > + */ > +int > +ext4_acl_chmod(const struct mnt_idmap *idmap, struct dentry *dentry, > + umode_t mode) > +{ > + struct inode *inode =3D d_inode(dentry); > + struct posix_acl *acl; > + handle_t *handle; > + int error, credits, retries =3D 0; > + > + if (!IS_POSIXACL(inode)) > + return 0; > + if (!inode->i_op->set_acl) > + return -EOPNOTSUPP; [Severity: Low] This isn't a bug, but idmap is unused here and dentry is only used to extract d_inode(dentry) for an ext4-internal helper called only from ext4_setattr(). The inode->i_op->set_acl check is also unnecessary since ext4_acl_chmod() never calls ->set_acl and notify_change() already rejects symlinks. The journal and -ENOSPC retry loop below also duplicates ext4_set_acl(); sharing a common helper would avoid the duplication and make it easier to keep the ACL and i_mode updates in a single transaction. [ ... ] > + error =3D __ext4_set_acl(handle, inode, ACL_TYPE_ACCESS, acl, > + 0 /* xattr_flags */); > + ext4_journal_stop(handle); [Severity: High] Does stopping the handle here split the access ACL update and the inode->i_mode update across two separate JBD2 transactions? Inside __ext4_set_acl() -> ext4_xattr_set_handle(), ext4_mark_iloc_dirty() serializes the old inode->i_mode into the first transaction, and for IS_SYNC(inode) files ext4_handle_sync() commits it synchronously before ext4_setattr() updates inode->i_mode via setattr_copy() and mark_inode_dirty() -> ext4_dirty_inode() in a second, non-synchronous transaction. This is a durability regression for IS_SYNC inodes and opens a crash-consistency window: if a crash or journal abort drops the second transaction after chmod(0640) on a 0604 file with an ACL, disk retains the new ACL with stale i_mode 0604, and acl_permission_check() skips ACL evaluation when (mode & S_IRWXG) is zero, honoring the stale other-read bit. Updating inode->i_mode and calling ext4_mark_inode_dirty(handle, inode) inside this same handle after __ext4_set_acl() succeeds, as ext4_set_acl() does, would keep both updates atomic on disk. [Severity: Medium] Can ignoring the return value of ext4_journal_stop(handle) silently drop synchronous commit or handle-abort errors? When IS_SYNC(inode) is set, ext4_xattr_set_handle() marks the handle synchronous so ext4_journal_stop() waits for commit and returns any I/O or abort error. Discarding it lets ext4_setattr() proceed with setattr_copy() and return 0 to userspace despite the failed commit. Capturing error2 =3D ext4_journal_stop(handle) and assigning error =3D erro= r2 when !error, as ext4_xattr_set() does, would propagate the failure. [ ... ] > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > index b4d581aa5ee1a..4869ca72d22e2 100644 > --- a/fs/ext4/inode.c > +++ b/fs/ext4/inode.c [ ... ] > @@ -7173,8 +7178,67 @@ 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)) > - rc =3D posix_acl_chmod(idmap, dentry, inode->i_mode); > + if (!error && (ia_valid & ATTR_MODE)) { > + umode_t new_mode =3D attr->ia_mode; > + > + if (!in_group_or_capable(idmap, inode, > + i_gid_into_vfsgid(idmap, inode))) > + new_mode &=3D ~S_ISGID; [Severity: Low] Is this in_group_or_capable() check dead work before ext4_acl_chmod()? ext4_acl_chmod() passes new_mode only to __posix_acl_chmod_masq() (which reads only S_IRWXU, S_IRWXG, and S_IRWXO) and posix_acl_equiv_mode(), ignoring S_ISGID, and setattr_copy() immediately runs the same in_group_or_capable() check again. When inode->i_gid is not in the caller's groups, this triggers a duplicate audited CAP_FSETID LSM check on every chmod(). > + > + /* > + * Update the ACL without touching inode->i_mode. The xattr > + * path can dirty the inode (for example through dquot) while > + * this runs; changing i_mode here would let that write persist > + * a mode whose ACL update later fails. > + */ > + rc =3D ext4_acl_chmod(idmap, dentry, new_mode); [Severity: High] Can moving setattr_copy() after ext4_acl_chmod() persist a new i_uid or i_gid on disk with S_ISUID or S_ISGID still set? Earlier in ext4_setattr(), the ownership transaction writes the new i_uid and i_gid to the journal while inode->i_mode still retains S_ISUID and S_ISGID. Before this patch, setattr_copy() and mark_inode_dirty() cleared those bits immediately; now ext4_acl_chmod() runs first and can force-commit that state via IS_SYNC(inode) or ext4_should_retry_alloc() on -ENOSPC, or abort the journal on an xattr I/O error so the recovery mark_inode_dirty() silently drops the clear in ext4_dirty_inode(). When a privileged chown() changes a user-created 04755 ACL executable to root, a crash or journal abort in this window can leave a setuid-root executable on disk. [ ... ] > + if (restore !=3D old_mode || > + (ia_valid & (ATTR_UID | ATTR_GID))) { > + inode->i_mode =3D restore; [Severity: Low] Should this check whether ownership actually changed instead of testing ia_valid & (ATTR_UID | ATTR_GID)? Callers such as __nfsd_setattr() can pass ATTR_UID or ATTR_GID alongside ATTR_MODE even when the requested uid/gid already matches the inode, so the earlier ownership transaction does not run. If ext4_acl_chmod() then fails on a directory or non-setid file, this still advances ctime, increments i_version, and dirties the inode even though no attribute changed. > + if (ia_valid & ATTR_CTIME_SET) > + inode_set_ctime_to_ts(inode, > + attr->ia_ctime); > + else > + inode_set_ctime_current(inode); [Severity: Medium] Can calling inode_set_ctime_to_ts() for ATTR_CTIME_SET violate ext4's FS_MGTIME contract? Because ext4_fs_type sets FS_MGTIME, concurrent stat() callers run fill_mg_cmtime() locklessly and can race with the plain WRITE_ONCE() stores in inode_set_ctime_to_ts(): CPU0 CPU1 ext4_setattr() inode_set_ctime_to_ts() WRITE_ONCE(i_ctime_sec, ...) fill_mg_cmtime() atomic_fetch_or(I_CTIME_QUERIED, pcn) WRITE_ONCE(i_ctime_nsec, ...) <-- clears I_CTIME_QUERIED It also skips inode_set_ctime_deleg()'s monotonicity and future-clamping checks when an NFSv4 delegated setattr combines ATTR_CTIME_SET with ownership and mode changes. Using inode_set_ctime_deleg() here would match setattr_copy_mgtime(). [ ... ] > + if (!error && !rc) { > + if (inc_ivers) > + inode_inc_iversion(inode); > + setattr_copy(idmap, inode, attr); > + /* > + * ext4_xattr_set_handle() advanced ctime while updating the > + * ACL. Do not let setattr_copy() rewind it to the timestamp > + * snapshotted before the ACL transaction. > + */ > + if ((ia_valid & ATTR_MODE) && !(ia_valid & ATTR_CTIME_SET)) > + inode_set_ctime_current(inode); [Severity: Medium] Can this unconditional inode_set_ctime_current() break i_mtime =3D=3D i_cti= me on FS_MGTIME ext4 mounts and add redundant multigrain timestamp work? Because ext4_fs_type sets FS_MGTIME, setattr_copy() dispatches to setattr_copy_mgtime(), which already calls inode_set_ctime_current() when ATTR_CTIME is set (never rewinding to attr->ia_ctime) and reuses that same timestamp for i_mtime. Calling inode_set_ctime_current() a second time on a combined ATTR_MODE | ATTR_MTIME | ATTR_CTIME operation such as truncate() on a setid file can advance i_ctime past i_mtime if a concurrent stat() sets I_CTIME_QUERIED or the coarse clock ticks between the two calls. Rewind protection is only needed when !is_mgtime(inode) && (ia_valid & ATTR_CTIME) && !(ia_valid & ATTR_CTIME_SET) and an ACL xattr was actually updated. [Severity: Low] Does this also advance i_ctime when ATTR_MODE is passed without ATTR_CTIME? Internal callers such as ovl_set_attr() and __remove_privs() invoke notify_change() with ATTR_MODE and without ATTR_CTIME, where setattr_copy() intentionally leaves i_ctime untouched. This regression updates i_ctime unconditionally even when no POSIX ACL exists. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_DEB80DE9513= 7BB46140E9E6CB67DE0180008@qq.com?part=3D1