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

[PATCH v12 02/15] vpci: restrict unhandled read/write operations for guests


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Tue, 9 Jan 2024 16:51:17 -0500
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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=XB9PkT1l9t41YyMel2hU6TA5dMUGiXDLX5RX/vyOjHw=; b=VplYJ5P2tEeLBuOC12g+mizsei1kldMX4XbxIaYezuSKi45cJp6fGLlClfMZf03wY9tJ4crvD9Nhdj/pY08RooYp4e5lFDAzX+kxtplLB5WZZfZncLQnWF2UKRNiBwHVF+9vSylKcZ7r8n3b6GWu6fnESMQ9ymCmXzyGvJ29A0dgv0F/POcJPk8oBbl1Y3I2Ll2Q3i1yf5esdn3lOfc48ZSl8UVgJQeCSK5S36eCoCoOYCMURXQXtarfDlz8i0WI7Vq2ixhuAxTadCoAABVQahqhl/FIwzF7o5fIMUXHuLAbrsrFiX1RnGMiZ6ZDG/2ANYBtOCPAJvBAaJek+wtpGw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q9l3UghIyVCk+1hN3vH0tk526Pob2VuTeo94lsGNFBtDSSwSK7DFc5g9/ol4gtLiZOe1+VqOM18gQpm+4uU5XaljF03RXYzTJJBY8L8FUKo9ofq4duBDKZHA5cfEConNZbdeGD+i9LSjcdgjqVdSoYvrEIFsFqRzseWd579o0gpO/4II82TnU30oOjr9qunayZHXend9D5uKTg4mxbqk0VOIeyAQ9W+Cq9CjEiK7EFT9ANOZCjTlt++3vfpYPFa8r3WPBUUnnlKnfgLDZvKMoCGzkIvMaYpBTcLeTNlZC+JF6Q6bxJgtWt/gfiRINYqDi1MAdeWO6N1DUiHJXimvdw==
  • Cc: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "Volodymyr Babchuk" <volodymyr_babchuk@xxxxxxxx>, Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Delivery-date: Tue, 09 Jan 2024 21:52:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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>
Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>
Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Signed-off-by: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
---
Since v9:
- removed stray formatting change
- added Roger's R-b tag
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 | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
index a1a004460491..e98693e1dc3e 100644
--- a/xen/drivers/vpci/vpci.c
+++ b/xen/drivers/vpci/vpci.c
@@ -268,6 +268,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:
@@ -311,6 +315,10 @@ static uint32_t vpci_read_hw(pci_sbdf_t sbdf, unsigned int 
reg,
 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.43.0




 


Rackspace

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