[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v8 03/13] vpci: restrict unhandled read/write operations for guests


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Date: Thu, 20 Jul 2023 00:32:31 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Unt8egmRvwPUu0glZoccRX4BB5aszaqAV25MRw9Jz1w=; b=RFFhrRn6a0MspLZ82RZVpuMhd3S+pTc/hUCtnOqx3xLsMExRhWIcS7AekH6O/djArhQodEMx7GEs84A1EN8Z/sYQP0XmVjU2exzsoaZu2+alXB2DYboZ66kPFiKbeU+QgvxqhSDtFDlp749HF+mY1OBHNWeYhs/VdiiNAE5l+E1w+Ttz2hPluvn61J3ISVW76WOFSYXQmnaYvvoMRPbnbrogCg5eCPI908sgzEa8J62BQaG0YB4vpRvvGq43nqg0BO0GsTJRsBzNRh+XMB0AjGezTjKGOzIIaHPPycdhuKAvp/taEh9MqriuluwvZwSqZY/iZox/cbZhvcecagU/Yw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=geA3nPDtFETcaj7QB62wA2L8PvdYFtir95WHhhHCjM2J8p1+pIz7CEx4pAHjtCP2X1O1eXAyMevTYCAk2iA+05YMXCKfMKbDQK5gTExYv4+xw79J4Lx22UdlUx3cjy6AKUqzEQ+hC5ByBkLKAFSXv9OmmIE4PjnWsZL3ZE7Iwy0Dk1bpE1Td8X6o13pE8y3YCK7s6LsumslZhvwmXtN6HbKYz5eGSR+3t5IAY1XeZn2NjtisBj85dOGZbXIjMigYiNXfidY6BhNRvCKkaMImeD/iUCwiGxY4pNzRzByitZARRdo/2aSfxLLK4Ub5laqqfOdeidQRn69ma493hpPU8Q==
  • Cc: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Thu, 20 Jul 2023 00:32:50 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZuqGrmAJWEwjbUkyUjUzRXQkJ0A==
  • Thread-topic: [PATCH v8 03/13] vpci: restrict unhandled read/write operations for guests

From: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>

A guest would be able to read and write those registers which are not
emulated and have no respective vPCI handlers, so it will be possible
for it to access the hardware directly.
In order to prevent a guest from reads and writes from/to the unhandled
registers make sure only hardware domain can access the hardware directly
and restrict guests from doing so.

Suggested-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>

---
Since v6:
- do not use is_hwdom parameter for vpci_{read|write}_hw and use
  current->domain internally
- update commit message
New in v6
---
 xen/drivers/vpci/vpci.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
index f22cbf2112..a6d2cf8660 100644
--- a/xen/drivers/vpci/vpci.c
+++ b/xen/drivers/vpci/vpci.c
@@ -233,6 +233,10 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int 
reg,
 {
     uint32_t data;
 
+    /* Guest domains are not allowed to read real hardware. */
+    if ( !is_hardware_domain(current->domain) )
+        return ~(uint32_t)0;
+
     switch ( size )
     {
     case 4:
@@ -273,9 +277,13 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int 
reg,
     return data;
 }
 
-static void vpci_write_hw(pci_sbdf_t sbdf, unsigned int reg, unsigned int size,
-                          uint32_t data)
+static void vpci_write_hw(pci_sbdf_t sbdf, unsigned int reg,
+                          unsigned int size, uint32_t data)
 {
+    /* Guest domains are not allowed to write real hardware. */
+    if ( !is_hardware_domain(current->domain) )
+        return;
+
     switch ( size )
     {
     case 4:
-- 
2.41.0

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.