From: "Darrick J. Wong" <djwong@kernel.org>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Theodore Ts'o <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>,
linux-ext4@vger.kernel.org,
syzbot+5322c5c260eb44d209ed@syzkaller.appspotmail.com
Subject: Re: [PATCH] ext4: verify dirent offset in ext4_readdir()
Date: Wed, 2 Jul 2025 08:23:04 -0700 [thread overview]
Message-ID: <20250702152304.GM9987@frogsfrogsfrogs> (raw)
In-Reply-To: <20250701141141.55938-1-dmantipov@yandex.ru>
On Tue, Jul 01, 2025 at 05:11:41PM +0300, Dmitry Antipov wrote:
> On a corrupted filesystem, an unexpectedly large invalid value
> returned by 'ext4_rec_len_from_disk()' may cause 'ext4_readdir()'
> to read the next dirent from an area beyond the corresponding
> buffer head's data. At this point, an exact length of the dirent
> is not known yet but it's possible to check whether the shortest
> possible dirent will be read from within the bh's data at least.
>
> Reported-by: syzbot+5322c5c260eb44d209ed@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=5322c5c260eb44d209ed
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
> ---
> fs/ext4/dir.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
> index d4164c507a90..8097016f69aa 100644
> --- a/fs/ext4/dir.c
> +++ b/fs/ext4/dir.c
> @@ -258,6 +258,12 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
>
> while (ctx->pos < inode->i_size
> && offset < sb->s_blocksize) {
> + /* Ensure that at least the shortest possible
> + * dirent will be read from within the bh's data.
> + */
> + if (offset + offsetof(struct ext4_dir_entry_2, name)
> + > bh->b_size)
> + break;
Why wouldn't you encode this check in __ext4_check_dir_entry and solve
this problem for all the callsites?
--D
> de = (struct ext4_dir_entry_2 *) (bh->b_data + offset);
> if (ext4_check_dir_entry(inode, file, de, bh,
> bh->b_data, bh->b_size,
> --
> 2.50.0
>
>
next prev parent reply other threads:[~2025-07-02 15:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 14:11 [PATCH] ext4: verify dirent offset in ext4_readdir() Dmitry Antipov
2025-07-02 15:23 ` Darrick J. Wong [this message]
2025-07-03 9:54 ` Dmitry Antipov
2025-07-14 3:38 ` Theodore Ts'o
2025-07-14 3:32 ` Theodore Ts'o
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=20250702152304.GM9987@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=adilger.kernel@dilger.ca \
--cc=dmantipov@yandex.ru \
--cc=linux-ext4@vger.kernel.org \
--cc=syzbot+5322c5c260eb44d209ed@syzkaller.appspotmail.com \
--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