public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
* [PULL 0/2] hw/nvme fixes
@ 2026-03-26  8:23 Klaus Jensen
  2026-03-26  8:23 ` [PULL 1/2] hw/nvme: re-enable wzds bit in namespace dlfeat Klaus Jensen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Klaus Jensen @ 2026-03-26  8:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Klaus Jensen

From: Klaus Jensen <k.jensen@samsung.com>

Hi,

The following changes since commit 007b29752ed06e467d3c830bc2c17a8851f8bcd3:

  Merge tag 'for-upstream' of https://gitlab.com/kmwolf/qemu into staging (2026-03-25 09:16:13 +0000)

are available in the Git repository at:

  https://gitlab.com/birkelund/qemu.git tags/pull-nvme-20260326

for you to fetch changes up to eb5cc99aff17cbfdad16b18d3503c6f22233eeb5:

  hw/nvme: fix heap-buffer-overflow in nvme_abort (2026-03-26 09:14:35 +0100)

----------------------------------------------------------------
nvme queue

----------------------------------------------------------------
Kaixuan Li (1):
      hw/nvme: fix heap-buffer-overflow in nvme_abort

Pankaj Raghav (1):
      hw/nvme: re-enable wzds bit in namespace dlfeat

 hw/nvme/ctrl.c | 4 +++-
 hw/nvme/ns.c   | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PULL 1/2] hw/nvme: re-enable wzds bit in namespace dlfeat
  2026-03-26  8:23 [PULL 0/2] hw/nvme fixes Klaus Jensen
@ 2026-03-26  8:23 ` Klaus Jensen
  2026-03-26  8:23 ` [PULL 2/2] hw/nvme: fix heap-buffer-overflow in nvme_abort Klaus Jensen
  2026-03-26 14:58 ` [PULL 0/2] hw/nvme fixes Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Klaus Jensen @ 2026-03-26  8:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Pankaj Raghav, Klaus Jensen, Keith Busch,
	Klaus Jensen, Jesper Devantier, qemu-block

From: Pankaj Raghav <p.raghav@samsung.com>

dlfeat was changed from 0x9 to 0x1 when PI support was added.
It was removed because we can't rely on unmap and have to physically
clear it to get the checksums right but that doesnt mean that we do not
support the bit.

The spec says that if wzds is enabled, then the controller supports
deallocate (DEAC) on write zeroes. But DEAC bit in write zeroes command
is only a hint, the controller might choose to physically write zeroes in
those areas.

As we are sending write zeroes command with BDRV_REQ_MAY_UNMAP to the
underlying block device anyway (if the unmap operation is supported),
change the dlfeat value back to 0x9.

A new flag FALLOC_FL_WRITE_ZEROES has been introduced in linux for
fallocate which will use the wzds bit in dlfeat to quickly zeroout extents
using unmap operation whenever possible[1].

[1] https://lore.kernel.org/linux-fsdevel/20250619111806.3546162-1-yi.zhang@huaweicloud.com/

Fixes: 146f720c55 ("hw/block/nvme: end-to-end data protection")
Suggested-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c
index 38f86a17268f..b0106eaa5c8f 100644
--- a/hw/nvme/ns.c
+++ b/hw/nvme/ns.c
@@ -75,7 +75,7 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp)
     ns->csi = NVME_CSI_NVM;
     ns->status = 0x0;
 
-    ns->id_ns.dlfeat = 0x1;
+    ns->id_ns.dlfeat = 0x9;
 
     /* support DULBE and I/O optimization fields */
     id_ns->nsfeat |= (NVME_ID_NS_NSFEAT_DAE | NVME_ID_NS_NSFEAT_OPTPERF_ALL);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PULL 2/2] hw/nvme: fix heap-buffer-overflow in nvme_abort
  2026-03-26  8:23 [PULL 0/2] hw/nvme fixes Klaus Jensen
  2026-03-26  8:23 ` [PULL 1/2] hw/nvme: re-enable wzds bit in namespace dlfeat Klaus Jensen
@ 2026-03-26  8:23 ` Klaus Jensen
  2026-03-26 14:58 ` [PULL 0/2] hw/nvme fixes Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Klaus Jensen @ 2026-03-26  8:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Kaixuan Li, qemu-stable, Klaus Jensen, Keith Busch,
	Klaus Jensen, Jesper Devantier, qemu-block

From: Kaixuan Li <kaixuanli@ntu.edu.sg>

In nvme_abort(), the submission queue pointer is dereferenced from the
guest-controlled sqid before validating it with nvme_check_sqid():

    NvmeSQueue *sq = n->sq[sqid];

Since sqid is a 16-bit value (range 0-65535) taken directly from CDW10,
and n->sq[] is typically only max_ioqpairs+1 (65) entries, a malicious
guest can trigger an out-of-bounds heap read by sending an Abort command
with a large sqid.

ASan reports this as heap-buffer-overflow in nvme_abort.

Fix this by moving the array dereference to after the nvme_check_sqid()
bounds validation.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3348
Fixes: 75209c071a ("hw/nvme: actually implement abort")
Cc: qemu-stable@nongnu.org
Signed-off-by: Kaixuan Li <kaixuanli@ntu.edu.sg>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index cc4593cd427a..be6c7028cb58 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6111,7 +6111,7 @@ static uint16_t nvme_abort(NvmeCtrl *n, NvmeRequest *req)
 {
     uint16_t sqid = le32_to_cpu(req->cmd.cdw10) & 0xffff;
     uint16_t cid  = (le32_to_cpu(req->cmd.cdw10) >> 16) & 0xffff;
-    NvmeSQueue *sq = n->sq[sqid];
+    NvmeSQueue *sq;
     NvmeRequest *r, *next;
     int i;
 
@@ -6120,6 +6120,8 @@ static uint16_t nvme_abort(NvmeCtrl *n, NvmeRequest *req)
         return NVME_INVALID_FIELD | NVME_DNR;
     }
 
+    sq = n->sq[sqid];
+
     if (sqid == 0) {
         for (i = 0; i < n->outstanding_aers; i++) {
             NvmeRequest *re = n->aer_reqs[i];
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PULL 0/2] hw/nvme fixes
  2026-03-26  8:23 [PULL 0/2] hw/nvme fixes Klaus Jensen
  2026-03-26  8:23 ` [PULL 1/2] hw/nvme: re-enable wzds bit in namespace dlfeat Klaus Jensen
  2026-03-26  8:23 ` [PULL 2/2] hw/nvme: fix heap-buffer-overflow in nvme_abort Klaus Jensen
@ 2026-03-26 14:58 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2026-03-26 14:58 UTC (permalink / raw)
  To: Klaus Jensen; +Cc: qemu-devel, Klaus Jensen

On Thu, 26 Mar 2026 at 08:24, Klaus Jensen <its@irrelevant.dk> wrote:
>
> From: Klaus Jensen <k.jensen@samsung.com>
>
> Hi,
>
> The following changes since commit 007b29752ed06e467d3c830bc2c17a8851f8bcd3:
>
>   Merge tag 'for-upstream' of https://gitlab.com/kmwolf/qemu into staging (2026-03-25 09:16:13 +0000)
>
> are available in the Git repository at:
>
>   https://gitlab.com/birkelund/qemu.git tags/pull-nvme-20260326
>
> for you to fetch changes up to eb5cc99aff17cbfdad16b18d3503c6f22233eeb5:
>
>   hw/nvme: fix heap-buffer-overflow in nvme_abort (2026-03-26 09:14:35 +0100)
>
> ----------------------------------------------------------------
> nvme queue
>
> ----------------------------------------------------------------



Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/11.0
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-26 14:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26  8:23 [PULL 0/2] hw/nvme fixes Klaus Jensen
2026-03-26  8:23 ` [PULL 1/2] hw/nvme: re-enable wzds bit in namespace dlfeat Klaus Jensen
2026-03-26  8:23 ` [PULL 2/2] hw/nvme: fix heap-buffer-overflow in nvme_abort Klaus Jensen
2026-03-26 14:58 ` [PULL 0/2] hw/nvme fixes Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox