Skip to contentSkip to conversation

VMCI: Verify PPNs before sending to device

PATCH In review Jorgen Hansen 2 participants 3 messages Jan 11, 2019 – Jan 14, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 VMCI: Verify PPNs before sending to device

The current version of the VMCI device only supports 32 bit PPNs, so check whether we are truncating PPNs, and fail the operation if we do. One such check did exist, but was wrong. Another check was missing.

Testing through code modification: constructed PPN not representable by 32-bit and observed that failure was reported.

Fixes 1f166439917b ("VMCI: guest side driver implementation.")
Fixes 06164d2b72aa ("VMCI: queue pairs implementation.")
---
 drivers/misc/vmw_vmci/vmci_guest.c      | 10 +++++++---
 drivers/misc/vmw_vmci/vmci_queue_pair.c | 10 ++++------
 2 files changed, 11 insertions(+), 9 deletions(-)
drivers/misc/vmw_vmci/vmci_guest.c +7 -3
index dad5abee656e..02bb3866cf9e 100644
@@ -532,10 +532,14 @@ static int vmci_guest_probe_device(struct pci_dev *pdev,
 	if (capabilities & VMCI_CAPS_NOTIFICATIONS) {
 		unsigned long bitmap_ppn =
 			vmci_dev->notification_base >> PAGE_SHIFT;
-		if (!vmci_dbell_register_notification_bitmap(bitmap_ppn)) {
+		u32 bitmap_ppn32 = bitmap_ppn;
+
+		if ((sizeof(bitmap_ppn) > sizeof(bitmap_ppn32)
+		     && bitmap_ppn != bitmap_ppn32) ||
+		    !vmci_dbell_register_notification_bitmap(bitmap_ppn)) {
 			dev_warn(&pdev->dev,
-				 "VMCI device unable to register notification bitmap with PPN 0x%x\n",
-				 (u32) bitmap_ppn);
+				 "VMCI device unable to register notification bitmap with PPN 0x%lx\n",
+				 bitmap_ppn);
 			error = -ENXIO;
 			goto err_remove_vmci_dev_g;
 		}
drivers/misc/vmw_vmci/vmci_queue_pair.c +4 -6
index 264f4ed8eef2..1da4f6cb01b2 100644
@@ -465,9 +465,8 @@ static int qp_alloc_ppn_set(void *prod_q,
 	for (i = 0; i < num_produce_pages; i++) {
 		unsigned long pfn;
 
-		produce_ppns[i] =
-			produce_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
-		pfn = produce_ppns[i];
+		pfn = produce_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
+		produce_ppns[i] = pfn;
 
 		/* Fail allocation if PFN isn't supported by hypervisor. */
 		if (sizeof(pfn) > sizeof(*produce_ppns)
@@ -478,9 +477,8 @@ static int qp_alloc_ppn_set(void *prod_q,
 	for (i = 0; i < num_consume_pages; i++) {
 		unsigned long pfn;
 
-		consume_ppns[i] =
-			consume_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
-		pfn = consume_ppns[i];
+		pfn = consume_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
+		consume_ppns[i] = pfn;
 
 		/* Fail allocation if PFN isn't supported by hypervisor. */
 		if (sizeof(pfn) > sizeof(*consume_ppns)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 82 lines

-----Original Message-----
From: Jorgen Hansen [mailto:[email protected]]
Sent: Friday, January 11, 2019 8:58 AM
To: [email protected]; [email protected]
Cc: [email protected]; Pv-drivers <[email protected]>; Jorgen S. Hansen <[email protected]>
Subject: [PATCH] VMCI: Verify PPNs before sending to device

The current version of the VMCI device only supports 32 bit PPNs, so check whether we are truncating PPNs, and fail the operation if we do. One such check did exist, but was wrong. Another check was missing.

Testing through code modification: constructed PPN not representable by 32-bit and observed that failure was reported.

Fixes 1f166439917b ("VMCI: guest side driver implementation.")
Fixes 06164d2b72aa ("VMCI: queue pairs implementation.")
---
 drivers/misc/vmw_vmci/vmci_guest.c      | 10 +++++++---
 drivers/misc/vmw_vmci/vmci_queue_pair.c | 10 ++++------
 2 files changed, 11 insertions(+), 9 deletions(-)
drivers/misc/vmw_vmci/vmci_guest.c +7 -3
index dad5abee656e..02bb3866cf9e 100644
@@ -532,10 +532,14 @@ static int vmci_guest_probe_device(struct pci_dev
 *pdev,
 	if (capabilities & VMCI_CAPS_NOTIFICATIONS) {
 		unsigned long bitmap_ppn =
 			vmci_dev->notification_base >> PAGE_SHIFT;
-		if (!vmci_dbell_register_notification_bitmap(bitmap_ppn)) {
+		u32 bitmap_ppn32 = bitmap_ppn;
+
+		if ((sizeof(bitmap_ppn) > sizeof(bitmap_ppn32)
+		     && bitmap_ppn != bitmap_ppn32) ||
+		    !vmci_dbell_register_notification_bitmap(bitmap_ppn)) {
 			dev_warn(&pdev->dev,
-				 "VMCI device unable to register notification
 bitmap with PPN 0x%x\n",
-				 (u32) bitmap_ppn);
+				 "VMCI device unable to register notification
 bitmap with PPN 0x%lx\n",
+				 bitmap_ppn);
drivers/misc/vmw_vmci/vmci_guest.c +0 -0
 			error = -ENXIO;
 			goto err_remove_vmci_dev_g;
 		}
drivers/misc/vmw_vmci/vmci_queue_pair.c +2 -3
index 264f4ed8eef2..1da4f6cb01b2 100644
@@ -465,9 +465,8 @@ static int qp_alloc_ppn_set(void *prod_q,
 	for (i = 0; i < num_produce_pages; i++) {
 		unsigned long pfn;
 
-		produce_ppns[i] =
-			produce_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
-		pfn = produce_ppns[i];
+		pfn = produce_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
+		produce_ppns[i] = pfn;
 
 		/* Fail allocation if PFN isn't supported by hypervisor. */
 		if (sizeof(pfn) > sizeof(*produce_ppns) @@ -478,9 +477,8

@@ static int qp_alloc_ppn_set(void *prod_q,

drivers/misc/vmw_vmci/vmci_queue_pair.c +2 -4
 	for (i = 0; i < num_consume_pages; i++) {
 		unsigned long pfn;
 
-		consume_ppns[i] =
-			consume_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
-		pfn = consume_ppns[i];
+		pfn = consume_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
+		consume_ppns[i] = pfn;
 
 		/* Fail allocation if PFN isn't supported by hypervisor. */
 		if (sizeof(pfn) > sizeof(*consume_ppns)
--
Quoted 1 line

2.17.1

Please ignore this patch.

Thomas Hellstrom reminded me that the dma mask for the device should be able to take care of this and since the VMCI device uses the default DMA mask, the device should only get 32-bit addresses. So we should Just remove the (wrong) overflow checks in vmci_queue_pair.c

Another patch supporting larger addresses will be sent out later.

Thanks,
Jorgen

#2 lore raw
In reply to Jorgen Hansen
Quoted 82 lines

-----Original Message-----
From: Jorgen Hansen [mailto:[email protected]]
Sent: Friday, January 11, 2019 8:58 AM
To: [email protected]; [email protected]
Cc: [email protected]; Pv-drivers <[email protected]>; Jorgen S. Hansen <[email protected]>
Subject: [PATCH] VMCI: Verify PPNs before sending to device

The current version of the VMCI device only supports 32 bit PPNs, so check whether we are truncating PPNs, and fail the operation if we do. One such check did exist, but was wrong. Another check was missing.

Testing through code modification: constructed PPN not representable by 32-bit and observed that failure was reported.

Fixes 1f166439917b ("VMCI: guest side driver implementation.")
Fixes 06164d2b72aa ("VMCI: queue pairs implementation.")
---
 drivers/misc/vmw_vmci/vmci_guest.c      | 10 +++++++---
 drivers/misc/vmw_vmci/vmci_queue_pair.c | 10 ++++------
 2 files changed, 11 insertions(+), 9 deletions(-)
drivers/misc/vmw_vmci/vmci_guest.c +7 -3
index dad5abee656e..02bb3866cf9e 100644
@@ -532,10 +532,14 @@ static int vmci_guest_probe_device(struct pci_dev
 *pdev,
 	if (capabilities & VMCI_CAPS_NOTIFICATIONS) {
 		unsigned long bitmap_ppn =
 			vmci_dev->notification_base >> PAGE_SHIFT;
-		if (!vmci_dbell_register_notification_bitmap(bitmap_ppn)) {
+		u32 bitmap_ppn32 = bitmap_ppn;
+
+		if ((sizeof(bitmap_ppn) > sizeof(bitmap_ppn32)
+		     && bitmap_ppn != bitmap_ppn32) ||
+		    !vmci_dbell_register_notification_bitmap(bitmap_ppn)) {
 			dev_warn(&pdev->dev,
-				 "VMCI device unable to register notification
 bitmap with PPN 0x%x\n",
-				 (u32) bitmap_ppn);
+				 "VMCI device unable to register notification
 bitmap with PPN 0x%lx\n",
+				 bitmap_ppn);
drivers/misc/vmw_vmci/vmci_guest.c +0 -0
 			error = -ENXIO;
 			goto err_remove_vmci_dev_g;
 		}
drivers/misc/vmw_vmci/vmci_queue_pair.c +2 -3
index 264f4ed8eef2..1da4f6cb01b2 100644
@@ -465,9 +465,8 @@ static int qp_alloc_ppn_set(void *prod_q,
 	for (i = 0; i < num_produce_pages; i++) {
 		unsigned long pfn;
 
-		produce_ppns[i] =
-			produce_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
-		pfn = produce_ppns[i];
+		pfn = produce_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
+		produce_ppns[i] = pfn;
 
 		/* Fail allocation if PFN isn't supported by hypervisor. */
 		if (sizeof(pfn) > sizeof(*produce_ppns) @@ -478,9 +477,8

@@ static int qp_alloc_ppn_set(void *prod_q,

drivers/misc/vmw_vmci/vmci_queue_pair.c +2 -4
 	for (i = 0; i < num_consume_pages; i++) {
 		unsigned long pfn;
 
-		consume_ppns[i] =
-			consume_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
-		pfn = consume_ppns[i];
+		pfn = consume_q->kernel_if->u.g.pas[i] >> PAGE_SHIFT;
+		consume_ppns[i] = pfn;
 
 		/* Fail allocation if PFN isn't supported by hypervisor. */
 		if (sizeof(pfn) > sizeof(*consume_ppns)
--
Quoted 1 line

2.17.1

Please ignore this patch.

Thomas Hellstrom reminded me that the dma mask for the device should be able to take care of this and since the VMCI device uses the default DMA mask, the device should only get 32-bit addresses. So we should Just remove the (wrong) overflow checks in vmci_queue_pair.c

Another patch supporting larger addresses will be sent out later.

Thanks,
Jorgen