Skip to contentSkip to conversation

hw/pvrdma: Protect against buggy or malicious guest driver

PATCH Superseded Yuval Shaia 3 participants 3 messages Mar 21, 2022 – Mar 29, 2022

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/pvrdma: Protect against buggy or malicious guest driver

Guest driver might execute HW commands when shared buffers are not yet allocated.
This might happen on purpose (malicious guest) or because some other guest/host address mapping.
We need to protect againts such case.

---
 hw/rdma/vmw/pvrdma_cmd.c  | 6 ++++++
 hw/rdma/vmw/pvrdma_main.c | 9 +++++----
 2 files changed, 11 insertions(+), 4 deletions(-)
hw/rdma/vmw/pvrdma_cmd.c +6 -0
index da7ddfa548..89db963c46 100644
@@ -796,6 +796,12 @@ int pvrdma_exec_cmd(PVRDMADev *dev)
 
     dsr_info = &dev->dsr_info;
 
+    if (!dsr_info->dsr) {
+            /* Buggy or malicious guest driver */
+            rdma_error_report("Exec command without dsr, req or rsp buffers");
+            goto out;
+    }
+
     if (dsr_info->req->hdr.cmd >= sizeof(cmd_handlers) /
                       sizeof(struct cmd_handler)) {
         rdma_error_report("Unsupported command");
hw/rdma/vmw/pvrdma_main.c +5 -4
index 91206dbb8e..aae382af59 100644
@@ -159,13 +159,13 @@ static void free_dsr(PVRDMADev *dev)
     free_dev_ring(pci_dev, &dev->dsr_info.cq, dev->dsr_info.cq_ring_state);
 
     rdma_pci_dma_unmap(pci_dev, dev->dsr_info.req,
-                         sizeof(union pvrdma_cmd_req));
+                       sizeof(union pvrdma_cmd_req));
 
     rdma_pci_dma_unmap(pci_dev, dev->dsr_info.rsp,
-                         sizeof(union pvrdma_cmd_resp));
+                       sizeof(union pvrdma_cmd_resp));
 
     rdma_pci_dma_unmap(pci_dev, dev->dsr_info.dsr,
-                         sizeof(struct pvrdma_device_shared_region));
+                       sizeof(struct pvrdma_device_shared_region));
 
     dev->dsr_info.dsr = NULL;
 }
@@ -249,7 +249,8 @@ static void init_dsr_dev_caps(PVRDMADev *dev)
 {
     struct pvrdma_device_shared_region *dsr;
 
-    if (dev->dsr_info.dsr == NULL) {
+    if (!dev->dsr_info.dsr) {
+        /* Buggy or malicious guest driver */
         rdma_error_report("Can't initialized DSR");
         return;
     }
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Yuval

Quoted 40 lines · Yuval Shaia

Guest driver might execute HW commands when shared buffers are not yet allocated.
This might happen on purpose (malicious guest) or because some other guest/host address mapping.
We need to protect againts such case.

---
 hw/rdma/vmw/pvrdma_cmd.c  | 6 ++++++
 hw/rdma/vmw/pvrdma_main.c | 9 +++++----
 2 files changed, 11 insertions(+), 4 deletions(-)
hw/rdma/vmw/pvrdma_cmd.c +6 -0
index da7ddfa548..89db963c46 100644
@@ -796,6 +796,12 @@ int pvrdma_exec_cmd(PVRDMADev *dev)
 
     dsr_info = &dev->dsr_info;
 
+    if (!dsr_info->dsr) {
+            /* Buggy or malicious guest driver */
+            rdma_error_report("Exec command without dsr, req or rsp buffers");
+            goto out;
+    }
+
     if (dsr_info->req->hdr.cmd >= sizeof(cmd_handlers) /
                       sizeof(struct cmd_handler)) {
         rdma_error_report("Unsupported command");
hw/rdma/vmw/pvrdma_main.c +0 -1
index 91206dbb8e..aae382af59 100644
@@ -159,13 +159,13 @@ static void free_dsr(PVRDMADev *dev)
     free_dev_ring(pci_dev, &dev->dsr_info.cq, dev->dsr_info.cq_ring_state);
 
     rdma_pci_dma_unmap(pci_dev, dev->dsr_info.req,
-                         sizeof(union pvrdma_cmd_req));

hw/rdma/vmw/pvrdma_main.c static void free_dsr(PVRDMADev *dev) · line 169

Quoted 10 lines
hw/rdma/vmw/pvrdma_main.c +3 -2
+                       sizeof(union pvrdma_cmd_req));
 
     rdma_pci_dma_unmap(pci_dev, dev->dsr_info.rsp,
-                         sizeof(union pvrdma_cmd_resp));
+                       sizeof(union pvrdma_cmd_resp));
 
     rdma_pci_dma_unmap(pci_dev, dev->dsr_info.dsr,
-                         sizeof(struct pvrdma_device_shared_region));
+                       sizeof(struct pvrdma_device_shared_region));
 

Nit: the above changes are not related to the patch, maybe drop them?

Thanks,
Marcel

Quoted 15 lines
hw/rdma/vmw/pvrdma_main.c +2 -2
     dev->dsr_info.dsr = NULL;
 }
@@ -249,7 +249,8 @@ static void init_dsr_dev_caps(PVRDMADev *dev)
 {
     struct pvrdma_device_shared_region *dsr;
 
-    if (dev->dsr_info.dsr == NULL) {
+    if (!dev->dsr_info.dsr) {
+        /* Buggy or malicious guest driver */
         rdma_error_report("Can't initialized DSR");
         return;
     }
--

2.20.1

#2 lore raw
Quoted 10 lines · Marcel Apfelbaum

Hi Yuval

Quoted 7 lines · Yuval Shaia

Guest driver might execute HW commands when shared buffers are not yet allocated.
This might happen on purpose (malicious guest) or because some other guest/host address mapping.
We need to protect againts such case.

Fixes CVE-2022-1050
Quoted 39 lines
Quoted 39 lines
---
  hw/rdma/vmw/pvrdma_cmd.c  | 6 ++++++
  hw/rdma/vmw/pvrdma_main.c | 9 +++++----
  2 files changed, 11 insertions(+), 4 deletions(-)
hw/rdma/vmw/pvrdma_cmd.c +6 -0
index da7ddfa548..89db963c46 100644
@@ -796,6 +796,12 @@ int pvrdma_exec_cmd(PVRDMADev *dev)
 
      dsr_info = &dev->dsr_info;
 
+    if (!dsr_info->dsr) {
+            /* Buggy or malicious guest driver */
+            rdma_error_report("Exec command without dsr, req or rsp buffers");
+            goto out;
+    }
+
      if (dsr_info->req->hdr.cmd >= sizeof(cmd_handlers) /
                        sizeof(struct cmd_handler)) {
          rdma_error_report("Unsupported command");
hw/rdma/vmw/pvrdma_main.c +2 -2
index 91206dbb8e..aae382af59 100644
@@ -159,13 +159,13 @@ static void free_dsr(PVRDMADev *dev)
      free_dev_ring(pci_dev, &dev->dsr_info.cq, dev->dsr_info.cq_ring_state);
 
      rdma_pci_dma_unmap(pci_dev, dev->dsr_info.req,
-                         sizeof(union pvrdma_cmd_req));
+                       sizeof(union pvrdma_cmd_req));
 
      rdma_pci_dma_unmap(pci_dev, dev->dsr_info.rsp,
-                         sizeof(union pvrdma_cmd_resp));
+                       sizeof(union pvrdma_cmd_resp));
 
Quoted 6 lines

hw/rdma/vmw/pvrdma_main.c static void free_dsr(PVRDMADev *dev) · line 169

Quoted 4 lines
hw/rdma/vmw/pvrdma_main.c +1 -1
      rdma_pci_dma_unmap(pci_dev, dev->dsr_info.dsr,
-                         sizeof(struct pvrdma_device_shared_region));
+                       sizeof(struct pvrdma_device_shared_region));
 

Nit: the above changes are not related to the patch, maybe drop them?

Yes please.

Quoted 22 lines

Thanks,
Marcel

Quoted 15 lines
hw/rdma/vmw/pvrdma_main.c +2 -2
      dev->dsr_info.dsr = NULL;
  }
@@ -249,7 +249,8 @@ static void init_dsr_dev_caps(PVRDMADev *dev)
  {
      struct pvrdma_device_shared_region *dsr;
 
-    if (dev->dsr_info.dsr == NULL) {
+    if (!dev->dsr_info.dsr) {
+        /* Buggy or malicious guest driver */
          rdma_error_report("Can't initialized DSR");
          return;
      }
--

2.20.1