nbdkit/0001-vddk-Don-t-use-uniniti...

72 lines
2.6 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 3578c005c8a2f479eb223bb89f7b0fba22d13766 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 22 Mar 2022 11:04:56 +0000
Subject: [PATCH] vddk: Don't use uninitialized values when computing preferred
block size
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Commit 63d2dd2eb2 ("vddk: Export block size information for this
plugin") tried to calculate the preferred block size from the logical
and physical sector size reported by VDDK. Unfortunately VDDK < 7s
VixDiskLib_GetInfo API returns a struct which does not contain
these fields at all. We knew about this already because the
debug code does not print them, but the block size code uses
them regardless of the VDDK version.
The practical result of this error was that sometimes (depending on
existing contents of memory) you would see the error:
nbdkit: vddk[1]: error: plugin must set preferred block size to a power of 2
Fix this by only using the fields when VDDK >= 7, and in earlier
versions assuming VDDKs normal sector size.
Reported-by: Xiaodai Wang
Fixes: commit 63d2dd2eb2c9980a07841fe84ec16844085a59c3
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2066655
(cherry picked from commit 31bc5322b179545bef827022e1ae3b7859387b1b)
---
plugins/vddk/vddk.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/plugins/vddk/vddk.c b/plugins/vddk/vddk.c
index 5d31b073..51ef8f33 100644
--- a/plugins/vddk/vddk.c
+++ b/plugins/vddk/vddk.c
@@ -855,6 +855,7 @@ vddk_block_size (void *handle,
{
struct vddk_handle *h = handle;
VixDiskLibInfo *info;
+ uint32_t logicalSectorSize, physicalSectorSize;
struct command info_cmd = { .type = INFO, .ptr = &info };
if (send_command_and_wait (h, &info_cmd) == -1)
@@ -862,8 +863,20 @@ vddk_block_size (void *handle,
/* VDDK can only serve whole 512 byte sectors. */
*minimum = VIXDISKLIB_SECTOR_SIZE;
- *preferred = MAX (MAX (info->logicalSectorSize, info->physicalSectorSize),
- 4096);
+
+ /* The logicalSectorSize and physicalSectorSize fields are only
+ * present in VDDK >= 7. In earlier versions they will not be
+ * initialized and contain random values (beyond the end of the
+ * returned structure). So compute sector sizes with this in mind.
+ */
+ logicalSectorSize = physicalSectorSize = VIXDISKLIB_SECTOR_SIZE;
+ if (library_version >= 7) {
+ logicalSectorSize = info->logicalSectorSize;
+ physicalSectorSize = info->physicalSectorSize;
+ }
+
+ *preferred = MAX (MAX (logicalSectorSize, physicalSectorSize), 4096);
+
*maximum = 0xffffffff;
VDDK_CALL_START (VixDiskLib_FreeInfo, "info")
--
2.31.1