Skip to contentSkip to conversation

hw/nvme: fix buffer overrun in nvme_changed_nslist (CVE-2021-3947)

PATCH In review Klaus Jensen 2 participants 2 messages Nov 17, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/nvme: fix buffer overrun in nvme_changed_nslist (CVE-2021-3947)

From: Klaus Jensen <[email protected]>

Fix missing offset verification.

Cc Philippe Mathieu-Daudé <[email protected]>
Fixes f432fdfa121 ("support changed namespace asynchronous event")

---

Note: Since its so easy to mess this fix up, the log pages code could probably use a refactor - there is a lot of duplicated code as well and it's easy to miss a check like this. However, defer that for 7.0.

 hw/nvme/ctrl.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/nvme/ctrl.c +5 -0
index 6a571d18cfae..5f573c417b3d 100644
@@ -4168,6 +4168,11 @@ static uint16_t nvme_changed_nslist(NvmeCtrl *n, uint8_t rae, uint32_t buf_len,
     int i = 0;
     uint32_t nsid;
 
+    if (off >= sizeof(nslist)) {
+        trace_pci_nvme_err_invalid_log_page_offset(off, sizeof(nslist));
+        return NVME_INVALID_FIELD | NVME_DNR;
+    }
+
     memset(nslist, 0x0, sizeof(nslist));
     trans_len = MIN(sizeof(nslist) - off, buf_len);
 
Signature · 1 line
2.34.0
Reviewed-by Tested-by Gaurav Kamathe on v1 1/1
#1 lore raw
Quoted 9 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

Fix missing offset verification.

Cc Philippe Mathieu-Daudé <[email protected]>
Fixes f432fdfa121 ("support changed namespace asynchronous event")
Quoted 26 lines

---

Note: Since its so easy to mess this fix up, the log pages code could probably use a refactor - there is a lot of duplicated code as well and it's easy to miss a check like this. However, defer that for 7.0.

 hw/nvme/ctrl.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/nvme/ctrl.c +5 -0
index 6a571d18cfae..5f573c417b3d 100644
@@ -4168,6 +4168,11 @@ static uint16_t nvme_changed_nslist(NvmeCtrl *n, uint8_t rae, uint32_t buf_len,
     int i = 0;
     uint32_t nsid;
 
+    if (off >= sizeof(nslist)) {
+        trace_pci_nvme_err_invalid_log_page_offset(off, sizeof(nslist));
+        return NVME_INVALID_FIELD | NVME_DNR;
+    }
+
     memset(nslist, 0x0, sizeof(nslist));
     trans_len = MIN(sizeof(nslist) - off, buf_len);