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

[PATCH v9 03/16] vpci: restrict unhandled read/write operations for guests


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Date: Tue, 29 Aug 2023 23:19:42 +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=u1exkS/uweIgKXeUpBvInyadEJMzoYayUA8BpUFSFtw=; b=iberMZOBsXwU5e/SktgmXy6EbrCeDNwLmSYhzfp+GgT3yKZWtQTu6db9clo10ldpNCP0qjNn+9PXUhKMvyEERDEHthSNK2ZTpUrLOX16IuDxDyMdIO1l+ynKEAzbklVn+PVSJHHdAY2W3bd3cdVzKt/QMpYHs5qNOj0vF5kvLO/JeJ7MMJSM+JMxGaTXeihJ6w0mz6dvz+1OIqFzF7wGdWzQGAXsl2fhLzFX0aUlU73rPqfPsv3Wd4FF6uQdiDMovluUICbUFIWqOlTvviwj1hQxaBIEcnicOXcktTulijxcjmeEO6C2ggXMg6iTEm/KpraXi4Bk8VoUPhSkg38sLw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yb8bctkTG9C4wzoqZGcx3fQI+wXfN/+KWBTmmJxhRIuZ3FdpPAlOmiJy2fDW7D9lBpYzbuCxhIMOAk6d5BvilBRaY/SqtejXPoBBJprm2nvpznvi8RO4bIn+KMAC+qJrh49Q9w9FWF0yCEUZw9nSSMAOzRe+8N4B/xqv7WFXpTwyCPYeFNR4F/+dXASebDvBmCSPi/mBhPw1xbk9jX1rus0ZUsfgei3XwzdiDwSs9/sUcQ/EENbOiRL/mC5+6+b4FiBaE5uJ2DGyWQDC7uq1Q7vjn2Qf7auqFaRdk22IgoceP89jFL98zXQTZffexwnzS2j7QK0ACP1mUArJ1qFN2w==
  • Cc: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>, Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Tue, 29 Aug 2023 23:20:05 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZ2s9K3uXHQsaiPESKImIi9IiKlw==
  • Thread-topic: [PATCH v9 03/16] 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>
Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

---
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 34fff2ef2d..cb45904114 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:
@@ -276,6 +280,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.41.0

 


Rackspace

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