xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Oleksandr Andrushchenko" <Oleksandr_Andrushchenko@epam.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH v2 2/4] vpci: restrict unhandled read/write operations for guests
Date: Mon, 18 Jul 2022 21:15:42 +0000	[thread overview]
Message-ID: <20220718211521.664729-3-volodymyr_babchuk@epam.com> (raw)
In-Reply-To: <20220718211521.664729-1-volodymyr_babchuk@epam.com>

From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>

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@citrix.com>
Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>

---
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 9fb3c05b2b..c7a40a2f41 100644
--- a/xen/drivers/vpci/vpci.c
+++ b/xen/drivers/vpci/vpci.c
@@ -215,6 +215,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:
@@ -255,9 +259,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.36.1

  parent reply	other threads:[~2022-07-18 21:16 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 21:15 [PATCH v2 0/4] vpci: first series in preparation for vpci on ARM Volodymyr Babchuk
2022-07-18 21:15 ` [PATCH v2 1/4] pci: add rwlock to pcidevs_lock machinery Volodymyr Babchuk
2022-07-19  6:20   ` Wei Chen
2022-07-20 18:43     ` Volodymyr Babchuk
2022-07-18 21:15 ` Volodymyr Babchuk [this message]
2022-07-18 21:15 ` [PATCH v2 3/4] vpci: use pcidevs locking to protect MMIO handlers Volodymyr Babchuk
2022-08-01 11:40   ` Jan Beulich
2022-08-09 20:33     ` Volodymyr Babchuk
2022-08-10  6:46       ` Jan Beulich
2022-07-18 21:15 ` [PATCH v2 4/4] vpci: include xen/vmap.h to fix build on ARM Volodymyr Babchuk
2022-07-19  6:07   ` Jan Beulich
2022-07-19 10:32     ` Volodymyr Babchuk
2022-07-19 10:40       ` Jan Beulich
2022-10-21 14:32         ` Oleksandr
2022-10-21 14:40           ` Henry Wang
2022-10-21 14:56             ` Bertrand Marquis
2022-10-22  0:50               ` Henry Wang
2022-10-24  6:34                 ` Jan Beulich
2022-10-27  8:28   ` Roger Pau Monné

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220718211521.664729-3-volodymyr_babchuk@epam.com \
    --to=volodymyr_babchuk@epam.com \
    --cc=Oleksandr_Andrushchenko@epam.com \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).