target-i386: fix protection bits in the TLB for SMEP
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 27 May 2014 11:24:54 +0000 (13:24 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 5 Jun 2014 14:10:35 +0000 (16:10 +0200)
User pages must be marked as non-executable when running under SMEP;
otherwise, fetching the page first and then calling it will fail.

With this patch, all SMEP testcases in kvm-unit-tests now pass.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
target-i386/helper.c

index 2b917ad28d92de13e674fc39ff421302c5f83ff9..04beaebc98d951f1303745659d5003ae22aac970 100644 (file)
@@ -749,8 +749,10 @@ do_check_protect_pse36:
 
     /* the page can be put in the TLB */
     prot = PAGE_READ;
-    if (!(ptep & PG_NX_MASK))
+    if (!(ptep & PG_NX_MASK) &&
+        !((env->cr[4] & CR4_SMEP_MASK) && (ptep & PG_USER_MASK))) {
         prot |= PAGE_EXEC;
+    }
     if (pte & PG_DIRTY_MASK) {
         /* only set write access if already dirty... otherwise wait
            for dirty access */