From: Jan Henrik Weinstock <jan@mwa.re>
To: tytso@mit.edu, adilger.kernel@dilger.ca
Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
lukas@mwa.re, simon@mwa.re, Jan Henrik Weinstock <jan@mwa.re>
Subject: [PATCH] ext4: fix kernel segfault after iterator overflow
Date: Thu, 27 Jun 2024 10:56:01 +0200 [thread overview]
Message-ID: <20240627085601.24321-1-jan@mwa.re> (raw)
When search_buf gets placed at the end of the virtual address space
de = (struct ext4_dir_entry_2 *) ((char *) de + de_len);
might overflow to zero and a subsequent loop iteration will crash.
Observed on a simulated riscv32 system using 2GB of memory and a rootfs
on MMC.
Signed-off-by: Jan Henrik Weinstock <jan@mwa.re>
---
fs/ext4/namei.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index a630b27a4..030a11412 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1537,7 +1537,8 @@ int ext4_search_dir(struct buffer_head *bh, char *search_buf, int buf_size,
de = (struct ext4_dir_entry_2 *)search_buf;
dlimit = search_buf + buf_size;
- while ((char *) de < dlimit - EXT4_BASE_DIR_LEN) {
+ while ((char *) de < dlimit - EXT4_BASE_DIR_LEN &&
+ (char *) de >= search_buf) {
/* this code is executed quadratically often */
/* do minimal checking `by hand' */
if (de->name + de->name_len <= dlimit &&
--
2.45.2
next reply other threads:[~2024-06-27 8:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-27 8:56 Jan Henrik Weinstock [this message]
2024-06-27 13:27 ` [PATCH] ext4: fix kernel segfault after iterator overflow 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=20240627085601.24321-1-jan@mwa.re \
--to=jan@mwa.re \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@mwa.re \
--cc=simon@mwa.re \
--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