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=1796288630; b=caNM4hE2bFsLqRnyGcjND1BYCm4vcGwE60QBdAqzeHg2H7wauTdnHoHUwY5hIBAyM7+g 5l8zBaRf+uSKsTL8sJwlDhXFAvueV9wv4bnvWtphZbMwaRf7oegbetajDqWOqcN0vptjt 9IlbGmweLsaDYjMPVzEoORRjMFdc04dku0OVaXdkURwIXhssJe3OLCNqXEg1OMb3dAfWB LM8+/W4+BfnpjP9iuXs26eKZtPjsDeVNXQozyY6cToyR0U6ghQwx0ZMoBokOkbUhqn4d+ hvxGUJak+tY4qZ4gVMQJb5B5HvjwECvTFhLRhvaBKh9DdBMA372H09VtKXLTKJbx1+g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288630; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=eWs35aTJI9owbrZS2ZakgSqFox0ojrtctbPybrCSPRg=; b=TabES3WlOIT4IDbiN4sJJZChz/38XByNwkHJ/p/SRcEuUkZ4KVQqQh54Nc+bhlsCA66v 0Z8PRfxZ6ZEKwewHscAsPfWLlE0SX8eyoo6YldWkz92iwKzl7z4ZdnYRYTT99K6xKKNYf DrR9fzfzvMQq8cbBMZnMEI6BS9n/vsaqJsAYEvt1k+VynZy7c+TluZ/ERNbmmqRe1oXjM jwRN9t9/6arX/IlL+BLDXNz0y6SZdZ4M5vONVgwPZio+86gRqObAOcDM2KfTZQrv4y7bO NPa6lss+oGyTWoyXeEVO6jOl/56TOga4KrWNNNX1ly4V9y/9s5jW8o8qt1in8G0Kukg== 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=U4i8i0+j; 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 DE903606A322 for ; Thu, 3 Dec 2026 09:03:50 +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=U4i8i0+j Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E5461F000C1; Thu, 3 Dec 2026 09:03:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796288630; bh=eWs35aTJI9owbrZS2ZakgSqFox0ojrtctbPybrCSPRg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=U4i8i0+jYlJCBGBRSOmJ3Q2l8h21w7udKPYh2/WjjPcsUjHRs1t3NJ7T+U7AGsCzn eAPzWF0YohcFNwbI4F/JWKZa36XtYLlvw+a1yJ20MBkouQ/2ZMHlJpquN9jRM2Y7kH XDcpPqwZ3xMtpuEcQoYTGwtgZMSDbUVTPn7g0BDykepRyBXjq0C3/+XKRRyDIfxGmv +hauoGlbmgeqpH3mGPD+3EEKKGbWTn9lUF4EhWLC3jv5LBAzQVva0youCObtFXKiNM +yz1CEQj5kAD7g8WK8C1BZQ/bvF4nfIZXIlAmInwp4bJCcx+huvScIotjuTPqkbrgX K4NRlQs9eAJXg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3] 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:03:49 +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: - [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, 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; > + > + /* > + * 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 =3D new_mode; > + rc =3D 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 =3D=3D 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 !=3D old_mode, rollback calls void mark_inode_dirt= y(), 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 =3D 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 st= op 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 =3D new_mode posix_acl_chmod() -> error generic_fillattr() stat->mode =3D inode->i_mode inode->i_mode =3D 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 !=3D old_mode) > + mark_inode_dirty(inode); > + } > + } [Severity: Medium] Does skipping mark_inode_dirty() when restore =3D=3D old_mode leave the bum= ped 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 =3D=3D old_mode skips mark_inode_dirty() above and this blo= ck 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/tencent_9DB0E32EA41= 3DD3419E9397CB335F565620A@qq.com?part=3D1