Commit d31a68f013 for qemu.org

commit d31a68f013bf901c29c55d34d756c5fbbdc02657
Author: Klaus Jensen <k.jensen@samsung.com>
Date:   Wed Nov 18 13:45:35 2026 +0100

    hw/nvme: bound zrwa flush by the write area and zone write boundary

    nvme_zone_mgmt_send_zrwa_flush incorrectly accepts a flush up to and
    including one LBA past the zone random write area. Fix the comparison.

    Additionally, there is no check that the last LBA to be flushed falls
    within the zone boundary (i.e., the *capacity* of the zone). That is, if
    a zone has a small capacity than size, the write pointer can be pushed
    past it. Fix with a check on the zone write boundary.

    Cc: qemu-stable@nongnu.org
    Link: https://gitlab.com/qemu-project/qemu/-/work_items/4520
    Fixes: e321b4cdc2dd ("hw/nvme: add support for zoned random write area")
    Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>
    Signed-off-by: Klaus Jensen <k.jensen@samsung.com>

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 16860ccd95..35e2c57851 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -4279,7 +4279,8 @@ static uint16_t nvme_zone_mgmt_send_zrwa_flush(NvmeCtrl *n, NvmeZone *zone,
         return NVME_INVALID_FIELD | NVME_DNR;
     }

-    if (elba < wp || elba > wp + ns->zns.zrwas) {
+    if (elba < wp || elba >= wp + ns->zns.zrwas ||
+        elba >= nvme_zone_wr_boundary(zone)) {
         return NVME_ZONE_BOUNDARY_ERROR | NVME_DNR;
     }