Skip to contentSkip to conversation

block: Fix error code for bdrv_getlength when the image is too big

PATCH Applied Fam Zheng 4 participants 6 messages May 15, 2015 – May 18, 2015

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

v2 cover block: Fix error code for bdrv_getlength when the image is too big

v2: Correct detection of overflow. [Markus, Berto]

If the image has a huge enough virtual size,

  $ qemu-img info afl9.img
  qemu-img: Can't get size of device 'image': Unknown error -512

It's because of the multiplication overflow in the return statement in bdrv_getlength (the big nagetive value is later truncated to 0x200). Fix it to return -EFBIG:

qemu-img: Can't get size of device 'image': File too large

Bug reported by Richard Jones in:

https://bugzilla.redhat.com/show_bug.cgi?id=1221499

Fam Zheng (2):
block: Detect multiplication overflow in bdrv_getlength
qemu-iotests: qemu-img info on afl VMDK image with a huge capacity

 block.c                                        |   1 +
 tests/qemu-iotests/059                         |   5 +++++
 tests/qemu-iotests/059.out                     |   3 +++
 tests/qemu-iotests/sample_images/afl9.vmdk.bz2 | Bin 0 -> 178 bytes
 4 files changed, 9 insertions(+)
 create mode 100644 tests/qemu-iotests/sample_images/afl9.vmdk.bz2
Signature · 1 line
2.4.0
author
#1 lore raw

PATCH v2 1/2 block: Detect multiplication overflow in bdrv_getlength

Bogus image may have a large total_sectors that will overflow the multiplication. For cleanness, fix the return code so the error message will be meaningful.

---
 block.c | 1 +
 1 file changed, 1 insertion(+)
block.c +1 -0
index 7904098..5d271a1 100644
@@ -2330,6 +2330,7 @@ int64_t bdrv_getlength(BlockDriverState *bs)
 {
     int64_t ret = bdrv_nb_sectors(bs);
 
+    ret = ret > INT64_MAX / BDRV_SECTOR_SIZE ? -EFBIG : ret;
     return ret < 0 ? ret : ret * BDRV_SECTOR_SIZE;
 }
 
Signature · 1 line
2.4.0
author
#3 lore raw

PATCH v2 2/2 qemu-iotests: qemu-img info on afl VMDK image with a huge capacity

In reply to Fam Zheng

The image is contributed by Richard W.M. Jones.

---
 tests/qemu-iotests/059                         |   5 +++++
 tests/qemu-iotests/059.out                     |   3 +++
 tests/qemu-iotests/sample_images/afl9.vmdk.bz2 | Bin 0 -> 178 bytes
 3 files changed, 8 insertions(+)
 create mode 100644 tests/qemu-iotests/sample_images/afl9.vmdk.bz2
tests/qemu-iotests/059 +5 -0
index 50ca5ce..0ded0c3 100755
@@ -132,6 +132,11 @@ _img_info
 $QEMU_IO -c "write -P 0xa 900G 512" "$TEST_IMG" | _filter_qemu_io
 $QEMU_IO -c "read -v 900G 1024" "$TEST_IMG" | _filter_qemu_io
 
+echo
+echo "=== Testing afl image with a very large capacity ==="
+_use_sample_img afl9.vmdk.bz2
+_img_info
+
 # success, all done
 echo "*** done"
 rm -f $seq.full
tests/qemu-iotests/059.out +3 -0
index cbb0de4..67e3cf5 100644
@@ -2336,4 +2336,7 @@ e1000003e0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
 e1000003f0:  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
 read 1024/1024 bytes at offset 966367641600
 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+=== Testing afl image with a very large capacity ===
+qemu-img: Can't get size of device 'image': File too large
 *** done
tests/qemu-iotests/sample_images/afl9.vmdk.bz2 new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..03615d36a12425cf4240bab86f4cfe648db14572
GIT binary patch
Signature · 1 line
2.4.0
Reviewed-by on the v2 series
#4 lore raw
In reply to Fam Zheng
Quoted 11 lines · Fam Zheng

v2: Correct detection of overflow. [Markus, Berto]

If the image has a huge enough virtual size,

  $ qemu-img info afl9.img
  qemu-img: Can't get size of device 'image': Unknown error -512

It's because of the multiplication overflow in the return statement in bdrv_getlength (the big nagetive value is later truncated to 0x200). Fix it to return -EFBIG:

Quoted 5 lines

qemu-img: Can't get size of device 'image': File too large

Bug reported by Richard Jones in:

https://bugzilla.redhat.com/show_bug.cgi?id=1221499

Series

Applied
#5 lore raw
In reply to Fam Zheng

Am 15.05.2015 um 10:36 hat Fam Zheng geschrieben:

Quoted 11 lines

v2: Correct detection of overflow. [Markus, Berto]

If the image has a huge enough virtual size,

  $ qemu-img info afl9.img
  qemu-img: Can't get size of device 'image': Unknown error -512

It's because of the multiplication overflow in the return statement in bdrv_getlength (the big nagetive value is later truncated to 0x200). Fix it to return -EFBIG:

Quoted 5 lines

qemu-img: Can't get size of device 'image': File too large

Bug reported by Richard Jones in:

https://bugzilla.redhat.com/show_bug.cgi?id=1221499

Thanks, applied to the block branch.

Kevin