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

[PATCH v3 4/6] vpci: restrict unhandled read/write operations for guests


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Date: Tue, 14 Mar 2023 20:56:30 +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=Qbz49nUoSSct90DRuc5faIaPrcHn0RvfZzcOrFLGObg=; b=CO6abEhEfnvaEBoIH2hOrG9qsGF/TW+utOQvrpg4iBaeVRVFPvtBW/s2OX9J9EBdmeNEgWj8NC2EChtJPomFW8BSEoyT9egN5L/Ia7TtdCh6oUKlA2+l9qtRrwaaHRnEjquti8UJ7vkXVuq4uKq7/iL7vWqfbnrmdwVC0B+JGePbo1pICp/zTkOK83hHNJCDxbqITbwhYqfI29sxMKHcT1dRnvS11+ywK9hwQ+Ce4+eL+bTlaak0UBNyPF8ly1xpulEol4CYGVNeHVyW8TBAEMc8o/UmJHUqyKr3cbkrq4zef/G5FEp0yLM+ZNaUYeqEvbPLOtoq3BdtePri7rb8xw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IUk7j6c2OI3hgPhgnXSR0ytuaFnhExLrKuxPX0pyr6GLtxm//1XFkITbunUKMrghmNd/x0sMYMwg5vG/U2Ab5uV1KepFA9syX4KXNPHN6XOidsVDtoJlPUESNEIn2c7e60AIRlFuqwoXil59+xXotWKjiHfAi/ZS9P9pPZvgSqUe13Nv97Tnj0LkCIXVORB/7M1ab+psB0rvr3tzd3eP+ZT8kPLzh4NGcqzRBXnpkL5ucewt7eCbIqJKeGdfkm5I8X7FsAzWu4bZQiWp53c2KpoEm5e2rwGLGETI4gAyjzVK41ierqWIHvHAjPuwiXIRmN/ibtcjtDkDz43NsFOnHw==
  • Cc: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Tue, 14 Mar 2023 20:57:05 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZVrdz9O2stZ5aY0OrZqeMa7i3ng==
  • Thread-topic: [PATCH v3 4/6] 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>

---

v3:
 - No changes

Older comments from another series:

Since v6:
- do not use is_hwdom parameter for vpci_{read|write}_hw and use
  current->domain internally
- update commit message
New in v6
Moved into another series
---
 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 5232f9605b..199ff55672 100644
--- a/xen/drivers/vpci/vpci.c
+++ b/xen/drivers/vpci/vpci.c
@@ -220,6 +220,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:
@@ -260,9 +264,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.39.2

 


Rackspace

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