From: Peter Maydell <[email protected]> In vmdk_read_extent() we use 'int' for cluster_bytes and buf_bytes. However, cluster_bytes is extent->cluster_sectors * 512 and buf_bytes is cluster_bytes * 2. The maximum value for extent->cluster_sectors (enforced in vmdk_add_extent()) is 0x20_0000, and so the worst case for buf_bytes is 0x8000_0000, which overflows a signed int.
Make the variable types here int64_t, which matches the type used by bdrv_co_pread()'s bytes argument and by extent->cluster_sectors. The worst case thing that a malicious VMDK image could do is cause us to try to g_malloc() 0xffffffff80000000, which will cause QEMU to abort(), so this is a self-denial-of-service only, and so a hardening bug rather than a security issue. Cc: [email protected] Fixes: 2b2c8c5dec6ba ("VMDK: read/write compressed extent") Reported-by: boy juju <[email protected]> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3843 Signed-off-by: Peter Maydell <[email protected]> Message-ID: <[email protected]> Reviewed-by: Kevin Wolf <[email protected]> Signed-off-by: Kevin Wolf <[email protected]> (cherry picked from commit 53c06d5239b4a4cc21686710bce478207dfbaa6e) Signed-off-by: Michael Tokarev <[email protected]> diff --git a/block/vmdk.c b/block/vmdk.c index 117e25492bf..ae51c0de430 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1927,7 +1927,7 @@ vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset, int64_t offset_in_cluster, QEMUIOVector *qiov, int bytes) { int ret; - int cluster_bytes, buf_bytes; + int64_t cluster_bytes, buf_bytes; uint8_t *cluster_buf, *compressed_data; uint8_t *uncomp_buf; uint32_t data_len; -- 2.47.3
