From: Jesper Wendel Devantier <foss@defmacro.it>
To: Klaus Jensen <its@irrelevant.dk>
Cc: qemu-devel@nongnu.org, Keith Busch <kbusch@kernel.org>,
qemu-block@nongnu.org, Klaus Jensen <k.jensen@samsung.com>,
qemu-stable@nongnu.org
Subject: Re: [PATCH] hw/nvme: fix zone descriptor extension allocation overflow
Date: Wed, 18 Nov 2026 12:07:08 +0000 [thread overview]
Message-ID: <20261118130708.0-foss@defmacro.it> (raw)
In-Reply-To: <20261117-fix-4730-v1-1-1a3d813ed0f0@samsung.com>
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>
prev parent reply other threads:[~2026-11-18 12:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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=20261118130708.0-foss@defmacro.it \
--to=foss@defmacro.it \
--cc=its@irrelevant.dk \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.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.