Skip to contentSkip to conversation

parallels: fix ext_off assertion failure due to overflow

PATCH New [email protected] 2 participants 3 messages Dec 12, 2024 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 parallels: fix ext_off assertion failure due to overflow

Hi,
If necessary, I can provide an image file to reproduce the error.

Regards,
Denis Rastyogin

#1 lore raw

PATCH 1/1 parallels: fix ext_off assertion failure due to overflow

From: Denis Rastyogin <[email protected]>

This error was discovered by fuzzing qemu-img.

When ph.ext_off has a sufficiently large value, the operation le64_to_cpu(ph.ext_off) << BDRV_SECTOR_BITS in parallels_read_format_extension() can cause an overflow in int64_t. This overflow triggers the assert(ext_off > 0)
check in block/parallels-ext.c: parallels_read_format_extension(), leading to a crash.

This commit adds a check to prevent overflow when shifting ph.ext_off by BDRV_SECTOR_BITS, ensuring that the value remains within a valid range.

---
 block/parallels.c | 4 ++++
 1 file changed, 4 insertions(+)
block/parallels.c +4 -0
index 9205a0864f..8f2b58e1c9 100644
@@ -1298,6 +1298,10 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
         error_setg(errp, "Catalog too large");
         return -EFBIG;
     }
+    if (le64_to_cpu(ph.ext_off) >= (INT64_MAX >> BDRV_SECTOR_BITS)) {
+        error_setg(errp, "Invalid image: Too big offset");
+        return -EFBIG;
+    }
 
     size = bat_entry_off(s->bat_size);
     s->header_size = ROUND_UP(size, bdrv_opt_mem_align(bs->file->bs));
Signature · 1 line
2.42.2
Reviewed-by on v1 1/1
#2 lore raw
Quoted 25 lines · On 12/12/24 11:41, [email protected] wrote:

From: Denis Rastyogin <[email protected]>

This error was discovered by fuzzing qemu-img.

When ph.ext_off has a sufficiently large value, the operation le64_to_cpu(ph.ext_off) << BDRV_SECTOR_BITS in parallels_read_format_extension() can cause an overflow in int64_t. This overflow triggers the assert(ext_off > 0)
check in block/parallels-ext.c: parallels_read_format_extension(), leading to a crash.

This commit adds a check to prevent overflow when shifting ph.ext_off by BDRV_SECTOR_BITS, ensuring that the value remains within a valid range.

---
  block/parallels.c | 4 ++++
  1 file changed, 4 insertions(+)
block/parallels.c +0 -0
index 9205a0864f..8f2b58e1c9 100644

block/parallels.c static int parallels_open(BlockDriverState *bs, QDict *options, int flags, · line 1307

Quoted 10 lines
block/parallels.c +4 -0
@@ -1298,6 +1298,10 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
          error_setg(errp, "Catalog too large");
          return -EFBIG;
      }
+    if (le64_to_cpu(ph.ext_off) >= (INT64_MAX >> BDRV_SECTOR_BITS)) {
+        error_setg(errp, "Invalid image: Too big offset");
+        return -EFBIG;
+    }
 
      size = bat_entry_off(s->bat_size);
      s->header_size = ROUND_UP(size, bdrv_opt_mem_align(bs->file->bs));