Commit 7dcf2a7955 for qemu.org

commit 7dcf2a795503c3f4a5221a3bfe52164ab3d2dc47
Author: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Date:   Tue Nov 24 12:33:09 2026 +0100

    hw/block/pflash_cfi01: Reject out-of-range blk_offset on load

    A migration stream can set blk_offset beyond the flash storage.
    The write-confirm path would then write past the end of it.
    Check that the pending write block fits in the storage in
    pflash_post_load() and fail the load.

    Cc: qemu-stable@nongnu.org
    Reported-by: phudd6 & kietvha1 from Viettel Cyber Security
    Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4388
    Fixes: 284a7ee2e290 ("hw/pflash: implement update buffer for block writes")
    Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
    Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
    Message-ID: <20261124185556.81132-4-philmd@oss.qualcomm.com>

diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 72c544dee8..7975d35789 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -1028,6 +1028,13 @@ static void postload_update_cb(void *opaque, bool running, RunState state)
 static int pflash_post_load(void *opaque, int version_id)
 {
     PFlashCFI01 *pfl = opaque;
+    uint64_t size = pfl->sector_len * pfl->nb_blocs;
+
+    if (pfl->blk_offset != -1
+        && (pfl->blk_offset >= size
+            || size - pfl->blk_offset < pfl->writeblock_size)) {
+        return -EINVAL;
+    }

     /*
      * ROMD mode is not in the VMState; derive it from the migrated