Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyuwon Cho" <kyuwoncho18@gmail.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH v2] ext4: validate dot entry before reading dotdot in htree readdir
Date: Sat, 05 Dec 2026 08:41:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-251288@kernel.org> (raw)
In-Reply-To: <179637501338.1425433.8835682775805888953@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] ext4: duplicated root hash guard and rec_len read in
  ext4_htree_fill_tree()
--

commit 3e82da14fda178af29c9f8c2f58b8aac85ce06cf
Author: Kyuwon Cho <kyuwoncho18@gmail.com>

ext4: validate dot entry before reading dotdot in htree readdir

This commit validates the record length of the '.' entry in
ext4_htree_fill_tree() against offsetof(struct dx_root, dotdot) before
storing '.' or '..' into the readdir rb-tree.

> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index b2753daad49f4..95dd2d1a76c29 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -1041,9 +1041,19 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
>  	if (IS_ERR(frame))
>  		return PTR_ERR(frame);
>  
> +	if (start_hash < 2 || (start_hash == 2 && start_minor_hash == 0)) {
> +		de = (struct ext4_dir_entry_2 *)frames[0].bh->b_data;
> +		if (unlikely(ext4_rec_len_from_disk(de->rec_len,
> +						    dir->i_sb->s_blocksize) !=
> +			     offsetof(struct dx_root, dotdot))) {
> +			EXT4_ERROR_INODE(dir, "Corrupt dir, invalid rec_len for '.'");
> +			err = -EFSCORRUPTED;
> +			goto errout;
> +		}
> +	}
> +
>  	/* Add '.' and '..' from the htree header */
>  	if (!start_hash && !start_minor_hash) {
> -		de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data;
>  		tmp_str.name = de->name;
>  		tmp_str.len = de->name_len;
>  		err = ext4_htree_store_dirent(dir_file, 0, 0,
> @@ -1053,7 +1063,6 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
>  		count++;
>  	}
>  	if (start_hash < 2 || (start_hash ==2 && start_minor_hash==0)) {
> -		de = (struct ext4_dir_entry_2 *) frames[0].bh->b_data;
>  		de = ext4_next_entry(de, dir->i_sb->s_blocksize);
>  		tmp_str.name = de->name;
>  		tmp_str.len = de->name_len;

[Severity: Low]
Could both the '.' and '..' insertions be enclosed inside the new
start_hash check instead of repeating the condition below?

Right now, de is initialized in the first if block and used across two
separate blocks below, which duplicates the hash guard and can trigger
-Wmaybe-uninitialized warnings depending on the compiler.

Since the check already verifies de->rec_len matches offsetof(struct
dx_root, dotdot), the '..' path also does not need to re-read and decode
de->rec_len via ext4_next_entry().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179637501338.1425433.8835682775805888953@gmail.com?part=1

      reply	other threads:[~2026-12-05  8:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  8:21 [PATCH v2] ext4: validate dot entry before reading dotdot in htree readdir Kyuwon Cho
2026-12-05  8:41 ` sashiko-bot [this message]

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-251288@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kyuwoncho18@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