Skip to contentSkip to conversation

hw/nvme: two fixes

PATCH In review Klaus Jensen 2 participants 4 messages Aug 8, 2023 – Aug 9, 2023

lore
Share & tools
lore
#0 lore raw

cover hw/nvme: two fixes

From: Klaus Jensen <[email protected]>

Fix two potential accesses to null pointers.

Klaus Jensen (2):
hw/nvme: fix null pointer access in directive receive hw/nvme: fix null pointer access in ruh update

 hw/nvme/ctrl.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/2 hw/nvme: fix null pointer access in directive receive

From: Klaus Jensen <[email protected]>

nvme_directive_receive() does not check if an endurance group has been configured (set) prior to testing if flexible data placement is enabled or not.

Fix this.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1815

Fixes 73064edfb864 ("hw/nvme: flexible data placement emulation")
---
 hw/nvme/ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/nvme/ctrl.c +1 -1
index d217ae91b506..e5b5c7034d2b 100644
@@ -6900,7 +6900,7 @@ static uint16_t nvme_directive_receive(NvmeCtrl *n, NvmeRequest *req)
     case NVME_DIRECTIVE_IDENTIFY:
         switch (doper) {
         case NVME_DIRECTIVE_RETURN_PARAMS:
-            if (ns->endgrp->fdp.enabled) {
+            if (ns->endgrp && ns->endgrp->fdp.enabled) {
                 id.supported |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
                 id.enabled |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
                 id.persistent |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/2 hw/nvme: fix null pointer access in ruh update

In reply to Klaus Jensen

From: Klaus Jensen <[email protected]>

The Reclaim Unit Update operation in I/O Management Receive does not verify the presence of a configured endurance group prior to accessing it.

Fix this.

Fixes 73064edfb864 ("hw/nvme: flexible data placement emulation")
---
 hw/nvme/ctrl.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/nvme/ctrl.c +7 -1
index e5b5c7034d2b..539d27355313 100644
@@ -4361,7 +4361,13 @@ static uint16_t nvme_io_mgmt_send_ruh_update(NvmeCtrl *n, NvmeRequest *req)
     uint32_t npid = (cdw10 >> 1) + 1;
     unsigned int i = 0;
     g_autofree uint16_t *pids = NULL;
-    uint32_t maxnpid = n->subsys->endgrp.fdp.nrg * n->subsys->endgrp.fdp.nruh;
+    uint32_t maxnpid;
+
+    if (!ns->endgrp || !ns->endgrp->fdp.enabled) {
+        return NVME_FDP_DISABLED | NVME_DNR;
+    }
+
+    maxnpid = n->subsys->endgrp.fdp.nrg * n->subsys->endgrp.fdp.nruh;
 
     if (unlikely(npid >= MIN(NVME_FDP_MAXPIDS, maxnpid))) {
         return NVME_INVALID_FIELD | NVME_DNR;
Signature · 1 line
2.41.0