[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250701141141.55938-1-dmantipov@yandex.ru>
Date: Tue, 1 Jul 2025 17:11:41 +0300
From: Dmitry Antipov <dmantipov@...dex.ru>
To: Theodore Ts'o <tytso@....edu>,
Andreas Dilger <adilger.kernel@...ger.ca>
Cc: linux-ext4@...r.kernel.org,
Dmitry Antipov <dmantipov@...dex.ru>,
syzbot+5322c5c260eb44d209ed@...kaller.appspotmail.com
Subject: [PATCH] ext4: verify dirent offset in ext4_readdir()
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@...kaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5322c5c260eb44d209ed
Signed-off-by: Dmitry Antipov <dmantipov@...dex.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;
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
Powered by blists - more mailing lists