All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Wei Liu" <wl@xen.org>, "Roger Pau Monné" <roger.pau@citrix.com>,
	"Paul Durrant" <paul@xen.org>
Subject: [PATCH 2/3] x86/HVM: fail virt-to-linear conversion for insn fetches from non-code segments
Date: Fri, 3 Dec 2021 12:22:37 +0100	[thread overview]
Message-ID: <46fdafdd-d6a9-778b-d634-fad8d2f6925a@suse.com> (raw)
In-Reply-To: <10c7b3c0-c64f-3d12-06d3-8c408f7c9f4c@suse.com>

Just like (in protected mode) reads may not go to exec-only segments and
writes may not go to non-writable ones, insn fetches may not access data
segments.

Fixes: 623e83716791 ("hvm: Support hardware task switching")
Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -2551,6 +2551,9 @@ bool hvm_vcpu_virtual_to_linear(
      */
     ASSERT(seg < x86_seg_none);
 
+    /* However, check that insn fetches only ever specify CS. */
+    ASSERT(access_type != hvm_access_insn_fetch || seg == x86_seg_cs);
+
     if ( !(v->arch.hvm.guest_cr[0] & X86_CR0_PE) )
     {
         /*
@@ -2615,10 +2618,17 @@ bool hvm_vcpu_virtual_to_linear(
                 if ( (reg->type & 0xa) == 0x8 )
                     goto out; /* execute-only code segment */
                 break;
+
             case hvm_access_write:
                 if ( (reg->type & 0xa) != 0x2 )
                     goto out; /* not a writable data segment */
                 break;
+
+            case hvm_access_insn_fetch:
+                if ( !(reg->type & 0x8) )
+                    goto out; /* not a code segment */
+                break;
+
             default:
                 break;
             }



  parent reply	other threads:[~2021-12-03 11:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-03 11:18 [PATCH 0/3] x86: insn-fetch related emulation adjustments Jan Beulich
2021-12-03 11:21 ` [PATCH 1/3] x86/HVM: permit CLFLUSH{,OPT} on execute-only code segments Jan Beulich
2021-12-03 11:48   ` Andrew Cooper
2021-12-03 11:55     ` Jan Beulich
2021-12-10 12:53   ` Durrant, Paul
2021-12-03 11:22 ` Jan Beulich [this message]
2021-12-03 11:49   ` [PATCH 2/3] x86/HVM: fail virt-to-linear conversion for insn fetches from non-code segments Andrew Cooper
2021-12-03 11:23 ` [PATCH 3/3] x86emul: drop "seg" parameter from insn_fetch() hook Jan Beulich
2021-12-03 12:24   ` Andrew Cooper
2021-12-10 12:56   ` Durrant, Paul
2021-12-10  9:43 ` Ping: [PATCH 0/3] x86: insn-fetch related emulation adjustments Jan Beulich

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=46fdafdd-d6a9-778b-d634-fad8d2f6925a@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=paul@xen.org \
    --cc=roger.pau@citrix.com \
    --cc=wl@xen.org \
    --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 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.