[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 24/37] qcow2: avoid misaligned 64bit bswap
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 24/37] qcow2: avoid misaligned 64bit bswap |
Date: |
Thu, 5 Nov 2015 19:17:52 +0100 |
From: John Snow <address@hidden>
If we create a buffer directly on the stack by using 12 bytes, there's
no guarantee the 64bit value we want to swap will be aligned, which
could cause errors with undefined behavior.
Spotted with clang -fsanitize=undefined and observed in iotests 15, 26,
44, 115 and 121.
Signed-off-by: John Snow <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-refcount.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 4b81c8d..6e0e5bd 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -560,13 +560,16 @@ static int alloc_refcount_block(BlockDriverState *bs,
}
/* Hook up the new refcount table in the qcow2 header */
- uint8_t data[12];
- cpu_to_be64w((uint64_t*)data, table_offset);
- cpu_to_be32w((uint32_t*)(data + 8), table_clusters);
+ struct QEMU_PACKED {
+ uint64_t d64;
+ uint32_t d32;
+ } data;
+ cpu_to_be64w(&data.d64, table_offset);
+ cpu_to_be32w(&data.d32, table_clusters);
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE);
ret = bdrv_pwrite_sync(bs->file->bs,
offsetof(QCowHeader, refcount_table_offset),
- data, sizeof(data));
+ &data, sizeof(data));
if (ret < 0) {
goto fail_table;
}
--
1.8.3.1
- [Qemu-devel] [PULL 14/37] blockdev: read-only-mode for blockdev-change-medium, (continued)
- [Qemu-devel] [PULL 14/37] blockdev: read-only-mode for blockdev-change-medium, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 19/37] block: support passing 'backing': '' to 'blockdev-add', Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 12/37] qmp: Introduce blockdev-change-medium, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 17/37] block: check for existing device IDs in external_snapshot_prepare(), Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 18/37] block: rename BlockdevSnapshot to BlockdevSnapshotSync, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 22/37] commit: reopen overlay_bs before base, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 21/37] block: add tests for the 'blockdev-snapshot' command, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 26/37] throttle: Check for pending requests in throttle_group_unregister_bs(), Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 23/37] qemu-iotests: Test the reopening of overlay_bs in 'block-commit', Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 25/37] qemu-img: add check for zero-length job len, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 24/37] qcow2: avoid misaligned 64bit bswap,
Kevin Wolf <=
- [Qemu-devel] [PULL 27/37] throttle: Use bs->throttle_state instead of bs->io_limits_enabled, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 20/37] block: add a 'blockdev-snapshot' QMP command, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 16/37] iotests: Add test for change-related QMP commands, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 28/37] block: Disallow snapshots if the overlay doesn't support backing files, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 29/37] block: Remove inner quotation marks in iotest 085, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 34/37] block: Add blk_get_refcnt(), Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 31/37] qemu-iotests: fix cleanup of background processes, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 30/37] block: test 'blockdev-snapshot' using a file BDS as the overlay, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 32/37] qemu-iotests: fix -valgrind option for check, Kevin Wolf, 2015/11/05
- [Qemu-devel] [PULL 33/37] mirror: block all operations on the target image during the job, Kevin Wolf, 2015/11/05