From: Sergej Proskurin <proskurin@sec.in.tum.de>
To: xen-devel@lists.xenproject.org
Cc: Sergej Proskurin <proskurin@sec.in.tum.de>,
Julien Grall <julien.grall@arm.com>,
Tamas K Lengyel <tamas@tklengyel.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Razvan Cojocaru <rcojocaru@bitdefender.com>
Subject: [PATCH v8 13/13] arm/mem_access: Walk the guest's pt in software
Date: Wed, 9 Aug 2017 10:20:38 +0200 [thread overview]
Message-ID: <20170809082038.3236-14-proskurin@sec.in.tum.de> (raw)
In-Reply-To: <20170809082038.3236-1-proskurin@sec.in.tum.de>
In this commit, we make use of the gpt walk functionality introduced in
the previous commits. If mem_access is active, hardware-based gva to ipa
translation might fail, as gva_to_ipa uses the guest's translation
tables, access to which might be restricted by the active VTTBR. To
side-step potential translation errors in the function
p2m_mem_access_check_and_get_page due to restricted memory (e.g. to the
guest's page tables themselves), we walk the guest's page tables in
software.
Signed-off-by: Sergej Proskurin <proskurin@sec.in.tum.de>
Acked-by: Tamas K Lengyel <tamas@tklengyel.com>
---
Cc: Razvan Cojocaru <rcojocaru@bitdefender.com>
Cc: Tamas K Lengyel <tamas@tklengyel.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Julien Grall <julien.grall@arm.com>
---
v2: Check the returned access rights after walking the guest's page tables in
the function p2m_mem_access_check_and_get_page.
v3: Adapt Function names and parameter.
v4: Comment why we need to fail if the permission flags that are
requested by the caller do not satisfy the mapped page.
Cosmetic fix that simplifies the if-statement checking for the
GV2M_WRITE permission.
v5: Move comment to ease code readability.
---
xen/arch/arm/mem_access.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/xen/arch/arm/mem_access.c b/xen/arch/arm/mem_access.c
index e0888bbad2..3e2bb4088a 100644
--- a/xen/arch/arm/mem_access.c
+++ b/xen/arch/arm/mem_access.c
@@ -22,6 +22,7 @@
#include <xen/vm_event.h>
#include <public/vm_event.h>
#include <asm/event.h>
+#include <asm/guest_walk.h>
static int __p2m_get_mem_access(struct domain *d, gfn_t gfn,
xenmem_access_t *access)
@@ -101,6 +102,7 @@ p2m_mem_access_check_and_get_page(vaddr_t gva, unsigned long flag,
const struct vcpu *v)
{
long rc;
+ unsigned int perms;
paddr_t ipa;
gfn_t gfn;
mfn_t mfn;
@@ -110,8 +112,35 @@ p2m_mem_access_check_and_get_page(vaddr_t gva, unsigned long flag,
struct p2m_domain *p2m = p2m_get_hostp2m(v->domain);
rc = gva_to_ipa(gva, &ipa, flag);
+
+ /*
+ * In case mem_access is active, hardware-based gva_to_ipa translation
+ * might fail. Since gva_to_ipa uses the guest's translation tables, access
+ * to which might be restricted by the active VTTBR, we perform a gva to
+ * ipa translation in software.
+ */
if ( rc < 0 )
- goto err;
+ {
+ /*
+ * The software gva to ipa translation can still fail, e.g., if the gva
+ * is not mapped.
+ */
+ if ( guest_walk_tables(v, gva, &ipa, &perms) < 0 )
+ goto err;
+
+ /*
+ * Check permissions that are assumed by the caller. For instance in
+ * case of guestcopy, the caller assumes that the translated page can
+ * be accessed with requested permissions. If this is not the case, we
+ * should fail.
+ *
+ * Please note that we do not check for the GV2M_EXEC permission. Yet,
+ * since the hardware-based translation through gva_to_ipa does not
+ * test for execute permissions this check can be left out.
+ */
+ if ( (flag & GV2M_WRITE) && !(perms & GV2M_WRITE) )
+ goto err;
+ }
gfn = gaddr_to_gfn(ipa);
--
2.13.3
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
prev parent reply other threads:[~2017-08-09 8:21 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-09 8:20 [PATCH v8 00/13] arm/mem_access: Walk guest page tables in SW if mem_access is active Sergej Proskurin
2017-08-09 8:20 ` [PATCH v8 01/13] arm/mem_access: Add and cleanup (TCR_|TTBCR_)* defines Sergej Proskurin
2017-08-09 8:20 ` [PATCH v8 02/13] arm/mem_access: Add defines supporting PTs with varying page sizes Sergej Proskurin
2017-08-09 8:20 ` [PATCH v8 03/13] arm/lpae: Introduce lpae_is_page helper Sergej Proskurin
2017-08-09 8:20 ` [PATCH v8 04/13] arm/mem_access: Add short-descriptor pte typedefs and macros Sergej Proskurin
2017-08-09 8:20 ` [PATCH v8 05/13] arm/mem_access: Introduce GV2M_EXEC permission Sergej Proskurin
2017-08-09 8:20 ` [PATCH v8 06/13] arm/mem_access: Introduce BIT_ULL bit operation Sergej Proskurin
2017-08-09 8:20 ` [PATCH v8 07/13] arm/mem_access: Introduce GENMASK_ULL " Sergej Proskurin
2017-08-15 18:08 ` Sergej Proskurin
2017-08-15 22:24 ` Stefano Stabellini
2017-08-09 8:20 ` [PATCH v8 08/13] arm/guest_access: Move vgic_access_guest_memory to guest_access.h Sergej Proskurin
2017-08-16 9:58 ` Sergej Proskurin
2017-08-16 10:11 ` Julien Grall
2017-08-16 12:35 ` Sergej Proskurin
2017-08-09 8:20 ` [PATCH v8 09/13] arm/guest_access: Rename vgic_access_guest_memory Sergej Proskurin
2017-08-14 17:29 ` Julien Grall
2017-08-09 8:20 ` [PATCH v8 10/13] arm/mem_access: Add software guest-page-table walk Sergej Proskurin
2017-08-09 8:20 ` [PATCH v8 11/13] arm/mem_access: Add long-descriptor based gpt Sergej Proskurin
2017-08-14 17:37 ` Julien Grall
2017-08-14 21:03 ` Sergej Proskurin
2017-08-15 10:13 ` Julien Grall
2017-08-15 18:03 ` Sergej Proskurin
2017-08-15 22:25 ` Stefano Stabellini
2017-08-15 22:28 ` Andrew Cooper
2017-08-16 8:53 ` Sergej Proskurin
2017-08-09 8:20 ` [PATCH v8 12/13] arm/mem_access: Add short-descriptor " Sergej Proskurin
2017-08-09 8:20 ` Sergej Proskurin [this message]
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=20170809082038.3236-14-proskurin@sec.in.tum.de \
--to=proskurin@sec.in.tum.de \
--cc=julien.grall@arm.com \
--cc=rcojocaru@bitdefender.com \
--cc=sstabellini@kernel.org \
--cc=tamas@tklengyel.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).