Skip to content

Commit 35f75d2

Browse files
richardweinbergertrini
authored andcommitted
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>
1 parent 048d795 commit 35f75d2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fs/ext4/ext4_common.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,13 +2181,18 @@ static char *ext4fs_read_symlink(struct ext2fs_node *node)
21812181
struct ext2fs_node *diro = node;
21822182
int status;
21832183
loff_t actread;
2184+
size_t alloc_size;
21842185

21852186
if (!diro->inode_read) {
21862187
status = ext4fs_read_inode(diro->data, diro->ino, &diro->inode);
21872188
if (status == 0)
21882189
return NULL;
21892190
}
2190-
symlink = zalloc(le32_to_cpu(diro->inode.size) + 1);
2191+
2192+
if (__builtin_add_overflow(le32_to_cpu(diro->inode.size), 1, &alloc_size))
2193+
return NULL;
2194+
2195+
symlink = zalloc(alloc_size);
21912196
if (!symlink)
21922197
return NULL;
21932198

0 commit comments

Comments
 (0)