udf_load_logicalvol() checks the aggregate partition map table length, but uses each entry's unvalidated partitionMapLength to walk the table. A truncated type-2 map near the end of a Logical Volume Descriptor can contain the sparable partition identifier while its packetLength field lies past the descriptor buffer. This causes a two-byte out-of-bounds read in udf_load_sparable_map(), reported by KASAN in udf_process_sequence(). Check that each map header fits in the remaining table and that its declared length fits in the table and covers the fields for its type. The 64-byte generic type-2 size covers the virtual, sparable, and metadata partition map layouts. Report and reject truncated headers and invalid map lengths before accessing type-specific fields. The unchecked walk is present in the initial imported tree. A custom LLM agent assisted with discovery and reproducer setup. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Co-developed-by: Gwanhyun Lee Signed-off-by: Gwanhyun Lee Signed-off-by: Junyoung Jang --- The malformed image uses a 4096-byte Logical Volume Descriptor with a 3656-byte partition map table and 16 maps. The last map begins at table offset 3626 and declares a 30-byte type-2 sparable map. Its packetLength field lies at descriptor byte 4106, past the end of the 4096-byte buffer. A second image declares a 3627-byte table, leaving only one byte of the last map header inside the table. On unmodified mainline 4dce97c6c265 with UDF and KASAN enabled, the first image produced: BUG: KASAN: use-after-free in udf_process_sequence+0x3cfe/0x3f60 Read of size 2 at addr ffff88807ffc000a by task busybox/57 Call Trace: udf_process_sequence+0x3cfe/0x3f60 udf_check_anchor_block+0x270/0x460 udf_load_vrs+0x67b/0xde0 udf_fill_super+0x778/0x19d0 The read crossed the descriptor boundary into an adjacent freed page; that is why KASAN classified it as use-after-free. The mount failed with EIO after the invalid packetLength was read. On patched mainline, three boots rejected map length 30 at offset 3626 before that read; three boots of the second image rejected the truncated header at the same offset. Neither patched case produced a KASAN report. Valid UDF and sparable UDF images mounted before and after the patch. fs/udf/super.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fs/udf/super.c b/fs/udf/super.c index a81a8509524a..41988a07b86b 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -1580,9 +1580,29 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block, i < sbi->s_partitions && offset < table_len; i++, offset += gpm->partitionMapLength) { struct udf_part_map *map = &sbi->s_partmaps[i]; + unsigned int min_len; + + if (table_len - offset < sizeof(*gpm)) { + udf_err(sb, "Truncated partition map header at offset %d\n", + offset); + ret = -EIO; + goto out_bh; + } gpm = (struct genericPartitionMap *) &(lvd->partitionMaps[offset]); type = gpm->partitionMapType; + min_len = sizeof(*gpm); + if (type == 1) + min_len = sizeof(struct genericPartitionMap1); + else if (type == 2) + min_len = sizeof(struct genericPartitionMap2); + if (gpm->partitionMapLength < min_len || + gpm->partitionMapLength > table_len - offset) { + udf_err(sb, "Invalid partition map length %u at offset %d\n", + gpm->partitionMapLength, offset); + ret = -EIO; + goto out_bh; + } if (type == 1) { struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)gpm; base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5 -- 2.43.0