From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org
Subject: [PULL 06/11] block/vmdk: Avoid overflowing multiplication in vmdk_open_vmdk4()
Date: Mon, 9 Nov 2026 17:45:28 +0100 [thread overview]
Message-ID: <20261109164533.293487-7-kwolf@redhat.com> (raw)
In-Reply-To: <20261109164533.293487-1-kwolf@redhat.com>
From: Peter Maydell <peter.maydell@linaro.org>
In vmdk_open_vmdk4() we set the uint32_t l1_entry_sectors with:
l1_entry_sectors = le32_to_cpu(header.num_gtes_per_gt)
* le64_to_cpu(header.granularity);
We have checked that num_gtes_per_gt is at most 512, but the
header.granularity has not been checked at this point, and so the
multiply can overflow the 32-bit variable. This overflow is harmless
beacuse we're about to call vmdk_add_extent(), which will fail if the
header.granularity (cluster_sectors) is more than 0x20_0000, but it's
a potential trap for the future if code that relies on the
l1_entry_sectors value gets added between where we set it and where
we make that check.
Check for overlarge granularity at the point of multiplication so
it's clear we can't overflow.
Cc: qemu-stable@nongnu.org
Reported-by: Tristan <https://gitlab.com/TristanInSec>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4029
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <20261103143516.2182626-6-peter.maydell@linaro.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/vmdk.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index d7e23ae8098..a9bd8a4245f 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1052,7 +1052,10 @@ vmdk_open_vmdk4(BlockDriverState *bs, BdrvChild *file, int flags,
error_setg(errp, "L2 table size too big");
return -EINVAL;
}
-
+ if (le64_to_cpu(header.granularity) > 0x200000) {
+ error_setg(errp, "Invalid granularity, image may be corrupt");
+ return -EFBIG;
+ }
l1_entry_sectors = le32_to_cpu(header.num_gtes_per_gt)
* le64_to_cpu(header.granularity);
if (l1_entry_sectors == 0) {
--
2.56.0
next prev parent reply other threads:[~2026-11-09 16:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 16:45 [PULL 00/11] Block layer patches Kevin Wolf
2026-11-09 16:45 ` [PULL 01/11] iotests: add --quiet arg to hide env variable dump Kevin Wolf
2026-11-09 16:45 ` [PULL 02/11] block/vmdk: Avoid assertion if image file has no extents Kevin Wolf
2026-11-09 16:45 ` [PULL 03/11] block/vmdk: Avoid reading off the end of descriptor memory Kevin Wolf
2026-11-09 16:45 ` [PULL 04/11] block/vmdk: Use larger types for byte counts in vmdk_read_extent() Kevin Wolf
2026-11-09 16:45 ` [PULL 05/11] block/vmdk: Reject a zero cluster_sectors parameter Kevin Wolf
2026-11-09 16:45 ` Kevin Wolf [this message]
2026-11-09 16:45 ` [PULL 07/11] block: add missing coroutine_fn annotations Kevin Wolf
2026-11-09 16:45 ` [PULL 08/11] iotests/290: add test case to check 'discard-no-unref' option behavior Kevin Wolf
2026-11-09 16:45 ` [PULL 09/11] qcow2: fix snapshot data corruption with discard-no-unref=on Kevin Wolf
2026-11-09 16:45 ` [PULL 10/11] iotests/290: add 'discard' and 'write -z -u' case with a snapshot Kevin Wolf
2026-11-09 16:45 ` [PULL 11/11] block/vhdx: Prevent out-of-bounds BAT accesses with malicious vhdx files Kevin Wolf
2026-11-09 20:53 ` [PULL 00/11] Block layer patches Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261109164533.293487-7-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.