[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/20] block: fix theoretical overflow in bdrv_init_padding()
From: |
Eric Blake |
Subject: |
[PULL 04/20] block: fix theoretical overflow in bdrv_init_padding() |
Date: |
Tue, 2 Feb 2021 16:45:13 -0600 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Calculation of sum may theoretically overflow, so use 64bit type and
add some good assertions.
Use int64_t constantly.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20201211183934.169161-4-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: tweak assertion order]
Signed-off-by: Eric Blake <eblake@redhat.com>
---
block/io.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/block/io.c b/block/io.c
index ab953bd58f48..c8c9dea55466 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1565,8 +1565,12 @@ static bool bdrv_init_padding(BlockDriverState *bs,
int64_t offset, int64_t bytes,
BdrvRequestPadding *pad)
{
- uint64_t align = bs->bl.request_alignment;
- size_t sum;
+ int64_t align = bs->bl.request_alignment;
+ int64_t sum;
+
+ bdrv_check_request(offset, bytes, &error_abort);
+ assert(align <= INT_MAX); /* documented in block/block_int.h */
+ assert(align <= SIZE_MAX / 2); /* so we can allocate the buffer */
memset(pad, 0, sizeof(*pad));
--
2.30.0
- [PULL 00/20] NBD patches for 2021-02-02, Eric Blake, 2021/02/02
- [PULL 01/20] iotests: Fix expected whitespace for 185, Eric Blake, 2021/02/02
- [PULL 03/20] util/iov: make qemu_iovec_init_extended() honest, Eric Blake, 2021/02/02
- [PULL 04/20] block: fix theoretical overflow in bdrv_init_padding(),
Eric Blake <=
- [PULL 02/20] block: refactor bdrv_check_request: add errp, Eric Blake, 2021/02/02
- [PULL 07/20] block/throttle-groups: throttle_group_co_io_limits_intercept(): 64bit bytes, Eric Blake, 2021/02/02
- [PULL 05/20] block/io: refactor bdrv_pad_request(): move bdrv_pad_request() up, Eric Blake, 2021/02/02
- [PULL 08/20] block/io: improve bdrv_check_request: check qiov too, Eric Blake, 2021/02/02
- [PULL 06/20] block/io: bdrv_pad_request(): support qemu_iovec_init_extended failure, Eric Blake, 2021/02/02
- [PULL 09/20] block: use int64_t as bytes type in tracked requests, Eric Blake, 2021/02/02
- [PULL 10/20] block/io: use int64_t bytes in driver wrappers, Eric Blake, 2021/02/02
- [PULL 11/20] block/io: support int64_t bytes in bdrv_co_do_pwrite_zeroes(), Eric Blake, 2021/02/02
- [PULL 12/20] block/io: support int64_t bytes in bdrv_aligned_pwritev(), Eric Blake, 2021/02/02
- [PULL 16/20] block/io: support int64_t bytes in read/write wrappers, Eric Blake, 2021/02/02