All of lore.kernel.org
 help / color / mirror / Atom feed
From: Evgeny Yakovlev <wrfsh@yandex-team.ru>
To: kvm@vger.kernel.org
Subject: [kvm-unit-tests PATCH] x86: access: revert PTE changes if CR4.SMEP change failed
Date: Tue, 19 Sep 2017 16:33:00 +0300	[thread overview]
Message-ID: <1505827980-9351-1-git-send-email-wrfsh@yandex-team.ru> (raw)

When calling set_cr4_smep(1) to enable SMEP implementation will first
drop user access bit in ptl2 and then attempt to change actual cr4
value. In case emulated CPU does not support setting CR4.SMEP this will
generate a GP which we expect. However, in that case we should also
revert user access bit change. Othervise supervisor access sticks and
later faults the test binary.

Signed-off-by: Evgeny Yakovlev <wrfsh@yandex-team.ru>
---
 x86/access.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/x86/access.c b/x86/access.c
index a0c19dc..ccdaefc 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -195,6 +195,7 @@ unsigned set_cr4_smep(int smep)
 {
     unsigned long cr4 = read_cr4();
     unsigned long old_cr4 = cr4;
+    unsigned long ptl2_access;
     extern u64 ptl2[];
     unsigned r;
 
@@ -204,9 +205,15 @@ unsigned set_cr4_smep(int smep)
     if (old_cr4 == cr4)
         return 0;
 
+    ptl2_access = ptl2[2];
     if (smep)
         ptl2[2] &= ~PT_USER_MASK;
     r = write_cr4_checking(cr4);
+    if (cr4 != read_cr4()) {
+        if (smep)
+            ptl2[2] = ptl2_access;
+        return r;
+    }
     if (!smep)
         ptl2[2] |= PT_USER_MASK;
     return r;
-- 
2.7.4

             reply	other threads:[~2017-09-19 13:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-19 13:33 Evgeny Yakovlev [this message]
2017-09-19 14:34 ` [kvm-unit-tests PATCH] x86: access: revert PTE changes if CR4.SMEP change failed Paolo Bonzini
2017-09-19 14:41   ` Евгений Яковлев

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=1505827980-9351-1-git-send-email-wrfsh@yandex-team.ru \
    --to=wrfsh@yandex-team.ru \
    --cc=kvm@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.