[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] vpci: add permission checks to map_range()
- To: xen-devel@xxxxxxxxxxxxxxxxxxxx
- From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
- Date: Mon, 24 Jul 2023 17:37:41 +0200
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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=dG3oPCszXfwQasS/uN0MSJM+luIJvXbEbNU+alUDoOY=; b=RCTPAF8/OE7JkwGJ7BJWY9AfZw6w5HyzHQQ7y5GHb387EzyBGk/RLWfxIXikizO+ElBX89Ci3lnhoW6ojWx1jAW/sljzmbVETIbTt6vf8jzrmOcPX1c0uup+cyQ9PlQz7wq3s4kM+90dcx5rBBH3SW8HrwP1NmGEcVwh6iNKR4VboRjtJGQj2q8DDOJOcPPExC/23khIo6LzCHgXyi6/oVAwjPxCtji09Ks8XPecy2Cuu2TwRJxrlp2tNO+SzVnOhRO34r8NlhFw3OXS+f84uylKVSQZkTJcVTMKRllpLEwVjSajUTzmMnvpHlUTDN+Kk4a5AT/hEbO9RKhJzLFgVQ==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FZVss69ow/aL+z5clJzrIieha+cLJPQMBqVa44hrhstV1GAfiKBR9PuzchxmU3YX/ms6YgwQ+UgIvmZyvJV4bLO4c4CTxuASeAUA/ot7/9z+h4XAZO+PUeREfjkXP1b7OcYS1iJ6WuoNMSJUvsVB82iaLR2C1PxFDcCCjAIvEpCQr5gvN0xbTunKnHdte67RLiOFqwSmak9qkrUeAaF6H1VzMrwYJTy1A61aepMJYyYktcu2artlB64l4WC/aTUJBNdk8dTi/j8VoWbZeaV+wGkXc2Ewj16j1NsN14Dnmyg261meakJWzdQy1dWgQSSM6obvzWV7CczjV3EHqTUUig==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
- Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>
- Delivery-date: Mon, 24 Jul 2023 15:38:35 +0000
- Ironport-data: A9a23:czyk8KsgB0VwVE3fQKwZrugVt+fnVJJfMUV32f8akzHdYApBsoF/q tZmKT2HO6nfZGr2Kt51Pt60oxgD756EydcwGwplqy1gQytB+JbJXdiXEBz9bniYRiHhoOCLz O1FM4Wdc5pkJpP4jk3wWlQ0hSAkjclkfpKlVKiffHg3HVQ+IMsYoUoLs/YjhYJ1isSODQqIu Nfjy+XSI1bg0DNvWo4uw/vrRChH4rKq4Vv0gnRkPaoQ5ACEzCFOZH4iDfrZw0XQE9E88tGSH 44v/JnhlkvF8hEkDM+Sk7qTWiXmlZaLYGBiIlIPM0STqkAqSh4ai87XB9JFAatjsB2bnsgZ9 Tl4ncfYpTHFnEH7sL91vxFwS0mSNEDdkVPNCSDXXce7lyUqf5ZwqhnH4Y5f0YAwo45K7W9yG fMwJwwgPjPZrt+Mnqu0FPh1nt4mLYq7BdZK0p1g5Wmx4fcOZ7nmGvyPyfoGmTA6i4ZJAOrUY NcfZXx3dhPcbhZTO1ARTpUjgOOvgXq5eDpdwL6XjfNvvy6Pk0osj/60b4K9lt+iHK25mm6Co W3L5SLhCwwyP92D0zuVtHmrg4cjmAuiAd1MS+zlraECbFu74XUcMxJOdnSAjd68gBGvdvFRF U4o0397xUQ13AnxJjXnZDWorXjBshMCVt54F+wh9BrL2qfS+xyeBGUPUnhGctNOnM08SCEu1 1SJt8j0HjEpu7qQIVqC8p+EoDX0PjIaRUcOfTQBTBcFy9D7rZsvkwnUSdJ+DK+yiMazEjb1q w1mtwA7jrQXyMIOiaOy+Amehyr2/8eRCAko+g/QQ2SpqBtjY5KobJCp7l6d6utcKIGeTR+Ku 31sd9Wi0d3ixKqlzESlKNjh1pn0jxpZGFUwWWJSIqQ=
- Ironport-hdrordr: A9a23:iEf1RqpId5uLIsj9aOXOCwsaV5tALNV00zEX/kB9WHVpm5Oj+v xGzc5w6farsl0ssREb9uxo9pPwI080kqQFmbX5XI3SJTUO3VHFEGgM1/qH/9SNIU3DH41mpN pdmspFebrN5DFB5K6VgTVQe+xQuuVvm5rY4Ns2oU0dLj2DPMpbnnxE40ugYzpLrE4sP+tJKL Osou584xawc3Ueacq2QlEDQuj4vtXO0L72fBIcABYjyQ+WyRel8qTzHRS01goXF2on+8ZozU H11yjCoomzufCyzRHRk0fV8pRtgdPkjvdTGcCWjcARCzP0ziKlfp5oVbGutC085Muv9FEput /RpApIBbU611rhOkWO5Tf90Qjp1zgjr1fk1F+jmHPm5ej0XigzBcZtjZ9QNkKx0TtogPhMlI Zwm06JvZteCh3N2Az7+tjzThlv0m65u2Arn+I/h2FWFaEedLhSh4oC+149KuZ3IAvKrKQcVM V+BsDV4/hbNXuccnDip2FqhOehW3widy32MHQqi4iw6Xx7jXp5x0wXyIg0hXEb7q8wTJFC+q DtLrlovKsmdL5YUYtNQMM6BeenAG3ERhzBdEiIJ078Ka0BM3XR77bq/bQO4v2wcpBg9up/pH 34aiIYiYcOQTOvNSXXt6c7sSwlAV/NEAgF8/suqaSQ4dbHNfjW2S7qciFcryLvmYRbPiThYY fMBHtnOY6eEYLQI/c34+SHYeg1FZA/arxhhj9pYSP7nuv7bqvXi8f8TNH/YJLQLBdMYBKOPp JEZkm4GPl9
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
Just like it's done for the XEN_DOMCTL_memory_mapping hypercall, add
the permissions checks to vPCI map_range(), which is used to map the
BARs into the domain p2m.
Adding those checks requires that for x86 PVH hardware domain builder
the permissions are set before initializing the IOMMU, or else
attempts to initialize vPCI done as part of IOMMU device setup will
fail due to missing permissions to create the BAR mappings.
Fixes: 9c244fdef7e7 ('vpci: add header handlers')
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
I'm unsure whether on ARM MMIO permissions are properly set for the
hardware domain, but I don't have a system to test with.
---
xen/arch/x86/hvm/dom0_build.c | 21 ++++++++++++++-------
xen/drivers/vpci/header.c | 18 ++++++++++++++++++
2 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c
index fd2cbf68bc62..c0ca57e05e98 100644
--- a/xen/arch/x86/hvm/dom0_build.c
+++ b/xen/arch/x86/hvm/dom0_build.c
@@ -715,13 +715,6 @@ static int __init pvh_setup_cpus(struct domain *d, paddr_t
entry,
return rc;
}
- rc = dom0_setup_permissions(d);
- if ( rc )
- {
- panic("Unable to setup Dom0 permissions: %d\n", rc);
- return rc;
- }
-
update_domain_wallclock_time(d);
v->is_initialised = 1;
@@ -1184,6 +1177,20 @@ int __init dom0_construct_pvh(struct domain *d, const
module_t *image,
printk(XENLOG_INFO "*** Building a PVH Dom%d ***\n", d->domain_id);
+ if ( is_hardware_domain(d) )
+ {
+ /*
+ * Setup permissions early so that calls to add MMIO regions to the
+ * p2m as part of vPCI setup don't fail due to permission checks.
+ */
+ rc = dom0_setup_permissions(d);
+ if ( rc )
+ {
+ printk("%pd unable to setup permissions: %d\n", d, rc);
+ return rc;
+ }
+ }
+
/*
* NB: MMCFG initialization needs to be performed before iommu
* initialization so the iommu code can fetch the MMCFG regions used by the
diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
index b41556d00746..12ae37deac83 100644
--- a/xen/drivers/vpci/header.c
+++ b/xen/drivers/vpci/header.c
@@ -17,10 +17,13 @@
* License along with this program; If not, see <http://www.gnu.org/licenses/>.
*/
+#include <xen/iocap.h>
#include <xen/sched.h>
#include <xen/softirq.h>
#include <xen/vpci.h>
+#include <xsm/xsm.h>
+
#include <asm/event.h>
#include <asm/p2m.h>
@@ -43,6 +46,21 @@ static int cf_check map_range(
{
unsigned long size = e - s + 1;
+ if ( !iomem_access_permitted(map->d, s, e) )
+ {
+ gprintk(XENLOG_WARNING,
+ "%pd denied access to MMIO range [%#lx, %#lx]\n", s, e);
+ return -EPERM;
+ }
+
+ rc = xsm_iomem_mapping(XSM_HOOK, map->d, s, e, map->map);
+ if ( rc )
+ {
+ gprintk(XENLOG_WARNING,
+ "%pd XSM denied access to MMIO range [%#lx, %#lx]\n", s,
e);
+ return rc;
+ }
+
/*
* ARM TODOs:
* - On ARM whether the memory is prefetchable or not should be passed
--
2.41.0
|