Skip to contentSkip to conversation

PVRDMA queue

GIT PULL Marcel Apfelbaum 2 participants 6 messages Jul 4, 2021

lore
Share & tools
lore
#0 lore raw

The following changes since commit 9c2647f75004c4f7d64c9c0ec55f8c6f0739a8b1:

Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2021-07-02 11:46:32 +0100)

are available in the Git repository at:

https://github.com/marcel-apf/qemu tags/pvrdma-04-07-2021

for you to fetch changes up to f6287078c2e41cd8de424682cc86c2afccbf3797:

pvrdma: Fix the ring init error flow (CVE-2021-3608) (2021-07-04 11:14:02 +0300)

----------------------------------------------------------------
PVRDMA queue

Several CVE fixes for the PVRDMA device.

----------------------------------------------------------------
Marcel Apfelbaum (3):
hw/rdma: Fix possible mremap overflow in the pvrdma device

    (CVE-2021-3582)

pvrdma: Ensure correct input on ring init (CVE-2021-3607)
pvrdma: Fix the ring init error flow (CVE-2021-3608)

 hw/rdma/vmw/pvrdma_cmd.c      | 6 ++++++
 hw/rdma/vmw/pvrdma_dev_ring.c | 2 +-
 hw/rdma/vmw/pvrdma_main.c     | 5 +++++
 3 files changed, 12 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.2
#1 lore raw

[PULL 3/3] pvrdma: Fix the ring init error flow (CVE-2021-3608)

Do not unmap uninitialized dma addresses.

Message-Id: <[email protected]>

---
 hw/rdma/vmw/pvrdma_dev_ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/rdma/vmw/pvrdma_dev_ring.c +1 -1
index 074ac59b84..42130667a7 100644
@@ -41,7 +41,7 @@ int pvrdma_ring_init(PvrdmaRing *ring, const char *name, PCIDevice *dev,
     qatomic_set(&ring->ring_state->cons_head, 0);
     */
     ring->npages = npages;
-    ring->pages = g_malloc(npages * sizeof(void *));
+    ring->pages = g_malloc0(npages * sizeof(void *));
 
     for (i = 0; i < npages; i++) {
         if (!tbl[i]) {
Signature · 1 line
2.17.2
#2 lore raw

[PULL 2/3] pvrdma: Ensure correct input on ring init (CVE-2021-3607)

In reply to Marcel Apfelbaum

Check the guest passed a non zero page count
for pvrdma device ring buffers.

Message-Id: <[email protected]>

---
 hw/rdma/vmw/pvrdma_main.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/rdma/vmw/pvrdma_main.c +5 -0
index 84ae8024fc..7c0c3551a8 100644
@@ -92,6 +92,11 @@ static int init_dev_ring(PvrdmaRing *ring, PvrdmaRingState **ring_state,
     uint64_t *dir, *tbl;
     int rc = 0;
 
+    if (!num_pages) {
+        rdma_error_report("Ring pages count must be strictly positive");
+        return -EINVAL;
+    }
+
     dir = rdma_pci_dma_map(pci_dev, dir_addr, TARGET_PAGE_SIZE);
     if (!dir) {
         rdma_error_report("Failed to map to page directory (ring %s)", name);
Signature · 1 line
2.17.2
#3 lore raw

[PULL 1/3] hw/rdma: Fix possible mremap overflow in the pvrdma device (CVE-2021-3582)

In reply to Marcel Apfelbaum

From: Marcel Apfelbaum <[email protected]>

Ensure mremap boundaries not trusting the guest kernel to pass the correct buffer length.

Message-Id: <[email protected]>

---
 hw/rdma/vmw/pvrdma_cmd.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/rdma/vmw/pvrdma_cmd.c +6 -0
index f59879e257..dadab4966b 100644
@@ -38,6 +38,12 @@ static void *pvrdma_map_to_pdir(PCIDevice *pdev, uint64_t pdir_dma,
         return NULL;
     }
 
+    length = ROUND_UP(length, TARGET_PAGE_SIZE);
+    if (nchunks * TARGET_PAGE_SIZE != length) {
+        rdma_error_report("Invalid nchunks/length (%u, %lu)", nchunks, length);
+        return NULL;
+    }
+
     dir = rdma_pci_dma_map(pdev, pdir_dma, TARGET_PAGE_SIZE);
     if (!dir) {
         rdma_error_report("Failed to map to page directory");
Signature · 1 line
2.17.2
#4 lore raw
In reply to Marcel Apfelbaum
Quoted 16 lines · Marcel Apfelbaum

The following changes since commit 9c2647f75004c4f7d64c9c0ec55f8c6f0739a8b1:

Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2021-07-02 11:46:32 +0100)

are available in the Git repository at:

https://github.com/marcel-apf/qemu tags/pvrdma-04-07-2021

for you to fetch changes up to f6287078c2e41cd8de424682cc86c2afccbf3797:

pvrdma: Fix the ring init error flow (CVE-2021-3608) (2021-07-04 11:14:02 +0300)

----------------------------------------------------------------
PVRDMA queue

Quoted 8 lines

Several CVE fixes for the PVRDMA device.

----------------------------------------------------------------
Marcel Apfelbaum (3):
hw/rdma: Fix possible mremap overflow in the pvrdma device

    (CVE-2021-3582)

pvrdma: Ensure correct input on ring init (CVE-2021-3607)
pvrdma: Fix the ring init error flow (CVE-2021-3608)

This fails to compile on 32-bit hosts:

In file included from ../hw/rdma/vmw/../rdma_backend_defs.h:23, from ../hw/rdma/vmw/../rdma_rm_defs.h:19,
from ../hw/rdma/vmw/../rdma_backend.h:22,
from ../hw/rdma/vmw/pvrdma_cmd.c:21:
../hw/rdma/vmw/pvrdma_cmd.c: In function 'pvrdma_map_to_pdir':
../hw/rdma/vmw/../rdma_utils.h:25:18: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t' {aka 'unsigned int'} [-Werror=format=]
error_report("%s: " fmt, "rdma", ## __VA_ARGS__)
^~~~~~
../hw/rdma/vmw/pvrdma_cmd.c:43:9: note: in expansion of macro 'rdma_error_report'
rdma_error_report("Invalid nchunks/length (%u, %lu)", nchunks, length); ^~~~~~~~~~~~~~~~~

You can see this in the gitlab CI jobs, eg:

https://gitlab.com/qemu-project/qemu/-/jobs/1398130500

thanks
-- PMM

#5 lore raw

Hi Peter,

Quoted 32 lines · Peter Maydell
Quoted 2 lines · Marcel Apfelbaum

The following changes since commit

9c2647f75004c4f7d64c9c0ec55f8c6f0739a8b1:

Quoted 2 lines

Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into

staging (2021-07-02 11:46:32 +0100)

Quoted 8 lines

are available in the Git repository at:

https://github.com/marcel-apf/qemu tags/pvrdma-04-07-2021

for you to fetch changes up to f6287078c2e41cd8de424682cc86c2afccbf3797:

pvrdma: Fix the ring init error flow (CVE-2021-3608) (2021-07-04

11:14:02 +0300)

Quoted 4 lines

----------------------------------------------------------------
PVRDMA queue

Quoted 8 lines

Several CVE fixes for the PVRDMA device.

----------------------------------------------------------------
Marcel Apfelbaum (3):
hw/rdma: Fix possible mremap overflow in the pvrdma device

    (CVE-2021-3582)

pvrdma: Ensure correct input on ring init (CVE-2021-3607)
pvrdma: Fix the ring init error flow (CVE-2021-3608)

This fails to compile on 32-bit hosts:

Quoted 16 lines

In file included from ../hw/rdma/vmw/../rdma_backend_defs.h:23, from ../hw/rdma/vmw/../rdma_rm_defs.h:19,
from ../hw/rdma/vmw/../rdma_backend.h:22,
from ../hw/rdma/vmw/pvrdma_cmd.c:21:
../hw/rdma/vmw/pvrdma_cmd.c: In function 'pvrdma_map_to_pdir':
../hw/rdma/vmw/../rdma_utils.h:25:18: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t' {aka 'unsigned int'} [-Werror=format=]
error_report("%s: " fmt, "rdma", ## __VA_ARGS__)
^~~~~~
../hw/rdma/vmw/pvrdma_cmd.c:43:9: note: in expansion of macro 'rdma_error_report'
rdma_error_report("Invalid nchunks/length (%u, %lu)", nchunks, length); ^~~~~~~~~~~~~~~~~

I reproduced the issue, thank you.
I will fix and re-spin.

Thanks,
Marcel

Quoted 7 lines

You can see this in the gitlab CI jobs, eg:

https://gitlab.com/qemu-project/qemu/-/jobs/1398130500

thanks
-- PMM