summaryrefslogtreecommitdiffstats
path: root/block.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2014-04-14 15:39:36 +0200
committerKevin Wolf <kwolf@redhat.com>2014-04-22 11:57:02 +0200
commitda15ee5134f715adb07e3688a1c6e8b42cb6ac94 (patch)
tree5f33a291e25b374e131f2c4f375a3524183accf3 /block.c
parent1dd3a44753f10970ded50950d28353c00bfcaf91 (diff)
downloadhqemu-da15ee5134f715adb07e3688a1c6e8b42cb6ac94.zip
hqemu-da15ee5134f715adb07e3688a1c6e8b42cb6ac94.tar.gz
block: Catch integer overflow in bdrv_rw_co()
Insanely large requests could cause an integer overflow in bdrv_rw_co() while converting sectors to bytes. This patch catches the problem and returns an error (if we hadn't overflown the integer here, bdrv_check_byte_request() would have rejected the request, so we're not breaking anything that was supposed to work before). We actually do have a test case that triggers behaviour where we accidentally let such a request pass, so that it would return success, but read 0 bytes instead of the requested 4 GB. It fails now like it should. If the vdi block driver wants to be able to deal with huge images, it can't read the whole block bitmap at once into memory like it does today, but needs to use a metadata cache like qcow2 does. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/block.c b/block.c
index 5a0b421..ec3fa50 100644
--- a/block.c
+++ b/block.c
@@ -2690,6 +2690,10 @@ static int bdrv_rw_co(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,
.iov_len = nb_sectors * BDRV_SECTOR_SIZE,
};
+ if (nb_sectors < 0 || nb_sectors > INT_MAX / BDRV_SECTOR_SIZE) {
+ return -EINVAL;
+ }
+
qemu_iovec_init_external(&qiov, &iov, 1);
return bdrv_prwv_co(bs, sector_num << BDRV_SECTOR_BITS,
&qiov, is_write, flags);
OpenPOWER on IntegriCloud