Skip to contentSkip to conversation

block/vmdk: prevent division by zero with zero cluster sectors

PATCH New [email protected] 1 participant 1 message Aug 17 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/vmdk: prevent division by zero with zero cluster sectors

From: Denis Rastyogin <[email protected]>

A zero cluster_sectors value passes the existing upper-bound check and later causes a division-by-zero in get_cluster_offset().

UBSan reports:

../block/vmdk.c:1608:30: runtime error: division by zero

    #0 0x5562d3b3b63b in get_cluster_offset ../block/vmdk.c:1608
    #1 0x5562d3db9aa7 in vmdk_co_block_status ../block/vmdk.c:1796
    #2 0x5562d3c48bb3 in bdrv_co_do_block_status ../block/io.c:2494
    #3 0x5562d3c55a3d in bdrv_co_common_block_status_above ../block/io.c:2672
    #4 0x5562d3c5630e in bdrv_co_block_status_above ../block/io.c:2752
    #5 0x5562d3ec5a3d in bdrv_co_block_status_above_entry block/block-gen.c:386
    #6 0x5562d40ab573 in coroutine_trampoline ../util/coroutine-ucontext.c:175
---
 block/vmdk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/vmdk.c +1 -1
index cd8b4ec7c8..7a7935b25a 100644
@@ -537,7 +537,7 @@ static int vmdk_add_extent(BlockDriverState *bs,
     BDRVVmdkState *s = bs->opaque;
     int64_t nb_sectors;
 
-    if (cluster_sectors > 0x200000) {
+    if (cluster_sectors == 0 || cluster_sectors > 0x200000) {
         /* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */
         error_setg(errp, "Invalid granularity, image may be corrupt");
         return -EFBIG;
Signature · 1 line
2.50.1