Commit 2a4384b4ef for qemu.org

commit 2a4384b4ef01ee3e2c9aeb96d7748307ff0f248b
Author: Thomas Huth <thuth@redhat.com>
Date:   Fri Nov 13 08:23:36 2026 +0100

    block/vhdx: Add alignment checks for region tables

    According to the VHDX specification:

     "The FileOffset and Length fields specify the 64-bit byte offset and 32-bit
      byte length of the object within the file. The values must be a multiple of
      1 MB, and FileOffset must be at least 1 MB."

    Thus let's add a sanity check to avoid that bad things could happen later.

    Cc: qemu-stable@nongnu.org
    Buglink: https://gitlab.com/qemu-project/qemu/-/work_items/3762
    Reported-by: Daniel Wade <danjwade95@gmail.com>
    Signed-off-by: Thomas Huth <thuth@redhat.com>
    Message-ID: <20261113072336.46309-1-thuth@redhat.com>
    Reviewed-by: Kevin Wolf <kwolf@redhat.com>
    Signed-off-by: Kevin Wolf <kwolf@redhat.com>

diff --git a/block/vhdx.c b/block/vhdx.c
index 8013a90a1a..e71973cf52 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -566,6 +566,16 @@ vhdx_open_region_tables(BlockDriverState *bs, BDRVVHDXState *s)

         vhdx_region_entry_le_import(&rt_entry);

+        /*
+         * According to the VHDX spec, offset and length must be multiple
+         * of 1 MiB and offset must be at least 1 MiB.
+         */
+        if (!QEMU_IS_ALIGNED(rt_entry.file_offset, MiB) ||
+            !QEMU_IS_ALIGNED(rt_entry.length, MiB) || !rt_entry.file_offset) {
+            ret = -EINVAL;
+            goto fail;
+        }
+
         /* check for region overlap between these entries, and any
          * other memory regions in the file */
         ret = vhdx_region_check(s, rt_entry.file_offset, rt_entry.length);