From: Klaus Jensen <its@irrelevant.dk>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Klaus Jensen <k.jensen@samsung.com>,
qemu-stable@nongnu.org,
Jesper Wendel Devantier <foss@defmacro.it>,
Keith Busch <kbusch@kernel.org>, Klaus Jensen <its@irrelevant.dk>,
qemu-block@nongnu.org
Subject: [PULL 2/5] hw/nvme: fix zone descriptor extension allocation overflow
Date: Fri, 20 Nov 2026 13:29:46 +0100 [thread overview]
Message-ID: <20261120122949.1044-3-its@irrelevant.dk> (raw)
In-Reply-To: <20261120122949.1044-1-its@irrelevant.dk>
From: Klaus Jensen <k.jensen@samsung.com>
nvme_ns_zoned_init_state sizes the zone descriptor extension array
with 32-bit arithmetic. A large enough zone extension size and number of
zones will wrap, causing either null pointer deref on Set Zone
Descriptor Extension or an out-of-bounds write.
nvme_get_zd_extension has the same problem.
Fix the initialization by using g_malloc0_n and compute the per-zone
offset using 64-bit arithmetic.
Cc: qemu-stable@nongnu.org
Fixes: 1a9290ade33a ("hw/block/nvme: Support Zone Descriptor Extensions")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4730
Reported-by: Karl Mehltretter
Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
hw/nvme/ns.c | 4 ++--
hw/nvme/nvme.h | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c
index 37d45bb4d533..b18fcab43b44 100644
--- a/hw/nvme/ns.c
+++ b/hw/nvme/ns.c
@@ -314,8 +314,8 @@ static void nvme_ns_zoned_init_state(NvmeNamespace *ns)
ns->zone_array = g_new0(NvmeZone, ns->num_zones);
if (ns->params.zd_extension_size) {
- ns->zd_extensions = g_malloc0(ns->params.zd_extension_size *
- ns->num_zones);
+ ns->zd_extensions = g_malloc0_n(ns->num_zones,
+ ns->params.zd_extension_size);
}
QTAILQ_INIT(&ns->exp_open_zones);
diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h
index a4b2c01a2cc4..1bfe85c10de0 100644
--- a/hw/nvme/nvme.h
+++ b/hw/nvme/nvme.h
@@ -363,7 +363,8 @@ static inline bool nvme_wp_is_valid(NvmeZone *zone)
static inline uint8_t *nvme_get_zd_extension(NvmeNamespace *ns,
uint32_t zone_idx)
{
- return &ns->zd_extensions[zone_idx * ns->params.zd_extension_size];
+ return ns->zd_extensions + (uint64_t)zone_idx *
+ ns->params.zd_extension_size;
}
static inline void nvme_aor_inc_open(NvmeNamespace *ns)
--
2.53.0
next prev parent reply other threads:[~2026-11-20 12:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 12:29 [PULL 0/5] hw/nvme fixes Klaus Jensen
2026-11-20 12:29 ` [PULL 1/5] hw/nvme: report data transfer error on failed dma Klaus Jensen
2026-11-20 12:29 ` Klaus Jensen [this message]
2026-11-20 12:29 ` [PULL 3/5] hw/nvme: fix open zone zrwa allocation Klaus Jensen
2026-11-20 12:29 ` [PULL 4/5] hw/nvme: bound zrwa flush by the write area and zone write boundary Klaus Jensen
2026-11-20 12:29 ` [PULL 5/5] hw/nvme: advance zone write pointer only once the write is committed Klaus Jensen
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=20261120122949.1044-3-its@irrelevant.dk \
--to=its@irrelevant.dk \
--cc=foss@defmacro.it \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.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.