All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] ext4: Fix integer overflow in ext4fs_read_symlink()
@ 2024-08-09  9:54 Richard Weinberger
  2024-08-09  9:54 ` [PATCH v2 2/3] compiler: Ensure __builtin_*_overflow() support Richard Weinberger
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Richard Weinberger @ 2024-08-09  9:54 UTC (permalink / raw)
  To: u-boot
  Cc: sjg, Jixiong.Hu, marek.vasut+renesas, patrick.delaunay,
	ilias.apalodimas, xypron.glpk, seanga2, trini, upstream+uboot,
	Richard Weinberger

While zalloc() takes a size_t type, adding 1 to the le32 variable
will overflow.
A carefully crafted ext4 filesystem can exhibit an inode size of 0xffffffff
and as consequence zalloc() will do a zero allocation.

Later in the function the inode size is again used for copying data.
So an attacker can overwrite memory.

Avoid the overflow by using the __builtin_add_overflow() helper.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 fs/ext4/ext4_common.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index 52152a2295..36999b608f 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -2181,13 +2181,18 @@ static char *ext4fs_read_symlink(struct ext2fs_node *node)
 	struct ext2fs_node *diro = node;
 	int status;
 	loff_t actread;
+	size_t alloc_size;
 
 	if (!diro->inode_read) {
 		status = ext4fs_read_inode(diro->data, diro->ino, &diro->inode);
 		if (status == 0)
 			return NULL;
 	}
-	symlink = zalloc(le32_to_cpu(diro->inode.size) + 1);
+
+	if (__builtin_add_overflow(le32_to_cpu(diro->inode.size), 1, &alloc_size))
+		return NULL;
+
+	symlink = zalloc(alloc_size);
 	if (!symlink)
 		return NULL;
 
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-08-26 10:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-09  9:54 [PATCH v2 1/3] ext4: Fix integer overflow in ext4fs_read_symlink() Richard Weinberger
2024-08-09  9:54 ` [PATCH v2 2/3] compiler: Ensure __builtin_*_overflow() support Richard Weinberger
2024-08-09  9:54 ` [PATCH v2 3/3] ext4: Fix zalloc() Richard Weinberger
2024-08-09 10:45   ` Heinrich Schuchardt
2024-08-26 10:28   ` Ilias Apalodimas
2024-08-09 16:13 ` [PATCH v2 1/3] ext4: Fix integer overflow in ext4fs_read_symlink() Heinrich Schuchardt
2024-08-09 16:29   ` Richard Weinberger
2024-08-09 22:02     ` Tom Rini
2024-08-16  3:47 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.