* [PATCH] hw/nvme: fix zone descriptor extension allocation overflow
@ 2026-11-17 7:53 Klaus Jensen
2026-11-18 12:07 ` Jesper Wendel Devantier
0 siblings, 1 reply; 2+ messages in thread
From: Klaus Jensen @ 2026-11-17 7:53 UTC (permalink / raw)
To: qemu-devel, Keith Busch, Klaus Jensen, Jesper Devantier,
qemu-block
Cc: Klaus Jensen, qemu-stable
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
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)
---
base-commit: 97c88c61d45dee6e1f9bc160a338048189846d28
change-id: 20261117-fix-4730-fe5e4d60673a
Best regards,
--
Klaus Jensen <k.jensen@samsung.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] hw/nvme: fix zone descriptor extension allocation overflow
2026-11-17 7:53 [PATCH] hw/nvme: fix zone descriptor extension allocation overflow Klaus Jensen
@ 2026-11-18 12:07 ` Jesper Wendel Devantier
0 siblings, 0 replies; 2+ messages in thread
From: Jesper Wendel Devantier @ 2026-11-18 12:07 UTC (permalink / raw)
To: Klaus Jensen
Cc: qemu-devel, Keith Busch, qemu-block, Klaus Jensen, qemu-stable
On Tue, 17 Nov 2026 08:53:11 +0100, Klaus Jensen <its@irrelevant.dk> wrote:
> 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
> 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)
>
> ---
> base-commit: 97c88c61d45dee6e1f9bc160a338048189846d28
> change-id: 20261117-fix-4730-fe5e4d60673a
>
> Best regards,
> --
> Klaus Jensen <k.jensen@samsung.com>
>
>
>
Reviewed-by: Jesper Wendel Devantier <foss@defmacro.it>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 12:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 7:53 [PATCH] hw/nvme: fix zone descriptor extension allocation overflow Klaus Jensen
2026-11-18 12:07 ` Jesper Wendel Devantier
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.