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=1796339731; b=AFnx5iW5qzH4Wn1mfI3xuJp/LYf0oGEssvnwDEO4OtpFXlpIpu517mwqDxSeZh9nMG2j 0wSw2uw2PqEFD4JgycmzKqkL89E2K/7tHH44a0adC740qwKyHMxKukI64FUHNPd3I+K0d YLOq29jAt6KLxV44E9/4kTf+UZJMxm2RqW8mTgghP//2ZaJ5xks5KXe6ONBSyuOK33rcp w8/cX8QMIb/quMLIM7sHbUW+nAZfRao0A0k17KM/lX2P+UkQ2qFB/4nssETfxipZ9QygN Rs4MFQDUd0uM1XgIjsKnhjwtDDNtcJ8ePo32oz0ZAwWdc/vpXAUsBq+8fYUnTpFLcpg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796339731; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=5U3lDIGjmo8KiZtBatrXPblezk3cCylYc9yizb8tlgY=; b=4i0nCV49SQK5oEqUahcqNqkZDLGwtigrU6Njk+1sxYg3dEhGwF9hmr7RZm20SdkClvYb kprJgkRUgZacE4MmNEDlbqKJL4cQLAi+OV3d9Lo8pzj7tov7wOdThPNu35EAr9izad7Ex +1wLYiTPSWXHIFS0Wq5pr6D4WTByQ7NJBCRZKZbx39+ohOi3nq6A7QMf347/1VuNUeD86 IMrylyVFqbLZqNxsI3R1++zaj6YOh11fcDAuT3xcb92GEgHsvGYQ2Ana7M37kPikHrDDD Dc6OE/sSiWk4lAJdV6AOk8F3AF1AuwL5IVix59IiKWKO3KGJYvEIjVBNnRGu3NvvgQA== 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=YnV6YklZ; 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 1A5DA606A332 for ; Thu, 3 Dec 2026 23:15:30 +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=YnV6YklZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 981261F0092C; Thu, 3 Dec 2026 23:15:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796339730; bh=5U3lDIGjmo8KiZtBatrXPblezk3cCylYc9yizb8tlgY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=YnV6YklZk9JPGbRAQvfeZzzLo+yvoeb8Tbg9Y3F+3WRcy2lEnTLDPYwz518O23D2+ e6ltzM3v8YMm/K0fNMMQZUtihYgIegxU8x+S8gHb2XAKMBoLslHo9kAWqnp4jK4EqV /3sDPmSk0CakdCIdh9ezOmXzGOyRSdQg5X8qi8md+EuKJgbu1q3k61RbqWQbESAGi+ 8XOi0bf4xb3++YhFPbDHrkz8s3BDXsRDtv5jmpKHmdtxeOLJcb1o3XjvyEQ6j36UDm xNAwVobBEgVAbFRTCnM3sWjE1oxCm/HJPU1CdxocmMeJRPoXAhdgE9ZqSg61WteDxD jThKl/d/oz4ag== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v15 13/13] ext4: add KUnit tests for dirdata Reply-To: sashiko-reviews@lists.linux.dev To: "Artem Blagodarenko" , linux-ext4@vger.kernel.org Cc: tytso@mit.edu In-Reply-To: <20261203184938.422849-14-ablagodarenko@thelustrecollective.com> References: <20261203184938.422849-1-ablagodarenko@thelustrecollective.com> <20261203184938.422849-14-ablagodarenko@thelustrecollective.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 23:15:30 +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 7 potential issues to consider: - [Critical] ext4: ext4_dirdata_set_lufid() rollback corrupts htree root or orphans inode - [Medium] ext4: TOCTOU race on dir permission/immutability in ext4_ioctl_set_lufid() - [Medium] ext4: unaligned rec_len accepted in dx_get_dx_info() and get_dx_countlimit() - [Low] ext4: inverted e2fsck vs kernel comment in test_dirdata_dx_node_limit() - [Low] ext4: inaccurate rename-test comment above dirdata_iget_stub() - [Low] ext4: oversized dot entry test misses first guard in dx_get_dx_info() - [Low] ext4: leak of dir_info on assertion failure in test_dirdata_htree_with_lufids() -- commit 09dacab8b09110015062b9b89088f346310d76d3 Author: Artem Blagodarenko ext4: add KUnit tests for dirdata This commit adds the ext4_dirdata_test KUnit suite to fs/ext4/namei-test.c and exports the needed dirdata and htree test helpers from fs/ext4/namei.c. > diff --git a/fs/ext4/namei-test.c b/fs/ext4/namei-test.c > index b45f5ad3b7af6..ba1bb52d24425 100644 > --- a/fs/ext4/namei-test.c > +++ b/fs/ext4/namei-test.c [ ... ] > + /* So is a rec_len of '.' that leaves no room for '..' */ > + dirdata_make_de(b, dir->i_ino, ".", EXT4_FT_DIR, false, 0, false, > + 0, 0, TEST_BLK_SIZE - 8); > + KUNIT_EXPECT_TRUE(test, IS_ERR(dx_get_dx_info_test(dir, b))); [Severity: Low] Does TEST_BLK_SIZE - 8 actually exercise the first-entry overflow guard in dx_get_dx_info()? dx_get_dx_info() checks rlen + EXT4_BASE_DIR_LEN > blocksize, and with EXT4_BASE_DIR_LEN =3D=3D 8 a rec_len of TEST_BLK_SIZE - 8 passes that check. This subcase only returns an error because the trailing 8 bytes of b happen to be zeroed from an earlier call; using TEST_BLK_SIZE - 4 would hit the intended guard directly. [ ... ] > + dir_info =3D kzalloc_obj(*dir_info); > + KUNIT_ASSERT_NOT_NULL(test, dir_info); > + dir_file->private_data =3D dir_info; > + cnt =3D ext4_htree_fill_tree(dir_file, curr_hash, 0, &next_hash); > + KUNIT_ASSERT_GE(test, cnt, 0); > + total +=3D cnt; > + ext4_htree_free_dir_info(dir_info); [Severity: Low] Can this leak dir_info if ext4_htree_fill_tree() fails? KUNIT_ASSERT_GE() aborts the test before ext4_htree_free_dir_info() runs, leaking both dir_info and any struct fname rb-tree nodes inserted before the error. Calling ext4_htree_free_dir_info(dir_info) before the assertion avoids the leak. [ ... ] > +/* The rename tests look the target up through ext4_iget() */ > +static struct inode *dirdata_iget_stub(struct super_block *sb, [Severity: Low] This isn't a bug, but test_dirdata_rename_keeps_lufid() never activates dirdata_iget_stub(); the only caller is test_dirdata_set_lufid(). [ ... ] > +/* > + * Dirdata 9: an htree index node of a casefolded and encrypted directory > + * may have the limit that the kernel computes or the one that e2fsck > + * computes, which reserves room for the hash in the fake dirent. > + */ [Severity: Low] Is this comment inverted relative to fs/ext4/namei.h? dx_node_limit() and dx_node_limit_ok() document that e2fsck (and the current kernel) do not reserve room for the hash in the fake dirent, while older kernels did. > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > index f9250407cedbc..b8a5bd8036036 100644 > --- a/fs/ext4/namei.c > +++ b/fs/ext4/namei.c [ ... ] > @@ -4991,6 +4993,7 @@ int ext4_dirdata_set_lufid(const struct mnt_idmap *= idmap, struct inode *dir, > =20 > return err; > } > +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_dirdata_set_lufid); [Severity: Critical] Can the error rollback in ext4_dirdata_set_lufid() (introduced in commit "ext4: Add EXT4_IOC_SET_LUFID ioctl for setting LUFID on directory entries") corrupt an htree root block or orphan the target inode? On a one-block linear directory, ext4_dirdata_set_lufid() deletes the entry from block 0 (bh) and calls ext4_add_fname(). If the larger LUFID entry does not fit, make_indexed_dir() sets EXT4_INODE_INDEX, moves existing entries to block 1, and rewrites bh into an htree root block before calling do_split(). If do_split() then fails on ext4_append() with -ENOSPC or -EDQUOT, make_indexed_dir() leaves dir indexed and bh formatted as an htree root. Rollback then calls add_dirent_to_buf(handle, &old_fname, dir, inode, NULL, bh) on that same bh. Without metadata_csum, ext4_find_dest_de() treats the block-spanning '..' rec_len as free space and overwrites dx_root_info and dx_entry[] with old_fname, silently corrupting the htree root on disk. With metadata_csum, ext4_check_dir_entry() rejects the full-block '..' entry with -EFSCORRUPTED, triggering EXT4_ERROR_INODE() and leaving inode orphaned. In an already-indexed directory, if ext4_dx_add_entry() splits the leaf block before failing, writing old_fname back into the stale bh can also place the entry in the wrong htree hash leaf. [Severity: Medium] Can a racing EXT4_IOC_SET_LUFID ioctl bypass a concurrent chmod or chattr +i on the parent directory? ext4_ioctl_set_lufid() (from commit "ext4: Add EXT4_IOC_SET_LUFID ioctl for setting LUFID on directory entries") calls inode_permission(idmap, dir, MAY_WRITE | MAY_EXEC) without holding dir->i_rwsem, and then sleeps in copy_from_user(), mnt_want_write_file(), and dquot_initialize() before ext4_dirdata_set_lufid() takes inode_lock_nested(dir, I_MUTEX_PARENT). CPU0 CPU1 ext4_ioctl_set_lufid() inode_permission(MAY_WRITE...) copy_from_user() (sleeps) vfs_fileattr_set() (chattr +i) inode_lock(dir) dir->i_flags |=3D S_IMMUTABLE inode_unlock(dir) ext4_dirdata_set_lufid() inode_lock_nested(dir, ...) ... (no MAY_WRITE/IMMUTABLE re-check) ext4_delete_entry() <-- mutates immutable dir Under dir->i_rwsem, ext4_dirdata_set_lufid() checks IS_APPEND(dir) but relies on the earlier unlocked inode_permission() call for MAY_WRITE, MAY_EXEC, and IS_IMMUTABLE(dir). Re-checking inode_permission(idmap, dir, MAY_WRITE | MAY_EXEC) after acquiring inode_lock_nested(dir, I_MUTEX_PARENT) would close this window. [ ... ] > @@ -5132,6 +5135,12 @@ bool ext4_check_dx_root_test(struct inode *dir, st= ruct dx_root *root) > } > EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_check_dx_root_test); > =20 > +struct dx_root_info *dx_get_dx_info_test(struct inode *dir, void *de_buf) > +{ > + return dx_get_dx_info(dir, de_buf); > +} > +EXPORT_SYMBOL_FOR_EXT4_TEST(dx_get_dx_info_test); [Severity: Medium] Can dx_get_dx_info() and get_dx_countlimit() (updated in commit "ext4: refactor dx_root to support variable dirent sizes") return unaligned htree pointers on a corrupted root block? On filesystems with blocksize < 65536, ext4_rec_len_from_disk() returns the raw 16-bit rec_len without enforcing 4-byte alignment, and neither dx_get_dx_info() nor get_dx_countlimit() checks (rlen & 3) !=3D 0 on '.' (or on '..' in dx_get_dx_info()). A crafted '.' rec_len such as 13 passes the bounds checks and places the '..' entry, dx_root_info, dx_countlimit, dx_entry[], and dx_tail at unaligned offsets even though none of those structs are __packed, triggering UBSAN alignment faults or traps on strict-alignment architectures. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203184938.4228= 49-1-ablagodarenko@thelustrecollective.com?part=3D13