Skip to contentSkip to conversation

hw/nvme: more fixes

GIT PULL Applied Klaus Jensen 4 participants 7 messages Aug 9, 2023 – Aug 24, 2023

lore
Share & tools
lore
#0 lore raw

From: Klaus Jensen <[email protected]>

Hi,

The following changes since commit a8fc5165aab02f328ccd148aafec1e59fd1426eb:

Merge tag 'nvme-next-pull-request' of https://gitlab.com/birkelund/qemu into staging (2023-08-08 16:39:20 -0700)

are available in the Git repository at:

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

for you to fetch changes up to 3439ba9c5da943d96f7a3c86e0a7eb2ff48de41c:

hw/nvme: fix null pointer access in ruh update (2023-08-09 15:32:32 +0200)

----------------------------------------------------------------
hw/nvme: fixes
-----BEGIN PGP SIGNATURE-----

iQEzBAABCgAdFiEEUigzqnXi3OaiR2bATeGvMW1PDekFAmTTlmcACgkQTeGvMW1P DemjjggAnhEvaJ4fgS9rsvtxCwtzLNc405xMpNxh6rPaxa+sL3RXPIrW6vWG13+W VcHw8DI8EV4DzAFP919ZmTUq9/boRbgxx84bStlILUPHWol8+eGYVVfT75wFKszx d4Vi3nyPSGlrxieSrosARqimcUDtFtDGGAxjvEcKgzhkcU3a8DVYAOmx/hdlWJJQ KSk4h/E1pKItFbvv+w9yszsbToeZN65oIy7kQtFgx0JOULyWvEYSVygotw/AruF3 FPQ0nrJuZ115w3cJWDszznVJ6+3EcWbD3luQc3zE1FOPp76EkAOkcnPh1XbBJrE2 2BsCX/XnXcZT7BWSJbEzGXLsHjqsPg==
=Zy0+
-----END PGP SIGNATURE-----

----------------------------------------------------------------

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

[PULL 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

Re: [PULL 1/2] hw/nvme: fix null pointer access in directive receive

Quoted 22 lines · Klaus Jensen

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 +0 -0
index d217ae91b506..e5b5c7034d2b 100644

hw/nvme/ctrl.c static uint16_t nvme_directive_receive(NvmeCtrl *n, NvmeRequest *req) · line 6903

Quoted 5 lines
hw/nvme/ctrl.c +1 -1
@@ -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) {

This patch fixes CVE-2023-40360 ("QEMU: NVMe: NULL pointer dereference in nvme_directive_receive"). Were you aware of the security implications?

Too bad we hadn't committed "Fixes: CVE-2023-40360" as that would have helped downstream distributions cherry-picking security fixes ASAP, since our stable is not that frequent. At least the commit has the '[email protected]' tag.

Quoted 3 lines
hw/nvme/ctrl.c +0 -0
                  id.supported |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
                  id.enabled |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
                  id.persistent |= 1 << NVME_DIRECTIVE_DATA_PLACEMENT;
#3 lore raw

Re: [PULL 1/2] hw/nvme: fix null pointer access in directive receive

24.08.2023 15:44, Philippe Mathieu-Daudé wrote:
..

Quoted 7 lines

This patch fixes CVE-2023-40360 ("QEMU: NVMe: NULL pointer dereference in nvme_directive_receive"). Were you aware of the security implications?

Too bad we hadn't committed "Fixes: CVE-2023-40360" as that would have helped downstream distributions cherry-picking security fixes ASAP, since our stable is not that frequent.

https://tracker.debian.org/news/1455443/accepted-qemu-1804dfsg-2-source-into-unstable/

FWIW.

/mjt

#4 lore raw

Re: [PULL 1/2] hw/nvme: fix null pointer access in directive receive

In reply to Philippe Mathieu-Daudé
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Klaus Jensen

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(-)
Quoted 15 lines

hw/nvme/ctrl.c static uint16_t nvme_directive_receive(NvmeCtrl *n, NvmeRequest *req) · line 6903

Quoted 10 lines
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) {

This patch fixes CVE-2023-40360 ("QEMU: NVMe: NULL pointer dereference in nvme_directive_receive"). Were you aware of the security implications?

Yes, but I was not aware of the CVE being assigned at the time. I don't think it was?

But if what you are saying is that it was my responsibility as maintainer, to get that reported and assigned, then I apologies and will of course keep that in mind going forward!

#5 lore raw

[PULL 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
#6 lore raw
In reply to Klaus Jensen
Quoted 10 lines · Klaus Jensen

From: Klaus Jensen<[email protected]>

Hi,

The following changes since commit a8fc5165aab02f328ccd148aafec1e59fd1426eb:

   Merge tag 'nvme-next-pull-request' ofhttps://gitlab.com/birkelund/qemu  into staging (2023-08-08 16:39:20 -0700)

are available in the Git repository at:

Quoted 8 lines

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

for you to fetch changes up to 3439ba9c5da943d96f7a3c86e0a7eb2ff48de41c:

hw/nvme: fix null pointer access in ruh update (2023-08-09 15:32:32 +0200)

----------------------------------------------------------------
hw/nvme: fixes

Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/8.1 as appropriate.

r~