Skip to contentSkip to conversation

udf: reject descriptors with oversized CRC length

PATCH In review Michael Bommarito 2 participants 2 messages Apr 13 – Apr 14

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udf: reject descriptors with oversized CRC length

udf_read_tagged() skips CRC verification when descCRCLength + sizeof(struct tag) exceeds the block size. A crafted UDF image can set descCRCLength to an oversized value to bypass CRC validation entirely; the descriptor is then accepted based solely on the 8-bit tag checksum, which is trivially recomputable.

Reject such descriptors instead of silently accepting them. A legitimate single-block descriptor should never have a CRC length that exceeds the block.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Assisted-by Claude:claude-opus-4-6
Assisted-by Codex:gpt-5-4

---
Found during a filesystem security audit. The CRC validation condition in udf_read_tagged() uses OR logic: the first arm (descCRCLength too large) short-circuits the second arm (CRC comparison), so an oversized descCRCLength causes the function to return the buffer head without verifying the CRC. The descriptor is accepted based solely on the 8-bit tag checksum.

A crafted UDF image with descCRCLength set to blocksize (e.g. 2048 on a 2048-byte-block filesystem, vs the 2032 limit) in both the main and reserve Volume Descriptor Sequences mounts successfully with corrupted descriptor bodies.

Reproduced on UML (ARCH=um, KASAN-enabled v7.0-rc7) with a mkudffs-generated 20 MiB image, both LVD copies patched to descCRCLength=2040, CRC left stale, body byte flipped, tag checksum recomputed. Mount succeeds (MOUNT=0) with the corrupt LVD accepted. With this patch applied, mount fails with EINVAL and the new "CRC length ... exceeds block size" error is logged.

Reproducer details and UML console logs available on request.

 fs/udf/misc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
fs/udf/misc.c +6 -2
index 0788593b6a1d..6928e378fbbd 100644
@@ -230,8 +230,12 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
 	}
 
 	/* Verify the descriptor CRC */
-	if (le16_to_cpu(tag_p->descCRCLength) + sizeof(struct tag) > sb->s_blocksize ||
-	    le16_to_cpu(tag_p->descCRC) == crc_itu_t(0,
+	if (le16_to_cpu(tag_p->descCRCLength) + sizeof(struct tag) > sb->s_blocksize) {
+		udf_err(sb, "block %u: CRC length %u exceeds block size\n",
+			block, le16_to_cpu(tag_p->descCRCLength));
+		goto error_out;
+	}
+	if (le16_to_cpu(tag_p->descCRC) == crc_itu_t(0,
 					bh->b_data + sizeof(struct tag),
 					le16_to_cpu(tag_p->descCRCLength)))
 		return bh;
Signature · 1 line
2.53.0
reviewer
#1 lore raw
Quoted 10 lines · Michael Bommarito

udf_read_tagged() skips CRC verification when descCRCLength + sizeof(struct tag) exceeds the block size. A crafted UDF image can set descCRCLength to an oversized value to bypass CRC validation entirely; the descriptor is then accepted based solely on the 8-bit tag checksum, which is trivially recomputable.

Reject such descriptors instead of silently accepting them. A legitimate single-block descriptor should never have a CRC length that exceeds the block.

Quoted 5 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Assisted-by Claude:claude-opus-4-6
Assisted-by Codex:gpt-5-4

Thanks for the fix! It looks good to me. I'll merge it into my tree later this week once the pull requests for the merge window are done.

Honza

Quoted 47 lines

---
Found during a filesystem security audit. The CRC validation condition in udf_read_tagged() uses OR logic: the first arm (descCRCLength too large) short-circuits the second arm (CRC comparison), so an oversized descCRCLength causes the function to return the buffer head without verifying the CRC. The descriptor is accepted based solely on the 8-bit tag checksum.

A crafted UDF image with descCRCLength set to blocksize (e.g. 2048 on a 2048-byte-block filesystem, vs the 2032 limit) in both the main and reserve Volume Descriptor Sequences mounts successfully with corrupted descriptor bodies.

Reproduced on UML (ARCH=um, KASAN-enabled v7.0-rc7) with a mkudffs-generated 20 MiB image, both LVD copies patched to descCRCLength=2040, CRC left stale, body byte flipped, tag checksum recomputed. Mount succeeds (MOUNT=0) with the corrupt LVD accepted. With this patch applied, mount fails with EINVAL and the new "CRC length ... exceeds block size" error is logged.

Reproducer details and UML console logs available on request.

 fs/udf/misc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
fs/udf/misc.c +6 -2
index 0788593b6a1d..6928e378fbbd 100644
@@ -230,8 +230,12 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
 	}
 
 	/* Verify the descriptor CRC */
-	if (le16_to_cpu(tag_p->descCRCLength) + sizeof(struct tag) > sb->s_blocksize ||
-	    le16_to_cpu(tag_p->descCRC) == crc_itu_t(0,
+	if (le16_to_cpu(tag_p->descCRCLength) + sizeof(struct tag) > sb->s_blocksize) {
+		udf_err(sb, "block %u: CRC length %u exceeds block size\n",
+			block, le16_to_cpu(tag_p->descCRCLength));
+		goto error_out;
+	}
+	if (le16_to_cpu(tag_p->descCRC) == crc_itu_t(0,
 					bh->b_data + sizeof(struct tag),
 					le16_to_cpu(tag_p->descCRCLength)))
 		return bh;
Signature · 1 line
2.53.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR