[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 46/54] block: fix data type casting for crypto payloa
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 46/54] block: fix data type casting for crypto payload offset |
Date: |
Fri, 6 Oct 2017 17:54:14 +0200 |
From: "Daniel P. Berrange" <address@hidden>
The crypto APIs report the offset of the data payload as an uint64_t
type, but the block driver is casting to size_t or ssize_t which will
potentially truncate.
Most of the block APIs use int64_t for offsets meanwhile, so even if
using uint64_t in the crypto block driver we are still at risk of
truncation.
Change the block crypto driver to use uint64_t, but add asserts that
the value is less than INT64_MAX.
Reviewed-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/crypto.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/block/crypto.c b/block/crypto.c
index 684cabeaf8..61f5d77bc0 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -364,8 +364,9 @@ static int block_crypto_truncate(BlockDriverState *bs,
int64_t offset,
PreallocMode prealloc, Error **errp)
{
BlockCrypto *crypto = bs->opaque;
- size_t payload_offset =
+ uint64_t payload_offset =
qcrypto_block_get_payload_offset(crypto->block);
+ assert(payload_offset < (INT64_MAX - offset));
offset += payload_offset;
@@ -395,8 +396,9 @@ block_crypto_co_readv(BlockDriverState *bs, int64_t
sector_num,
uint8_t *cipher_data = NULL;
QEMUIOVector hd_qiov;
int ret = 0;
- size_t payload_offset =
+ uint64_t payload_offset =
qcrypto_block_get_payload_offset(crypto->block) / 512;
+ assert(payload_offset < (INT64_MAX / 512));
qemu_iovec_init(&hd_qiov, qiov->niov);
@@ -462,8 +464,9 @@ block_crypto_co_writev(BlockDriverState *bs, int64_t
sector_num,
uint8_t *cipher_data = NULL;
QEMUIOVector hd_qiov;
int ret = 0;
- size_t payload_offset =
+ uint64_t payload_offset =
qcrypto_block_get_payload_offset(crypto->block) / 512;
+ assert(payload_offset < (INT64_MAX / 512));
qemu_iovec_init(&hd_qiov, qiov->niov);
@@ -524,7 +527,9 @@ static int64_t block_crypto_getlength(BlockDriverState *bs)
BlockCrypto *crypto = bs->opaque;
int64_t len = bdrv_getlength(bs->file->bs);
- ssize_t offset = qcrypto_block_get_payload_offset(crypto->block);
+ uint64_t offset = qcrypto_block_get_payload_offset(crypto->block);
+ assert(offset < INT64_MAX);
+ assert(offset < len);
len -= offset;
--
2.13.6
- [Qemu-block] [PULL 35/54] qemu-iotests: Allow QMP pretty printing in common.qemu, (continued)
- [Qemu-block] [PULL 35/54] qemu-iotests: Allow QMP pretty printing in common.qemu, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 38/54] qemu-io: Add -C for opening with copy-on-read, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 41/54] block: Add blkdebug hook for copy-on-read, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 37/54] commit: Remove overlay_bs, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 39/54] block: Uniform handling of 0-length bdrv_get_block_status(), Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 40/54] iotests: Restore stty settings on completion, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 42/54] block: Perform copy-on-read in loop, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 36/54] qemu-iotests: Test commit block job where top has two parents, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 43/54] iotests: Add test 197 for covering copy-on-read, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 44/54] block: use 1 MB bounce buffers for crypto instead of 16KB, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 46/54] block: fix data type casting for crypto payload offset,
Kevin Wolf <=
- [Qemu-block] [PULL 45/54] crypto: expose encryption sector size in APIs, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 47/54] block: convert crypto driver to bdrv_co_preadv|pwritev, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 50/54] block/mirror: check backing in bdrv_mirror_top_refresh_filename, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 48/54] block: convert qcrypto_block_encrypt|decrypt to take bytes offset, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 49/54] block: support passthrough of BDRV_REQ_FUA in crypto driver, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 53/54] qcow2: truncate the tail of the image file after shrinking the image, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 54/54] block/mirror: check backing in bdrv_mirror_top_flush, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 51/54] iotests: Fix 195 if IMGFMT is part of TEST_DIR, Kevin Wolf, 2017/10/06
- [Qemu-block] [PULL 52/54] qcow2: fix return error code in qcow2_truncate(), Kevin Wolf, 2017/10/06
- Re: [Qemu-block] [Qemu-devel] [PULL 00/54] Block layer patches, Peter Maydell, 2017/10/06