All of lore.kernel.org
 help / color / mirror / Atom feed
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 3/8] block/vhdx-log: Improve sanity checks to avoid OOB accesses with bad images
Date: Tue, 17 Nov 2026 18:17:53 +0100	[thread overview]
Message-ID: <20261117171758.237462-4-kwolf@redhat.com> (raw)
In-Reply-To: <20261117171758.237462-1-kwolf@redhat.com>

From: Thomas Huth <thuth@redhat.com>

The multiplication "hdr->descriptor_count * sizeof(VHDXLogDescriptor)" in
vhdx_log_hdr_is_valid() can overflow on 32-bit systems, so this function
could mark bad images as valid when the truncated result is smaller than
hdr->entry_length. Switch to a division on the right hand side instead to
avoid the overflow problems.

The second problem is in vhdx_log_read_desc(): desc_sectors is a 32-bit
value, thus the multiplication "desc_sectors * VHDX_LOG_SECTOR_SIZE" is
also done with 32 bit arithmetics, and the result is used as "size_t"
parameter for qemu_try_blockalign(), i.e. the parameter here is also
only 32 bits on 32-bit systems. Let's add a sanity check here to avoid
the overflow problem that could lead to trouble later.

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3860
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20261111150659.253918-1-thuth@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/vhdx-log.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/block/vhdx-log.c b/block/vhdx-log.c
index 4385a2d4f62..5c20468e1e6 100644
--- a/block/vhdx-log.c
+++ b/block/vhdx-log.c
@@ -246,7 +246,7 @@ static bool vhdx_log_hdr_is_valid(VHDXLogEntries *log, VHDXLogEntryHeader *hdr,
         goto exit;
     }
 
-    if (hdr->descriptor_count * sizeof(VHDXLogDescriptor) > hdr->entry_length) {
+    if (hdr->descriptor_count > hdr->entry_length / sizeof(VHDXLogDescriptor)) {
         goto exit;
     }
 
@@ -360,6 +360,10 @@ vhdx_log_read_desc(BlockDriverState *bs, BDRVVHDXState *s, VHDXLogEntries *log,
     }
 
     desc_sectors = vhdx_compute_desc_sectors(hdr.descriptor_count);
+    if (desc_sectors > UINT32_MAX / VHDX_LOG_SECTOR_SIZE) {
+        ret = -EINVAL;
+        goto exit;
+    }
     desc_entries = qemu_try_blockalign(bs->file->bs,
                                        desc_sectors * VHDX_LOG_SECTOR_SIZE);
     if (desc_entries == NULL) {
-- 
2.56.1



  parent reply	other threads:[~2026-11-17 17:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 17:17 [PULL 0/8] Block layer patches Kevin Wolf
2026-11-17 17:17 ` [PULL 1/8] block/bochs: validate bitmap size and compute extent_blocks after validation Kevin Wolf
2026-11-17 17:17 ` [PULL 2/8] iotests: better heuristics to find I/O tests build/source dirs Kevin Wolf
2026-11-17 20:06   ` Richard Henderson
2026-11-17 20:50     ` Kevin Wolf
2026-11-17 17:17 ` Kevin Wolf [this message]
2026-11-17 17:17 ` [PULL 4/8] iotests: fix false positive on running-outside-venv warning Kevin Wolf
2026-11-17 17:17 ` [PULL 5/8] block/vhdx: Add alignment checks for region tables Kevin Wolf
2026-11-17 17:17 ` [PULL 6/8] block: read the old child length after draining in bdrv_replace_child_bs() Kevin Wolf
2026-11-17 17:17 ` [PULL 7/8] block: add bdrv_child_notify_resize() to notify a single parent Kevin Wolf
2026-11-17 17:17 ` [PULL 8/8] block: notify only the replaced child in bdrv_replace_child_bs() Kevin Wolf

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=20261117171758.237462-4-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.