[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-7.2.8 14/24] vmdk: Don't corrupt desc file in vmdk_write_cid
From: |
Michael Tokarev |
Subject: |
[Stable-7.2.8 14/24] vmdk: Don't corrupt desc file in vmdk_write_cid |
Date: |
Wed, 13 Dec 2023 16:00:23 +0300 |
From: Fam Zheng <fam@euphon.net>
If the text description file is larger than DESC_SIZE, we force the last
byte in the buffer to be 0 and write it out.
This results in a corruption.
Try to allocate a big buffer in this case.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1923
Signed-off-by: Fam Zheng <fam@euphon.net>
Message-ID: <20231124115654.3239137-1-fam@euphon.net>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 9fb7b350ba9816ebca8a7614fec486fd4269ab2d)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
(Mjt: fixups in block/vmdk.c due to missing-in-7.2 v8.0.0-2084-g28944f99c4
"vmdk: mark more functions as coroutine_fns and GRAPH_RDLOCK")
diff --git a/block/vmdk.c b/block/vmdk.c
index 26376352b9..f8d3a13568 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -346,29 +346,41 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t
cid)
BDRVVmdkState *s = bs->opaque;
int ret = 0;
- desc = g_malloc0(DESC_SIZE);
- tmp_desc = g_malloc0(DESC_SIZE);
- ret = bdrv_pread(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
+ size_t desc_buf_size;
+
+ if (s->desc_offset == 0) {
+ desc_buf_size = bdrv_getlength(bs->file->bs);
+ if (desc_buf_size > 16ULL << 20) {
+ error_report("VMDK description file too big");
+ return -EFBIG;
+ }
+ } else {
+ desc_buf_size = DESC_SIZE;
+ }
+
+ desc = g_malloc0(desc_buf_size);
+ tmp_desc = g_malloc0(desc_buf_size);
+ ret = bdrv_pread(bs->file, s->desc_offset, desc_buf_size, desc, 0);
if (ret < 0) {
goto out;
}
- desc[DESC_SIZE - 1] = '\0';
+ desc[desc_buf_size - 1] = '\0';
tmp_str = strstr(desc, "parentCID");
if (tmp_str == NULL) {
ret = -EINVAL;
goto out;
}
- pstrcpy(tmp_desc, DESC_SIZE, tmp_str);
+ pstrcpy(tmp_desc, desc_buf_size, tmp_str);
p_name = strstr(desc, "CID");
if (p_name != NULL) {
p_name += sizeof("CID");
- snprintf(p_name, DESC_SIZE - (p_name - desc), "%" PRIx32 "\n", cid);
- pstrcat(desc, DESC_SIZE, tmp_desc);
+ snprintf(p_name, desc_buf_size - (p_name - desc), "%" PRIx32 "\n",
cid);
+ pstrcat(desc, desc_buf_size, tmp_desc);
}
- ret = bdrv_pwrite_sync(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
+ ret = bdrv_pwrite_sync(bs->file, s->desc_offset, desc_buf_size, desc, 0);
out:
g_free(desc);
diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059
index e8be217e1f..9bcf1e7525 100755
--- a/tests/qemu-iotests/059
+++ b/tests/qemu-iotests/059
@@ -84,6 +84,8 @@ echo
echo "=== Testing big twoGbMaxExtentFlat ==="
_make_test_img -o "subformat=twoGbMaxExtentFlat" 1000G
_img_info --format-specific | _filter_img_info --format-specific
+$QEMU_IO -c "write 990G 512 -P 89" "$TEST_IMG" | _filter_qemu_io
+$QEMU_IO -c "read 990G 512 -P 89" "$TEST_IMG" | _filter_qemu_io
_cleanup_test_img
echo
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
index 2b83c0c8b6..275ee7c778 100644
--- a/tests/qemu-iotests/059.out
+++ b/tests/qemu-iotests/059.out
@@ -2032,6 +2032,10 @@ Format specific information:
virtual size: 2147483648
filename: TEST_DIR/t-f500.IMGFMT
format: FLAT
+wrote 512/512 bytes at offset 1063004405760
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+read 512/512 bytes at offset 1063004405760
+512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
=== Testing malformed VMFS extent description line ===
qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Invalid extent line: RW 12582912
VMFS "dummy.IMGFMT" 1
--
2.39.2
- [Stable-7.2.8 04/24] net: Update MemReentrancyGuard for NIC, (continued)
- [Stable-7.2.8 04/24] net: Update MemReentrancyGuard for NIC, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 05/24] linux-user: Fix loaddr computation for some elf files, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 03/24] net: Provide MemReentrancyGuard * to qemu_new_nic(), Michael Tokarev, 2023/12/13
- [Stable-7.2.8 07/24] tests/avocado: Replace assertRegexpMatches() for Python 3.12 compatibility, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 12/24] hw/nvram/xlnx-efuse-ctrl: Free XlnxVersalEFuseCtrl[] "pg0-lock" array, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 09/24] hw/virtio: Free VirtIOIOMMUPCI::vdev.reserved_regions[] on finalize(), Michael Tokarev, 2023/12/13
- [Stable-7.2.8 10/24] hw/misc/mps2-scc: Free MPS2SCC::oscclk[] array on finalize(), Michael Tokarev, 2023/12/13
- [Stable-7.2.8 11/24] hw/nvram/xlnx-efuse: Free XlnxEFuse::ro_bits[] array on finalize(), Michael Tokarev, 2023/12/13
- [Stable-7.2.8 13/24] hw/virtio: Add VirtioPCIDeviceTypeInfo::instance_finalize field, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 15/24] hw/mips/malta: Fix the malta machine on big endian hosts, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 14/24] vmdk: Don't corrupt desc file in vmdk_write_cid,
Michael Tokarev <=
- [Stable-7.2.8 18/24] hw/acpi/erst: Do not ignore Error* in realize handler, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 16/24] hw/audio/hda-codec: fix multiplication overflow, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 21/24] ui/gtk-egl: move function calls back to regular code path, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 20/24] ui/gtk-egl: Check EGLSurface before doing scanout, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 19/24] msix: unset PCIDevice::msix_vector_poll_notifier in rollback, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 24/24] system/memory: use ldn_he_p/stn_he_p, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 22/24] ui/vnc-clipboard: fix inflate_buffer, Michael Tokarev, 2023/12/13
- [Stable-7.2.8 23/24] target/arm: Disable SME if SVE is disabled, Michael Tokarev, 2023/12/13
- Re: [Stable-7.2.8 00/24] Patch Round-up for stable 7.2.8, freeze on 2023-12-23, Cole Robinson, 2023/12/13