]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
parallels: fix possible int overflow
authorDmitry Frolov <frolov@swemel.ru>
Wed, 6 Nov 2024 08:04:36 +0000 (11:04 +0300)
committerKevin Wolf <kwolf@redhat.com>
Mon, 25 Nov 2024 10:03:14 +0000 (11:03 +0100)
The sum "cluster_index + count" may overflow uint32_t.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
Message-ID: <20241106080521.219255-2-frolov@swemel.ru>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/parallels.c

index 9205a0864fa6ba96319eb58b3da54d11e99dcadb..071b6dcaf8b2acdbada8b58bcc5fefd84458d88f 100644 (file)
@@ -184,11 +184,11 @@ static int mark_used(BlockDriverState *bs, unsigned long *bitmap,
     BDRVParallelsState *s = bs->opaque;
     uint32_t cluster_index = host_cluster_index(s, off);
     unsigned long next_used;
-    if (cluster_index + count > bitmap_size) {
+    if ((uint64_t)cluster_index + count > bitmap_size) {
         return -E2BIG;
     }
     next_used = find_next_bit(bitmap, bitmap_size, cluster_index);
-    if (next_used < cluster_index + count) {
+    if (next_used < (uint64_t)cluster_index + count) {
         return -EBUSY;
     }
     bitmap_set(bitmap, cluster_index, count);