diff options
author | Richard Weinberger <richard@nod.at> | 2024-08-09 11:54:28 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2024-08-15 16:14:36 -0600 |
commit | 35f75d2a46e5859138c83a75cd2f4141c5479ab9 (patch) | |
tree | e05e35550e6340b480d3596d4bcd83c469d6ad46 /fs | |
parent | 048d795bb5b3d9c5701b4855f5e74bcf6849bf5e (diff) | |
download | u-boot-35f75d2a46e5859138c83a75cd2f4141c5479ab9.tar.gz |
ext4: Fix integer overflow in ext4fs_read_symlink()
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ext4/ext4_common.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index 7cf0160c408..76f7102456e 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; |