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=1796331912; b=qQ8P7D2sv6YrJK2+vy0P4320y1OxIKIV9VTIVs4/A7xfnA2H9D2YBSYHMMtpIuzvB1GT LeqKlxPYu5rTJO8FAWV6NgC81AWulhl2RW74czvunfvd6A0VGcL6J8WW+1ygCIihZxNja Eb4iv+PLbEEHaTpN5XFhnPWNUIUv9qbnXz8ZwdkLLQmvkS43N1tJtIndgOlNAwidTJpiM fZ6pMyRpSD7MArVMSr8m7kE2TRkTlrJLeszVB/vZebaFDejzzPXHBRciUOm4AQ3J59a17 GCxmO3raP9wcmMzJT1fzfFgR7755pirdSpL0XFZjgIHdJM2i3QUR+Hge3OfvWPEwdTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796331912; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Ar65OsVAB6cyCqeTDR5MEgGqCXKRkfgKjnjWQLZn1GA=; b=r03wPZMfGlYDBftx51Qyh05RWMJJGOYy8NUXMRnMcWFKgpJAq6s1plc7ZemxPJzLx/QJ Lu45Zz12eYxIsYzN6GZeisDB+XZPGp7nqk6/JwNC775Jk5pCWuAoa9n76NZFza4JOiMvh rn+81gk4c5Vneuul31dY9fbxkodI4IdJXu8WIYBzROsyt2umeADof3YQkhvpoidHr1YSa F82YthnxKZNcnS6KHvA4DH+abP0TWsFC5LV3j9he/EDPq2B7Mpt84ZGJc6KGHM4WznPkk Osl7IapXpzdsrM47WIRnBzy6vZKRe+y+7EqV10wxBcoHLrlIilageJvXpFL3a7MtkBw== 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=KUzDpeoj; 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 7A95A606A322 for ; Thu, 3 Dec 2026 21:05:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KUzDpeoj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3244A1F000C2; Thu, 3 Dec 2026 21:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796331912; bh=Ar65OsVAB6cyCqeTDR5MEgGqCXKRkfgKjnjWQLZn1GA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=KUzDpeojeY6HlAM0klYjaaOnRAEsCNancCfZJT0UyfUs0pDN1m0FpjU1ORD0FVg9L 4leDvb+pTYnuWBZR0hFQPtA7IWhKr0MknxlrHEUo/18XdeJoBMInANLTJtkIRml10O zILGczakeBzL3jweEorxaYhrzPnc4s7hR3IC3OJxsm4QZ5Ea2h8ylmODkPS/g3norB AXfnQxHwPpaYAwlZUOZYUwxhYQiFF6wZhe5fty1HaT6wR5GRwnihnIGScsF9PDdKaK kir0XhiSS1PU6tMVGxEQiUzwqLzA4/nZuFsXzBo0nvbJDxUsDoMu7tW2uESt5baLv5 ppzMyUUoJ1+YQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v15 08/13] ext4: rename ext4_dir_rec_len() and clarify dirdata usage Reply-To: sashiko-reviews@lists.linux.dev To: "Artem Blagodarenko" , linux-ext4@vger.kernel.org Cc: tytso@mit.edu In-Reply-To: <20261203184938.422849-9-ablagodarenko@thelustrecollective.com> References: <20261203184938.422849-1-ablagodarenko@thelustrecollective.com> <20261203184938.422849-9-ablagodarenko@thelustrecollective.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 21:05:10 +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_dir_entry_len() parses dirdata flags on non-dirdata filesystems - [Medium] ext4: do_split() leaves unzeroed slack parsed as dirdata in add_dirent_to_buf() - [Medium] ext4: dx_get_dx_info() omits 4-byte rec_len alignment check - [Low] ext4: commit message omits API and behavioral changes in rename patch - [Low] ext4: redundant ext4_dir_entry_len() walk in __ext4_check_dir_entry() -- commit 2d5f99bd8296e9ea507c7610391e9c358e49b150 Author: Artem Blagodarenko > ext4: rename ext4_dir_rec_len() and clarify dirdata usage > > Rename ext4_dir_rec_len() to ext4_dirent_rec_len() to better > reflect that it computes the record length for a directory > entry based on the provided name length. > > Update the comment to clarify handling of dirdata-enabled > directories and document the use of ext4_dir_entry_len() > when dirdata is present. > > ext4_dir_entry_len() reads the dirdata of an entry, so the length of > the entry that do_split() hands to add_dirent_to_buf() now depends on > on-disk data. add_dirent_to_buf() checks that this entry has room for > the new one before anything is written, instead of overrunning the > block when the directory is corrupted. > > Signed-off-by: Artem Blagodarenko > Assisted-by: Claude:claude-opus-5-5 [Severity: Low] Should the commit message also describe the API and behavioral changes bundled into this patch? In addition to the rename and the check in add_dirent_to_buf(), the diff widens ext4_dirent_rec_len()'s name_len parameter from __u8 to unsigned int (avoiding 8-bit truncation when name_len + dirdata >=3D 256), adds a dlen parameter to exported ext4_find_dest_de(), and switches __ext4_check_dir_entry(), dx_move_dirents(), dx_pack_dirents(), ext4_find_dest_de(), and ext4_insert_dentry() from ext4_dir_rec_len() to ext4_dir_entry_len(). Also, the new comment in ext4_add_dirent_to_inline() says the dirdata types are defined in the next patch, though commit "ext4: add dirdata format definitions and access helpers" already defined them. > diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c > index 43f4f2d451aa8..06d8d2eb52ea4 100644 > --- a/fs/ext4/dir.c > +++ b/fs/ext4/dir.c > @@ -89,16 +89,15 @@ int __ext4_check_dir_entry(const char *function, unsi= gned int line, > bool fake =3D is_fake_dir_entry(de); > bool has_csum =3D ext4_has_feature_metadata_csum(dir->i_sb); > =20 > - if (unlikely(rlen < ext4_dir_rec_len(1, fake ? NULL : dir))) > + if (unlikely(rlen < ext4_dirent_rec_len(1, fake ? NULL : dir))) > error_msg =3D "rec_len is smaller than minimal"; > else if (unlikely(rlen % 4 !=3D 0)) > error_msg =3D "rec_len % 4 !=3D 0"; > - else if (unlikely(rlen < ext4_dir_rec_len(de->name_len, > - fake ? NULL : dir))) > - error_msg =3D "rec_len is too small for name_len"; > else if (unlikely(next_offset > size)) > error_msg =3D "directory entry overrun"; > - else if (unlikely(next_offset > size - ext4_dir_rec_len(1, > + else if (unlikely(rlen < ext4_dir_entry_len(de, size, fake ? NULL : dir= ))) > + error_msg =3D "rec_len is too small for name_len"; > + else if (unlikely(next_offset > size - ext4_dirent_rec_len(1, > has_csum ? NULL : dir) && > next_offset !=3D size)) > error_msg =3D "directory entry too close to block end"; [Severity: Low] Does calling ext4_dir_entry_len() here validate anything beyond ext4_dirent_rec_len(de->name_len, fake ? NULL : dir)? By this point rlen % 4 =3D=3D 0 and next_offset <=3D size are already verif= ied. Inside ext4_dirent_get_data_len(), any non-zero dirdata length satisfies EXT4_BASE_DIR_LEN + de->name_len + dirdata <=3D rec_len (and out-of-bounds records return 0), so rounding up to 4 bytes can never exceed the already 4-byte-aligned rlen. Keeping ext4_dirent_rec_len() here avoids re-decoding de->rec_len and running the READ_ONCE() dirdata walk on every entry check (which ext4_find_dest_de() then repeats immediately). > diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h > index 32401150503eb..e34d91cd63ece 100644 > --- a/fs/ext4/ext4.h > +++ b/fs/ext4/ext4.h [ ... ] > @@ -4529,8 +4535,8 @@ static inline unsigned int ext4_dir_entry_len(struc= t ext4_dir_entry_2 *de, > 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); > =20 > - return max(ext4_dir_rec_len(de->name_len + dirdata, NULL), > - ext4_dir_rec_len(de->name_len, dir)); > + return max(ext4_dirent_rec_len(de->name_len + dirdata, NULL), > + ext4_dirent_rec_len(de->name_len, dir)); > } [Severity: Medium] Should ext4_dir_entry_len() skip ext4_dirent_get_data_len() when EXT4_FEATURE_INCOMPAT_DIRDATA is not enabled? On a non-dirdata filesystem, an entry with upper file_type bits set and a padding byte after the name larger than its current rec_len gets dirdata =3D=3D 0 from ext4_dirent_get_data_len(), so it passes __ext4_check_dir_entry() and dx_move_dirents() / dx_pack_dirents() copy only its original length. Once do_split() expands the last entry's rec_len to the rest of the half-block, subsequent ext4_dir_entry_len() calls see that byte as in-bounds and jump the entry length, annexing uncopied or stale block bytes into the entry (or failing in add_dirent_to_buf() with -EFSCORRUPTED). Passing the superblock to ext4_dir_entry_len() and gating ext4_dirent_get_data_len() on ext4_has_feature_dirdata(sb) would keep non-dirdata filesystems from interpreting those bits. [Severity: Medium] Can dx_get_dx_info() (added in commit "ext4: refactor dx_root to support variable dirent sizes") return an unaligned pointer into the htree root block? fs/ext4/namei.c:dx_get_dx_info() { ... rlen =3D ext4_rec_len_from_disk(de->rec_len, blocksize); if (rlen < EXT4_BASE_DIR_LEN || rlen + EXT4_BASE_DIR_LEN > blocksize || ext4_dir_entry_len(de, blocksize, NULL) > rlen) return ERR_PTR(-EFSCORRUPTED); off =3D rlen; ... } For blocksize < 65536, ext4_rec_len_from_disk() returns the raw 16-bit value without masking the low two bits, and dx_get_dx_info() does not check rlen % 4 !=3D 0. A '.' entry with an unaligned rec_len (such as 13 with name_len 1) passes ext4_dir_entry_len(de, blocksize, NULL) <=3D rlen, shifting '..', dx_root_info, and the dx_entry array in dx_probe() to unaligned offsets and causing unaligned 16-bit and 32-bit accesses on non-packed structs. > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > index 78ee4936e6cc4..6050dbfd9f786 100644 > --- a/fs/ext4/namei.c > +++ b/fs/ext4/namei.c [ ... ] > @@ -1797,7 +1797,7 @@ static struct ext4_dir_entry_2 *dx_pack_dirents(str= uct inode *dir, char *base, > while ((char*)de < base + blocksize) { > next =3D ext4_next_entry(de, blocksize); > if (de->inode && de->name_len) { > - rec_len =3D ext4_dir_rec_len(de->name_len, dir); > + rec_len =3D ext4_dir_entry_len(de, blocksize, dir); > if (de > to) > memmove(to, de, rec_len); > to->rec_len =3D ext4_rec_len_to_disk(rec_len, blocksize); [ ... ] > @@ -2035,9 +2036,29 @@ static int add_dirent_to_buf(handle_t *handle, str= uct ext4_filename *fname, > =20 > if (!de) { > err =3D ext4_find_dest_de(dir, bh, bh->b_data, > - blocksize - csum_size, fname, &de); > + blocksize - csum_size, fname, &de, 0); > if (err) > return err; > + } else { > + /* > + * do_split() hands over the last entry of a half. Its length > + * comes from on-disk dirdata, so check that the new entry fits > + * before it is written. do_split() has already packed this > + * half and left it to us to dirty, so dirty it on failure too. > + */ > + unsigned int nlen =3D de->inode ? > + ext4_dir_entry_len(de, blocksize, dir) : 0; > + unsigned int rlen =3D ext4_rec_len_from_disk(de->rec_len, > + blocksize); > + > + if (nlen > rlen || > + rlen - nlen < ext4_dirent_rec_len(fname_len(fname), dir)) { > + EXT4_ERROR_INODE(dir, > + "no room for new entry in split block %llu", > + (unsigned long long)bh->b_blocknr); > + ext4_handle_dirty_dirblock(handle, dir, bh); > + return -EFSCORRUPTED; > + } > } > BUFFER_TRACE(bh, "get_write_access"); > err =3D ext4_journal_get_write_access(handle, dir->i_sb, bh, [Severity: Medium] Can add_dirent_to_buf() and ext4_insert_dentry() parse unzeroed stale bytes left after dx_pack_dirents() as dirdata? dx_pack_dirents() compacts entries in the first half without zeroing the trailing slack space, and do_split() then extends the last entry's rec_len to blocksize - csum_size. If that entry has stray upper file_type bits whose dirdata was previously ignored because its offset or length exceeded the old rec_len, re-evaluating ext4_dir_entry_len() over the expanded rec_len reads the unzeroed slack bytes as ddh_length. That either makes add_dirent_to_buf() falsely report EXT4_ERROR_INODE and return -EFSCORRUPTED, or causes ext4_insert_dentry() to split at the bogus nlen and permanently attach stale block bytes to the entry as phantom dirdata. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203184938.4228= 49-1-ablagodarenko@thelustrecollective.com?part=3D8