From: sashiko-bot@kernel.org
To: "Artem Blagodarenko" <artem.blagodarenko@gmail.com>,
linux-ext4@vger.kernel.org
Cc: tytso@mit.edu
Subject: Re: [PATCH v15 03/13] ext4: replace ext4_dir_entry with ext4_dir_entry_2
Date: Thu, 03 Dec 2026 19:33:34 +0000 [thread overview]
Message-ID: <sashiko-outbox-248517@kernel.org> (raw)
In-Reply-To: <20261203184938.422849-4-ablagodarenko@thelustrecollective.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ext4: EXT4_BASE_DIR_LEN change exposes OOB read in
is_fake_dir_entry()
- [Low] ext4: commit message omits EXT4_BASE_DIR_LEN change and
misstates rationale
--
commit 905a73de84c1289ce2b9fc43573bee81e7c8e5f8
Author: Artem Blagodarenko <artem.blagodarenko@gmail.com>
> ext4: replace ext4_dir_entry with ext4_dir_entry_2
>
> Replace remaining uses of struct ext4_dir_entry in namei.c
> with struct ext4_dir_entry_2.
>
> The code paths affected by this change already depend on the
> filetype feature, so using struct ext4_dir_entry_2 is
> appropriate and avoids mixing the two directory entry types
> unnecessarily.
>
> This change does not affect support for 16-bit rec_len.
>
> Signed-off-by: Artem Blagodarenko <artem.blagodarenko@gmail.com>
> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
[Severity: Low]
Does this commit message accurately cover the changes and rationale?
The patch also changes EXT4_BASE_DIR_LEN in fs/ext4/ext4.h from 9 to 8,
which alters the loop bound in ext4_search_dir() and is unrelated to
replacing struct ext4_dir_entry. If split out, that change would fix
commit c186f0887fe7 ("ext4: fix use-after-free in ext4_search_dir").
The changelog also omits the count_offset = sizeof(struct dx_node) cleanup
in get_dx_countlimit() and the KUnit updates in fs/ext4/namei.h and
fs/ext4/namei-test.c.
The converted functions in fs/ext4/namei.c run regardless of whether
EXT4_FEATURE_INCOMPAT_FILETYPE is set; the rename is safe because both
structs share the same inode and rec_len layout and none of these paths
access name_len or file_type.
Both structs also have the same __le16 rec_len field, so it is 16-bit
name_len rather than rec_len that differs between them.
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index dc2c181337a16..ca727888425ab 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -2523,10 +2523,8 @@ static inline int ext4_emergency_state(struct super_block *sb)
> * Structure of a directory entry
> */
> #define EXT4_NAME_LEN 255
> -/*
> - * Base length of the ext4 directory entry excluding the name length
> - */
> -#define EXT4_BASE_DIR_LEN (sizeof(struct ext4_dir_entry_2) - EXT4_NAME_LEN)
> +/* offsetof avoids sizeof()+padding giving 9 instead of the correct on-disk 8 */
> +#define EXT4_BASE_DIR_LEN offsetof(struct ext4_dir_entry_2, name)
[Severity: Medium]
Can lowering EXT4_BASE_DIR_LEN from 9 to 8 cause a 1-byte out-of-bounds
read of de->name[1] in is_fake_dir_entry()?
Previously, EXT4_BASE_DIR_LEN was 9 due to trailing struct padding, so
ext4_search_dir() stopped at (char *)de < dlimit - 9 and kept de->name[1]
in bounds. With EXT4_BASE_DIR_LEN now 8, a corrupted directory block with
an unaligned rec_len can place an entry at dlimit - 9 with name_len == 1.
Fast-commit replay (ext4_fc_replay_unlink() -> __ext4_unlink() ->
ext4_find_entry()) can look up a 1-byte "." entry from EXT4_FC_TAG_UNLINK,
pass de->name + de->name_len <= dlimit in ext4_search_dir(), and reach
__ext4_check_dir_entry(), which calls is_fake_dir_entry(de) first:
fs/ext4/dir.c:is_fake_dir_entry() {
if ((de->name_len > 0) && (de->name_len <= 2) && (de->name[0] == '.') &&
(de->name[1] == '.' || de->name[1] == '\0'))
return true;
}
When de sits at dlimit - 9 with name_len == 1 and name[0] == '.',
de->name[1] reads at dlimit, one byte past the directory block buffer,
triggering a KASAN out-of-bounds report or a page fault. Handling
name_len == 1 without reading de->name[1] avoids the out-of-bounds read.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203184938.422849-1-ablagodarenko@thelustrecollective.com?part=3
next prev parent reply other threads:[~2026-12-03 19:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 18:49 [PATCH v15 00/13] Data in direntry (dirdata) feature, with KUnit tests Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 01/13] ext4: validate count against limit in ext4_dx_csum_verify/_set Artem Blagodarenko
2026-12-03 19:03 ` sashiko-bot
2026-12-03 18:49 ` [PATCH v15 02/13] ext4: use the e2fsck limit for htree index nodes Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 03/13] ext4: replace ext4_dir_entry with ext4_dir_entry_2 Artem Blagodarenko
2026-12-03 19:33 ` sashiko-bot [this message]
2026-12-03 18:49 ` [PATCH v15 04/13] ext4: add ext4_dir_entry_is_tail() Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 05/13] ext4: add dirdata format definitions and access helpers Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 06/13] ext4: refactor dx_root to support variable dirent sizes Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 07/13] ext4: size the htree root from where its dx_entry array starts Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 08/13] ext4: rename ext4_dir_rec_len() and clarify dirdata usage Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 09/13] ext4: dirdata feature Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 10/13] ext4: add dirdata LUFID support for directory entry rename Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 11/13] ext4: add dirdata set/get helpers Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 12/13] ext4: Add EXT4_IOC_SET_LUFID ioctl for setting LUFID on directory entries Artem Blagodarenko
2026-12-03 18:49 ` [PATCH v15 13/13] ext4: add KUnit tests for dirdata Artem Blagodarenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-248517@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=artem.blagodarenko@gmail.com \
--cc=linux-ext4@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox