[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240627085601.24321-1-jan@mwa.re>
Date: Thu, 27 Jun 2024 10:56:01 +0200
From: Jan Henrik Weinstock <jan@....re>
To: tytso@....edu,
adilger.kernel@...ger.ca
Cc: linux-ext4@...r.kernel.org,
linux-kernel@...r.kernel.org,
lukas@....re,
simon@....re,
Jan Henrik Weinstock <jan@....re>
Subject: [PATCH] ext4: fix kernel segfault after iterator overflow
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@....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
Powered by blists - more mailing lists