]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
squashfs: Fix integer overflow in sqfs_inode_size()
authorRichard Weinberger <richard@nod.at>
Fri, 2 Aug 2024 16:36:45 +0000 (18:36 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 15 Aug 2024 22:14:36 +0000 (16:14 -0600)
A carefully crafted squashfs filesystem can exhibit an extremly large
inode size and overflow the calculation in sqfs_inode_size().
As a consequence, the squashfs driver will read from wrong locations.

Fix by using __builtin_add_overflow() to detect the overflow.

Signed-off-by: Richard Weinberger <richard@nod.at>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
fs/squashfs/sqfs_inode.c

index d25cfb53e75d9c5f7d69bc4fcdf67b3deee35f6e..bb3ccd37e33b34380780798f7f4de535548db680 100644 (file)
@@ -78,11 +78,16 @@ int sqfs_inode_size(struct squashfs_base_inode *inode, u32 blk_size)
 
        case SQFS_SYMLINK_TYPE:
        case SQFS_LSYMLINK_TYPE: {
+               int size;
+
                struct squashfs_symlink_inode *symlink =
                        (struct squashfs_symlink_inode *)inode;
 
-               return sizeof(*symlink) +
-                       get_unaligned_le32(&symlink->symlink_size);
+               if (__builtin_add_overflow(sizeof(*symlink),
+                   get_unaligned_le32(&symlink->symlink_size), &size))
+                       return -EINVAL;
+
+               return size;
        }
 
        case SQFS_BLKDEV_TYPE: