]> git.openpandora.org Git - pandora-u-boot.git/commitdiff
fs/squashfs: fix heap buffer overflow in sqfs_frag_lookup()
authorEric Kilmer <eric.kilmer@trailofbits.com>
Fri, 20 Feb 2026 19:48:08 +0000 (14:48 -0500)
committerTom Rini <trini@konsulko.com>
Mon, 23 Feb 2026 18:45:50 +0000 (12:45 -0600)
sqfs_frag_lookup() reads a 16-bit metadata block header whose lower
15 bits encode the data size. Unlike sqfs_read_metablock() in
sqfs_inode.c, this function does not validate that the decoded size is
within SQFS_METADATA_BLOCK_SIZE (8192). A malformed SquashFS image can
set the size field to any value up to 32767, causing memcpy to write
past the 8192-byte 'entries' heap buffer.

Add the same bounds check used by sqfs_read_metablock(): reject any
metadata block header with SQFS_METADATA_SIZE(header) exceeding
SQFS_METADATA_BLOCK_SIZE.

Found by fuzzing with libFuzzer + AddressSanitizer.

Signed-off-by: Eric Kilmer <eric.kilmer@trailofbits.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
fs/squashfs/sqfs.c

index f668c26472eb4aaae6a570854e6336009e0860d4..9cb8b4afcddbb8908dc22a1f684244fc1422d7ac 100644 (file)
@@ -178,6 +178,11 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
                goto out;
        }
 
+       if (SQFS_METADATA_SIZE(header) > SQFS_METADATA_BLOCK_SIZE) {
+               ret = -EINVAL;
+               goto out;
+       }
+
        entries = malloc(SQFS_METADATA_BLOCK_SIZE);
        if (!entries) {
                ret = -ENOMEM;