From: Razvan Cojocaru <rcojocaru@bitdefender.com>
To: Tamas K Lengyel <tamas.lengyel@zentific.com>,
Andrew Cooper <andrew.cooper3@citrix.com>
Cc: "xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: Blocking CR and MSR writes via mem_access?
Date: Mon, 27 Oct 2014 18:10:57 +0200 [thread overview]
Message-ID: <544E6E91.3080508@bitdefender.com> (raw)
In-Reply-To: <5432A674.7000205@bitdefender.com>
> I've actually been looking at this for a bit, and while it's true that
> it might work for CR events, it's less clear how that would work for MSRs.
>
> The CR part might be done in the following fashion:
>
> vcpu_guest_context_any_t ctx;
>
> if (xc_vcpu_getcontext(xch, domain, req.vcpu_id, &ctx) == 0) {
> ctx.c.ctrlreg[crNumber] = req.gla; /* old value */
> xc_vcpu_setcontext(xch, domain, req.vcpu_id, &ctx);
> }
Coming back to this, testing showed that the values were indeed _not_
written. Looking at the code, we end up in arch_set_info_guest() in
xen/arch/x86/domain.c, which does a few things and then, for HVM guests,
calls hvm_set_info_guest() and pretty much exits:
741 if ( is_hvm_vcpu(v) )
742 {
743 hvm_set_info_guest(v);
744 goto out;
745 }
In the VMX case, this doesn't do much (it definitely doesn't set any CR
registers):
1542 static void vmx_set_info_guest(struct vcpu *v)
1543 {
1544 unsigned long intr_shadow;
1545
1546 vmx_vmcs_enter(v);
1547
1548 __vmwrite(GUEST_DR7, v->arch.debugreg[7]);
1549
1550 /*
1551 * If the interruptibility-state field indicates blocking by STI,
1552 * setting the TF flag in the EFLAGS may cause VM entry to fail
1553 * and crash the guest. See SDM 3B 22.3.1.5.
1554 * Resetting the VMX_INTR_SHADOW_STI flag looks hackish but
1555 * to set the GUEST_PENDING_DBG_EXCEPTIONS.BS here incurs
1556 * immediately vmexit and hence make no progress.
1557 */
1558 __vmread(GUEST_INTERRUPTIBILITY_INFO, &intr_shadow);
1559 if ( v->domain->debugger_attached &&
1560 (v->arch.user_regs.eflags & X86_EFLAGS_TF) &&
1561 (intr_shadow & VMX_INTR_SHADOW_STI) )
1562 {
1563 intr_shadow &= ~VMX_INTR_SHADOW_STI;
1564 __vmwrite(GUEST_INTERRUPTIBILITY_INFO, intr_shadow);
1565 }
1566
1567 vmx_vmcs_exit(v);
1568 }
Hope this helps others considering going down this road.
Regards,
Razvan
next prev parent reply other threads:[~2014-10-27 16:10 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-02 10:49 Blocking CR and MSR writes via mem_access? Razvan Cojocaru
2014-10-02 11:39 ` Jan Beulich
2014-10-02 11:46 ` Razvan Cojocaru
2014-10-02 11:51 ` Andrew Cooper
2014-10-02 11:54 ` Razvan Cojocaru
2014-10-02 11:51 ` Jan Beulich
2014-10-02 12:04 ` Razvan Cojocaru
2014-10-03 12:32 ` Tamas K Lengyel
2014-10-03 12:37 ` Andrew Cooper
2014-10-03 13:00 ` Razvan Cojocaru
2014-10-03 16:22 ` Tamas K Lengyel
2014-10-03 18:13 ` Razvan Cojocaru
2014-10-06 14:25 ` Razvan Cojocaru
2014-10-07 8:59 ` Tamas K Lengyel
2014-10-07 10:21 ` Razvan Cojocaru
2014-10-07 10:48 ` Razvan Cojocaru
2014-10-07 12:30 ` Tamas K Lengyel
2014-10-07 12:40 ` Jan Beulich
2014-10-07 12:46 ` Tamas K Lengyel
2014-10-07 12:49 ` Andrew Cooper
2014-10-07 12:55 ` Razvan Cojocaru
2014-10-07 12:58 ` Tamas K Lengyel
2014-10-07 13:06 ` Razvan Cojocaru
2014-10-07 12:48 ` Razvan Cojocaru
2014-10-27 16:10 ` Razvan Cojocaru [this message]
2014-10-03 12:42 ` Razvan Cojocaru
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=544E6E91.3080508@bitdefender.com \
--to=rcojocaru@bitdefender.com \
--cc=andrew.cooper3@citrix.com \
--cc=tamas.lengyel@zentific.com \
--cc=xen-devel@lists.xen.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.