[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 24/26] vmdk: Fix data corruption bug in WRITE and RE
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 24/26] vmdk: Fix data corruption bug in WRITE and READ handling |
Date: |
Wed, 14 Nov 2012 19:47:25 +0100 |
From: Gerhard Wiesinger <address@hidden>
Fixed a MAJOR BUG in VMDK files on file boundaries on reads
and ALSO ON WRITES WHICH MIGHT CORRUPT THE IMAGE AND DATA!!!!!!
Triggered for example with the following VMDK file (partly listed):
RW 4193792 FLAT "XP-W1-f001.vmdk" 0
RW 2097664 FLAT "XP-W1-f002.vmdk" 0
RW 4193792 FLAT "XP-W1-f003.vmdk" 0
RW 512 FLAT "XP-W1-f004.vmdk" 0
RW 4193792 FLAT "XP-W1-f005.vmdk" 0
RW 2097664 FLAT "XP-W1-f006.vmdk" 0
RW 4193792 FLAT "XP-W1-f007.vmdk" 0
RW 512 FLAT "XP-W1-f008.vmdk" 0
Patch includes:
1.) Patch fixes wrong calculation on extent boundaries. Especially it
fixes the relativeness of the sector number to the current extent.
Verfied correctness with:
1.) Converted either with Virtualbox to VDI and then with qemu-img and
then with qemu-img only:
VBoxManage clonehd --format vdi /VM/XP-W/new/XP-W1.vmdk
~/.VirtualBox/Harddisks/XP-W1-new-test.vdi
./qemu-img convert -O raw ~/.VirtualBox/Harddisks/XP-W1-new-test.vdi
/root/QEMU/VM-XP-W1/XP-W1-via-VBOX.img
md5sum /root/QEMU/VM-XP-W/XP-W1-direct.img
md5sum /root/QEMU/VM-XP-W/XP-W1-via-VBOX.img
=> same MD5 hash
2.) Verified debug log files
3.) Run Windows XP successfully
4.) chkdsk run successfully without any errors
Signed-off-by: Gerhard Wiesinger <address@hidden>
Acked-by: Fam Zheng <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vmdk.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index 1a80e5a..51398c0 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1092,6 +1092,7 @@ static int vmdk_read(BlockDriverState *bs, int64_t
sector_num,
BDRVVmdkState *s = bs->opaque;
int ret;
uint64_t n, index_in_cluster;
+ uint64_t extent_begin_sector, extent_relative_sector_num;
VmdkExtent *extent = NULL;
uint64_t cluster_offset;
@@ -1103,7 +1104,9 @@ static int vmdk_read(BlockDriverState *bs, int64_t
sector_num,
ret = get_cluster_offset(
bs, extent, NULL,
sector_num << 9, 0, &cluster_offset);
- index_in_cluster = sector_num % extent->cluster_sectors;
+ extent_begin_sector = extent->end_sector - extent->sectors;
+ extent_relative_sector_num = sector_num - extent_begin_sector;
+ index_in_cluster = extent_relative_sector_num %
extent->cluster_sectors;
n = extent->cluster_sectors - index_in_cluster;
if (n > nb_sectors) {
n = nb_sectors;
@@ -1154,6 +1157,7 @@ static int vmdk_write(BlockDriverState *bs, int64_t
sector_num,
VmdkExtent *extent = NULL;
int n, ret;
int64_t index_in_cluster;
+ uint64_t extent_begin_sector, extent_relative_sector_num;
uint64_t cluster_offset;
VmdkMetaData m_data;
@@ -1196,7 +1200,9 @@ static int vmdk_write(BlockDriverState *bs, int64_t
sector_num,
if (ret) {
return -EINVAL;
}
- index_in_cluster = sector_num % extent->cluster_sectors;
+ extent_begin_sector = extent->end_sector - extent->sectors;
+ extent_relative_sector_num = sector_num - extent_begin_sector;
+ index_in_cluster = extent_relative_sector_num %
extent->cluster_sectors;
n = extent->cluster_sectors - index_in_cluster;
if (n > nb_sectors) {
n = nb_sectors;
--
1.7.6.5
- [Qemu-devel] [PATCH 07/26] aio: switch aiocb_size type int -> size_t, (continued)
- [Qemu-devel] [PATCH 07/26] aio: switch aiocb_size type int -> size_t, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 08/26] aio: use g_slice_alloc() for AIOCB pooling, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 10/26] fdc: Remove status0 parameter from fdctrl_set_fifo(), Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 09/26] aio: rename AIOPool to AIOCBInfo, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 12/26] fdc-test: insert media before fuzzing registers, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 13/26] fdc-test: add tests for non-DMA READ command, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 14/26] fdc: use status0 field instead of a local variable, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 18/26] fdc-test: Check READ ID, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 17/26] fdc: fix false FD_SR0_SEEK, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 16/26] fdc: fix FD_SR0_SEEK for initial seek on DMA transfers, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 24/26] vmdk: Fix data corruption bug in WRITE and READ handling,
Kevin Wolf <=
- [Qemu-devel] [PATCH 21/26] fdc: remove double affectation of FD_MSR_CMDBUSY flag, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 20/26] fdc-tests: add tests for VERIFY command, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 22/26] fdc: fix typo in zero constant, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 19/26] fdc: implement VERIFY command, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 23/26] fdc: remove last usage of FD_STATE_SEEK, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 11/26] fdc-test: split test_media_change() test, so insert part can be reused, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 15/26] fdc: fix FD_SR0_SEEK for non-DMA transfers and multi sectors transfers, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 25/26] megasas: Use bdrv_drain_all instead of qemu_aio_flush, Kevin Wolf, 2012/11/14
- [Qemu-devel] [PATCH 26/26] qemu-io: Use bdrv_drain_all instead of qemu_aio_flush, Kevin Wolf, 2012/11/14
- Re: [Qemu-devel] [PULL 00/26] Block patches, Kevin Wolf, 2012/11/19