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=1796333858; b=Fr/0xjzoJ48aGXUMyScYr13BpBI3Pr/Lqk6DPLQ2TDerEExY0qDPDUFfoSqLZDlZeYDS R+/n7xuNlngaW1eKEM+imM/Ftkaaqh/A0YCV8zOOOIGelx5WReLJRmoaqptNnUzE8yL/I 5kC9ZVyyXH/A1dfOavjgQliQpz361ea7YgaTHs08ba8xkV6SilMvC3AbweKMDrR+2qvbB 3TOKSI5xIxeLENhncBbpN5WVSFc7odMD8hoT/YUCka9C4jvDhgZA5/Y1JQvgVSyls/hWw CpcfXISDcouwK9pPFEYc3FeuK7eqPTRSLRtn1xKy5BMPhYrPNi34Kd8OkX7i/ZNAmIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796333858; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=K5Q3mYOYl4VjN/YGdUJZd0MIFq4aoQd7+dmz1GPAYBU=; b=cyZRT/SwkgB8MTBrhfwkxyVySVgL4tu7x1gcFpYBC3FY2nQqZfevEmP2Tter8wq6ZubC mEtJY7q1k2y1AEL47TUUXV5pQ+Ul99O6xy+yuFJvi9acQRR2diCgQViEqQOBkElInzx50 /glvNRxAhA1rx+JR5JECdsQmGnFj9HTG2YCr0buGBCEUOQ9WBW5/7J02jEXxOLn5s/R8q 247I/ubwMDtDbItWj+CnxJIn9ZAyaMd9HecGl1LSRFiBU08c/NWkbkpabF7jYgEVPRF8L mrGiQ6ge3a+X4SdaopOLtEJa686Hg+rWg/fXc49SvxL4BiZyEjKt/MiSBWZtAuJRENQ== 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=UjT0Czwn; 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 94E8A606A322 for ; Thu, 3 Dec 2026 21:37:38 +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=UjT0Czwn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 465401F000C2; Thu, 3 Dec 2026 21:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796333858; bh=K5Q3mYOYl4VjN/YGdUJZd0MIFq4aoQd7+dmz1GPAYBU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=UjT0CzwnTCLvqT5Gw9U4J7oBZPA1cemMV1CpURnZ0ULxA+GC1wDbplg/11V9hd7tS VlOvSKaTW8/24JJnO2FjWoS08nmuJ3D0kJqmNibc0EIFhv3660uO4ZubeRzgPAw0D/ LAbX+ZmnbVf50bty4NcvbasUda90lx5+ovxukK/YhsqScGaiVL8IkZ1NNm+U9mpRz+ j9rO1STVVRZY59UnNl6xicyDJdPu7u8ZaAnNunLmMkRmfSRDo1NWaKIyV3YJlwuXtE ld/bwNqtJ8+OPD3m0W0xrD32fQenV2a2ERCG0ZZLrZwNyXVsQrOXYP1lQkPn+8fVzX IXAvEz1ZXJgkA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v15 09/13] ext4: dirdata feature Reply-To: sashiko-reviews@lists.linux.dev To: "Artem Blagodarenko" , linux-ext4@vger.kernel.org Cc: tytso@mit.edu In-Reply-To: <20261203184938.422849-10-ablagodarenko@thelustrecollective.com> References: <20261203184938.422849-1-ablagodarenko@thelustrecollective.com> <20261203184938.422849-10-ablagodarenko@thelustrecollective.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 21:37:37 +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 8 potential issues to consider: - [Medium] ext4: ext4_dir_entry_len() parses dirdata flags without INCOMPAT_DIRDATA - [Medium] ext4: allow mounting INCOMPAT_DIRDATA without INCOMPAT_FILETYPE - [Medium] ext4: missing rlen alignment and dirdata checks in get_dx_countlimit() - [Medium] ext4: ext4_feature_set_ok() allows dirdata without filetype feature - [Medium] ext4: enable EXT4_FEATURE_INCOMPAT_DIRDATA before dirdata handlers exist - [Low] ext4: misplaced bounds check and unchecked rec_len in dx_show_leaf() - [Low] ext4: unused data1/data2 parameters in ext4_init_new_dir_data() - [Low] ext4: commit message omits feature enablement, LUFID, and API changes -- commit 9524cb5f9f3b3666d39ad56c5cf72650999c906d Author: Artem Blagodarenko > ext4: dirdata feature > > When fscrypt and casefold are enabled together for a directory, > all ext4_dir_entry[_2] in that directory store a n 8-byte hash > of the filename after 'name' between 'name_len' and 'rec_len'. > > However, there is no clear indication there is important data > stored in these bytes, which are only for padding and alignment > in other directory entries. This adds complexity to code handling > the on-disk directory entries, and there is no provision for other > metadata to be stored in each dir entry after 'name'. > > The dirdata feature adds a mechanism to store multiple metadata > entries in each dir entry after 'name' (including the fchash). > The unused high 4 bits of 'file_type' are used to indicate whether > additional data fields are stored after 'name'. If a bit is set, > the corresponding dirdata record is present, starting after a NUL > filename terminator. If present, a record starts with a 1-byte > length (including the length byte itself) and the data immediately > follows the length byte without any alignment. > > This allows up to four different dirdata records to be stored in > each entry, and allows unhandled record bytes to be skipped without > having to process the contents, providing forward compatibility. > > If and when the fourth and last dirdata record is needed, it is > recommended to further subdivide it into sub-records, with > the first byte being the total length, and then there being a > second byte that gives the sub-record length, etc. as long as > the total record length is less than 255 bytes. However, this > would not affect compatibility with the current code since the > record length would allow it to be skipped without processing. > > Signed-off-by: Pravin Shelar > Signed-off-by: Artem Blagodarenko > Assisted-by: Claude:claude-opus-5-5 [Severity: Low] This isn't a bug, but the commit message only describes the generic on-disk dirdata format and fchash motivation, which were already introduced in commit "ext4: add dirdata format definitions and access helpers". It omits the actual changes made here: enabling EXT4_FEATURE_INCOMPAT_DIRDATA in EXT4_FEATURE_INCOMPAT_SUPP and sysfs, adding ext4_dirent_data_corrupt() and variable-size dot/dotdot handling in htree helpers, interpreting dentry->d_fsdata as struct ext4_dentry_param via ext4_dentry_get_fid(), marking fast-commit ineligible via EXT4_FC_REASON_DIRDATA, and introducing ext4_insert_dentry_data() and ext4_init_new_dir_data(). [ ... ] > diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h > index e34d91cd63ece..98014749e5d43 100644 > --- a/fs/ext4/ext4.h > +++ b/fs/ext4/ext4.h > @@ -2385,6 +2385,7 @@ EXT4_FEATURE_INCOMPAT_FUNCS(casefold, CASEFOLD) > EXT4_FEATURE_INCOMPAT_FLEX_BG| \ > EXT4_FEATURE_INCOMPAT_EA_INODE| \ > EXT4_FEATURE_INCOMPAT_MMP | \ > + EXT4_FEATURE_INCOMPAT_DIRDATA | \ > EXT4_FEATURE_INCOMPAT_INLINE_DATA | \ > EXT4_FEATURE_INCOMPAT_ENCRYPT | \ > EXT4_FEATURE_INCOMPAT_CASEFOLD | \ [Severity: Medium] Does adding EXT4_FEATURE_INCOMPAT_DIRDATA here allow mounting a dirdata filesystem without EXT4_FEATURE_INCOMPAT_FILETYPE? Dirdata stores its presence flags in the upper 4 bits of de->file_type, which is the high byte of a 16-bit name_len when FILETYPE is disabled, yet ext4_feature_set_ok() does not reject that combination. As a result, ext4_dirdata_set() (added later in the series) unconditionally sets dirdata bits in de->file_type while ext4_setent() gates file_type and LUFID updates on ext4_has_feature_filetype(), skipping LUFID updates on overwriting renames and leaving the overwritten inode's LUFID attached to the renamed entry. [Severity: Medium] Can mounting EXT4_FEATURE_INCOMPAT_DIRDATA without EXT4_FEATURE_INCOMPAT_FILETYPE also cause newly allocated directory blocks to fail validation as corrupted? Because ext4_feature_set_ok() permits this combination and ext4_set_de_type() is a no-op without FILETYPE, ext4_init_dirblock() leaves stale bytes in de->file_type for '.' and '..' when ext4_append() reuses an already-uptodate buffer. ext4_dirent_data_corrupt() then interprets non-zero upper bits in those stale bytes as dirdata flags and reports corruption. Rejecting dirdata without filetype in ext4_feature_set_ok() would prevent both issues. [ ... ] > @@ -4509,6 +4538,28 @@ static inline int ext4_dirent_get_data_len(struct = ext4_dir_entry_2 *de, > return dlen; > } > =20 > +/* > + * ext4_dirent_data_corrupt() - check the dirdata records of an entry > + * @sb: super block > + * @de: directory entry > + * @rec_len: the record length of the directory entry (decoded) > + * > + * On a dirdata filesystem every record flagged in the high bits of > + * de->file_type must fit inside the entry. ext4_dirent_get_data_len() > + * returns 0 when one does not, which would make the length of the entry > + * depend on its current rec_len; callers treat that as corruption > + * instead. Without the feature the flags are not interpreted. > + */ > +static inline bool ext4_dirent_data_corrupt(struct super_block *sb, > + struct ext4_dir_entry_2 *de, > + unsigned int rec_len) > +{ > + if (!ext4_has_feature_dirdata(sb) || ext4_dir_entry_is_tail(de) || > + !(de->file_type & ~EXT4_FT_MASK)) > + return false; > + return ext4_dirent_get_data_len(de, rec_len) =3D=3D 0; > +} [Severity: Medium] Does ext4_dir_entry_len() still interpret dirdata flags when EXT4_FEATURE_INCOMPAT_DIRDATA is disabled, contradicting ext4_dirent_data_corrupt()? fs/ext4/ext4.h:ext4_dir_entry_len() { unsigned int rec_len =3D ext4_rec_len_from_disk(de->rec_len, blocksize); unsigned int dirdata =3D ext4_dirent_get_data_len(de, rec_len); return max(ext4_dirent_rec_len(de->name_len + dirdata, NULL), ext4_dirent_rec_len(de->name_len, dir)); } On a non-dirdata filesystem, if a 1-block directory has a '..' entry with rec_len =3D=3D 12, a non-zero upper nibble in file_type, and a non-zero pad= ding byte (for example 4), make_indexed_dir() passes validation because ext4_dirent_get_data_len(dotdot_de, 12) returns 0, writes dx_root_info at offset 24, and expands dotdot_de->rec_len to blocksize - 12. Subsequent calls to get_dx_countlimit() and dx_get_dx_info() then see the expanded rec_len, compute a larger dotdot_rec_len (16), and read dx_root_info at offset 28 instead of 24, failing checksum generation and breaking the directory with ERR_BAD_DX_DIR. Gating ext4_dirent_get_data_len() in ext4_dir_entry_len() on ext4_has_feature_dirdata() would avoid this. [ ... ] > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > index 6050dbfd9f786..12ffd34cf46d0 100644 > --- a/fs/ext4/namei.c > +++ b/fs/ext4/namei.c > @@ -329,23 +329,33 @@ static struct dx_countlimit *get_dx_countlimit(stru= ct inode *inode, > { > struct ext4_dir_entry_2 *de; > struct dx_root_info *root; > - int count_offset; > + int count_offset, dotdot_rec_len; > int blocksize =3D EXT4_BLOCK_SIZE(inode->i_sb); > unsigned int rlen =3D ext4_rec_len_from_disk(dirent->rec_len, blocksize= ); > =20 > - if (rlen =3D=3D blocksize) > + if (rlen =3D=3D blocksize) { > count_offset =3D sizeof(struct dx_node); > - else if (rlen =3D=3D 12) { > - de =3D (struct ext4_dir_entry_2 *)(((void *)dirent) + 12); > - if (ext4_rec_len_from_disk(de->rec_len, blocksize) !=3D blocksize - 12) > + } else { > + if (rlen < EXT4_BASE_DIR_LEN || > + rlen + EXT4_BASE_DIR_LEN > blocksize) > + return NULL; > + de =3D (struct ext4_dir_entry_2 *)(((char *)dirent) + rlen); > + if (ext4_rec_len_from_disk(de->rec_len, blocksize) !=3D > + (unsigned int)(blocksize - rlen)) > + return NULL; > + /* de->rec_len covers whole dx_root block, calculate actual length. > + * This is the '..' entry, which never carries the casefold+fscrypt > + * hash, so pass NULL for dir regardless of the directory's flags */ > + dotdot_rec_len =3D ext4_dir_entry_len(de, blocksize, NULL); > + if (rlen + dotdot_rec_len + sizeof(struct dx_root_info) + > + sizeof(struct dx_countlimit) > blocksize) > return NULL; > - root =3D (struct dx_root_info *)(((void *)de + 12)); > + root =3D (struct dx_root_info *)(((char *)de + dotdot_rec_len)); > if (root->reserved_zero || > root->info_length !=3D sizeof(struct dx_root_info)) > return NULL; > - count_offset =3D 32; > - } else > - return NULL; > + count_offset =3D root->info_length + rlen + dotdot_rec_len; > + } > =20 > if (offset) > *offset =3D count_offset; [Severity: Medium] Can an unaligned dot rec_len in get_dx_countlimit() cause unaligned accesses to dx_root_info, dx_countlimit, dx_entry, and dx_tail? Previously get_dx_countlimit() only accepted rlen =3D=3D blocksize or rlen =3D=3D 12, guaranteeing 4-byte alignment. Now a corrupted root block = with an unaligned rlen (such as 9) passes and produces unaligned pointers (and dx_get_dx_info() is missing the same (rlen & EXT4_DIR_ROUND) check). Unlike dx_get_dx_info(), get_dx_countlimit() also omits ext4_dirent_data_corrupt() on '.' and '..' and the ext4_dir_entry_len(dirent, blocksize, NULL) > rlen check, so corrupt dirdata causes ext4_dirent_get_data_len() to return 0 and silently compute the wrong count_offset instead of returning NULL. [ ... ] > @@ -586,7 +598,9 @@ static struct stats dx_show_leaf(struct inode *dir, > (unsigned) ((char *) de - base)); > #endif > } > - space +=3D ext4_dirent_rec_len(de->name_len, dir); > + if ((char *)de + EXT4_BASE_DIR_LEN > base + size) > + break; > + space +=3D ext4_dir_entry_len(de, size, dir); > names++; > } > de =3D ext4_next_entry(de, size); [Severity: Low] Is this bounds check in dx_show_leaf() too late and incomplete for a corrupted leaf block? In DX_DEBUG builds, the loop already dereferences de->inode (and, when show_names is set, de->name_len, de->name, and EXT4_DIRENT_HASH(de)) before reaching this check. When de->inode =3D=3D 0, the check is bypassed before ext4_next_entry(de, size) reads de->rec_len, and ext4_dir_entry_len() is also called without verifying (char *)de + rec_len <=3D base + size, allowi= ng an out-of-bounds read past the leaf buffer. [ ... ] > @@ -2930,8 +2961,9 @@ int ext4_init_dirblock(handle_t *handle, struct ino= de *inode, > } > EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_init_dirblock); > =20 > -int ext4_init_new_dir(handle_t *handle, struct inode *dir, > - struct inode *inode) > +int ext4_init_new_dir_data(handle_t *handle, struct inode *dir, > + struct inode *inode, > + const void *data1, const void *data2) > { > struct buffer_head *dir_block =3D NULL; > ext4_lblk_t block =3D 0; [Severity: Low] Are data1 and data2 in ext4_init_new_dir_data() unused? Neither parameter is referenced in the function body, and even at the end of the series the function still ignores them with no direct in-tree callers (only the ext4_init_new_dir() wrapper passing NULL, NULL); similarly, __ext4_link() forwards dentry->d_fsdata even though no in-tree link caller sets it. [ ... ] > diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c > index faa76f0210991..a433418a8182b 100644 > --- a/fs/ext4/sysfs.c > +++ b/fs/ext4/sysfs.c > @@ -362,6 +362,7 @@ EXT4_ATTR_FEATURE(verity); > #endif > EXT4_ATTR_FEATURE(metadata_csum_seed); > EXT4_ATTR_FEATURE(fast_commit); > +EXT4_ATTR_FEATURE(dirdata); > #if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_FS_ENCRYPTION) > EXT4_ATTR_FEATURE(encrypted_casefold); > #endif [Severity: Medium] Does advertising dirdata in sysfs and adding EXT4_FEATURE_INCOMPAT_DIRDATA to EXT4_FEATURE_INCOMPAT_SUPP in this commit allow read-write mounts of dirdata filesystems before the dirdata read, write, and rename handlers exist? At this commit, ext4_insert_dentry_data() ignores its data parameter and writes casefold+fscrypt hashes at the legacy fixed offset, hash readers such as ext4_match() and ext4_readdir() still read the legacy offset, and ext4_setent() copies de->file_type verbatim on rename without adjusting dirdata payloads, corrupting entries on disk because __ext4_check_dir_entry() already enforces ext4_dirent_data_corrupt(). These handlers are added later by commit "ext4: add dirdata LUFID support for directory entry rename" and commit "ext4: add dirdata set/get helpers", so deferring EXT4_FEATURE_INCOMPAT_SUPP and sysfs enablement until after those patches would keep the series bisectable. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203184938.4228= 49-1-ablagodarenko@thelustrecollective.com?part=3D9