Re: [PATCH] ext4: fix out-of-bounds read in ext4_inlinedir_to_tree()
From: Jiahao Xu
Date: Fri Dec 04 2026 - 01:17:31 EST
Hi Jan,
Thanks for looking at this, and I agree with the direction: the check belongs
in __ext4_check_dir_entry() rather than in each reader, since dx_make_map()
and the others reach that state precisely because the check accepts a fake
entry where the on-disk format does not allow one.
Before reworking it, one thing worth flagging so we do not end up with two
overlapping fixes in flight: Ted's -v2 series already takes that route.
[PATCH -v2 21/32] ext4: don't read dirent hashes from fake directory
entries
<20261119191719.1943298-22-tytso@xxxxxxx>
That patch promotes is_fake_dir_entry() to ext4_is_fake_dir_entry(), adds
ext4_dirent_has_hash(), rejects EXT4_FT_DIR_CSUM entries with a nonzero inode
or name_len in __ext4_check_dir_entry(), and skips the hash reads on fake
entries in dir.c, namei.c (dx_make_map(), htree_dirblock_to_tree(),
ext4_match(), ext4_search_dir()) and inline.c. That is a superset of what my
patch guards, so I will drop the inline.c hunk instead of adding a second
guard for the same read.
What it does not do is validate where a fake entry is allowed to appear, which
is the rest of your comment. I prototyped that on top of the current tree to
see what it would reject, and ran the ext4 KUnit suite against it:
- checksum entry: EXT4_FT_DIR_CSUM has to be the 12-byte tail at the end of a
full block, i.e. size == blocksize, offset == size - sizeof(struct
ext4_dir_entry_tail), rec_len 12, and inode and name_len zero. That covers
both the inline-space case and an entry carrying the tail type anywhere in
the block.
- "." has to be the first entry of the block.
- ".." has to follow it, but this one needs to be conditional: the
unconditional form fails test_namei_dx_map_pack_and_move(), because
dx_move_dirents() does move ".." into a new block at a different offset.
Gating it on the block actually starting with "." keeps the existing suite
(562 tests) green.
With Ted's change the hash reads are skipped for fake entries, so the crafted
image from the report no longer crashes on its own; the position checks above
then reject such metadata instead of merely not touching it.
Do you want that as a separate follow-up on top of Ted's series, or would you
rather have it folded into his "don't read dirent hashes from fake directory
entries"? Until you tell me which shape you prefer I will not post another
version of my patch, so there is no duplicate traffic in the meantime.
Thanks,
Jiahao