From 585815c1f8f7bc453f1963f5c897df20a188049e Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Thu, 20 Oct 2022 14:34:27 +0200 Subject: [PATCH] libblkid: exfat - avoid undefined shift Exfat filesystem probe can use undefined shift if block_bits or bpc_bits is a bogus value. Avoid this by limiting shift size. Reproducer found with OSS-Fuzz (issue 52571) running over cryptsetup project (blkid is used in header init). Signed-off-by: Milan Broz --- libblkid/src/superblocks/exfat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libblkid/src/superblocks/exfat.c b/libblkid/src/superblocks/exfat.c index 101a2321e3..9d13094251 100644 --- a/libblkid/src/superblocks/exfat.c +++ b/libblkid/src/superblocks/exfat.c @@ -37,8 +37,8 @@ struct exfat_entry_label { uint8_t reserved[8]; } __attribute__((__packed__)); -#define BLOCK_SIZE(sb) (1u << (sb)->block_bits) -#define CLUSTER_SIZE(sb) (BLOCK_SIZE(sb) << (sb)->bpc_bits) +#define BLOCK_SIZE(sb) ((sb)->block_bits < 32 ? (1u << (sb)->block_bits) : 0) +#define CLUSTER_SIZE(sb) ((sb)->bpc_bits < 32 ? (BLOCK_SIZE(sb) << (sb)->bpc_bits) : 0) #define EXFAT_FIRST_DATA_CLUSTER 2 #define EXFAT_LAST_DATA_CLUSTER 0xffffff6 #define EXFAT_ENTRY_SIZE 32 -- 2.47.3