squashfs: Fix integer overflow in sqfs_inode_size()
authorRichard Weinberger <richard@nod.at>
Fri, 2 Aug 2024 16:36:45 +0000 (18:36 +0200)
committerDaniel Leidert <dleidert@debian.org>
Wed, 30 Apr 2025 23:19:02 +0000 (01:19 +0200)
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>
Reviewed-By: Daniel Leidert <dleidert@debian.org>
Origin: https://source.denx.de/u-boot/u-boot/-/commit/c8e929e5758999933f9e905049ef2bf3fe6b140d
Bug: https://www.openwall.com/lists/oss-security/2025/02/17/2
Bug-Debian: https://bugs.debian.org/1098254
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2024-57254
Bug-Freexian-Security: https://deb.freexian.com/extended-lts/tracker/CVE-2024-57254

Gbp-Pq: Name CVE-2024-57254.patch

fs/squashfs/sqfs_inode.c

index e76ec7cbdfd97d4b9c155a3666ad4d28273417c3..540f7d039a9c0ee0a14a67f0d965f6bfffe0648a 100644 (file)
@@ -77,11 +77,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: