xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Razvan Cojocaru <rcojocaru@bitdefender.com>
To: Andres Lagar Cavilla <andres@lagarcavilla.org>
Cc: "Tian, Kevin" <kevin.tian@intel.com>, Keir Fraser <keir@xen.org>,
	Ian Campbell <ian.campbell@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	Jun Nakajima <jun.nakajima@intel.com>,
	"Dong, Eddie" <eddie.dong@intel.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
	Jan Beulich <jbeulich@suse.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH V6 5/5] xen: Handle resumed instruction based on previous mem_event reply
Date: Thu, 11 Sep 2014 00:28:06 +0300	[thread overview]
Message-ID: <5410C266.1060007@bitdefender.com> (raw)
In-Reply-To: <CADzFZPv74RJw2QMz7HXnW-UngC9ZmdHn1=WajtLMeKCpDX1kAA@mail.gmail.com>

On 09/10/14 21:28, Andres Lagar Cavilla wrote:
>     On Wed, Sep 10, 2014 at 5:12 PM, Razvan Cojocaru
>     <rcojocaru@bitdefender.com <mailto:rcojocaru@bitdefender.com>> wrote:
>     > On 09/10/2014 07:03 PM, George Dunlap wrote:
>     >> On Tue, Sep 9, 2014 at 11:28 AM, Razvan Cojocaru
>     >> <rcojocaru@bitdefender.com <mailto:rcojocaru@bitdefender.com>> wrote:
>     >>> In a scenario where a page fault that triggered a mem_event occured,
>     >>> p2m_mem_access_check() will now be able to either 1) emulate the
>     >>> current instruction, or 2) emulate it, but don't allow it to perform
>     >>> any writes.
>     >>>
>     >>> Signed-off-by: Razvan Cojocaru <rcojocaru@bitdefender.com
>     <mailto:rcojocaru@bitdefender.com>>
>     >>> Acked-by: Kevin Tian <kevin.tian@intel.com
>     <mailto:kevin.tian@intel.com>>
>     >> [snip]
>     >>
>     >>> +    else if ( v->arch.mem_event.emulate_flags == 0 &&
>     >>> +              npfec.kind != npfec_kind_with_gla ) /* don't send
>     a mem_event */
>     >>> +    {
>     >>> +        v->arch.mem_event.emulate_flags = MEM_EVENT_FLAG_EMULATE;
>     >>> +        v->arch.mem_event.gpa = gpa;
>     >>> +        v->arch.mem_event.eip = eip;
>     >>> +    }
>     >>
>     >> It looks like the previous if() is true, that it will never get to
>     >> this point (because it will either return 0 or 1 depending on whether
>     >> p2m->access_required is set).  So you don't need to make this an
>     >> "else" here -- you should just add a blank line and make this a
>     normal
>     >> if().
>     >>
>     >> Also, maybe it's just because I'm not familiar with the mem_event
>     >> interface, but I don't really see what this code is doing.  It seems
>     >> to be changing the behavior even for clients that aren't using
>     >> MEM_EVENT_FLAG_EMULATE*.  Is that intended?  In any case it seems
>     like
>     >> there could be a better comment here.
>     >
>     > Thanks, those are very good points. I'll make that a regular if(), and
>     > test also if introspection monitoring is enabled (please see patch
>     3/5:
>     > d->arch.hvm_domain.introspection_enabled) before setting the emulate
>     > flag, that way we won't alter the behaviour for other clients.
> 
>     ...and you should also put a comment there explaining why someone with
>     introspection enabled wouldn't want an event here (something I'm still
>     not clear on).
> 
>     Are you *sure* that everyone who enables introspection will want that
>     event suppressed (not just you), and that no one else will?
>     Otherwise, it might make more sense to add some kind of flag to enable
>     or disable it, rather than gating it on introspection.  Or it's
>     possible everyone actually does want that event suppressed -- in which
>     case making it universal is the best option.
> 
>     Andres, any opinions here?
> 
> 
> My view of the mem event interface is that it should err on the side of
> informing the consumer. Now, if the consumer doesn't sign up for
> something, why bother (i.e. we don't inform of writes, if the access
> mode set for the gfn does not mask writes, etc).
> 
> In an ideal world, the emulation of the instruction should raise all
> relevant new mem events. We don't know a priori what the consumer might
> learn throughout the execution of this specific instruction. Does it
> read from or write to new gfns which have mem access masks set? TTBOMK,
> because the emulation does not go through the EPT fault handler, no mem
> access events will be generated, even if they should.
> 
> This is a long-standing shortcoming of mem event in security frameworks,
> in that mem access is only defined as raising events through EPT faults.
> One could conceivably craft an attack by having an instruction that
> through its emulation reads/writes a massive buffer going into other
> gfns. Conversely, "virtual DMA", i.e. qemu accesses via
> map_foreign_pages and grant accesses form backends don't raise mem
> access events. So there are many (conceptual) holes.
> 
> A decent thing to do for now would be to add a flag ..._EMULATE_SILENT,
> which resolves to the current behavior, and lack of ..._EMULATE_SILENT
> in a brave future would raise all the mem access events resulting from
> the full emulation of this instruction. Fix the API at least, before
> it's set in stone.

As far as I understand, George is asking about why events that have
npfec.kind != npfec_kind_with_gla are being emulated instead of being
sent out like the rest, and if that's a requirement that all memory
introspection clients might have.

To answer that question, _our_ application is not interested in events
other than npfec_kind_with_gla, and because of that it seemed worthwhile
to save a HV <-> dom0 roundtrip for events that would need to be ignored
by the application anyway, and thus keep the guest as responsive as
possible. I can't, of course, state that no other introspection client
will be interested in the other types of events.  But I can add another
parameter to xc_mem_access_enable_introspection() (please see patch 3/5
in the series) to specify whether non-npfec_kind_with_gla events should
be ignored or not (is this what the ..._EMULATE_SILENT suggestion refers
to?).


Thanks,
Razvan Cojocaru

  reply	other threads:[~2014-09-10 21:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-09 10:28 [PATCH V6 0/5] Basic guest memory introspection support Razvan Cojocaru
2014-09-09 10:28 ` [PATCH V6 1/5] xen: Emulate with no writes Razvan Cojocaru
2014-09-09 10:28 ` [PATCH V6 2/5] xen: Optimize introspection access to guest state Razvan Cojocaru
2014-09-09 10:28 ` [PATCH V6 3/5] xen, libxc: Force-enable relevant MSR events Razvan Cojocaru
2014-09-09 10:28 ` [PATCH V6 4/5] xen, libxc: Request page fault injection via libxc Razvan Cojocaru
2014-09-10 14:38   ` Jan Beulich
2014-09-09 10:28 ` [PATCH V6 5/5] xen: Handle resumed instruction based on previous mem_event reply Razvan Cojocaru
2014-09-10 16:03   ` George Dunlap
2014-09-10 16:12     ` Razvan Cojocaru
2014-09-10 16:38       ` George Dunlap
     [not found]         ` <CAJu=L59+C7+byC0UJVcriERf-cueiz8CYcCeBOZfXX8ZLjTBRQ@mail.gmail.com>
2014-09-10 18:28           ` Andres Lagar Cavilla
2014-09-10 21:28             ` Razvan Cojocaru [this message]
2014-09-11 10:09               ` George Dunlap
2014-09-11 10:44                 ` Razvan Cojocaru
2014-09-11 14:40             ` Tamas K Lengyel
2014-09-11 16:42               ` Andres Lagar Cavilla
2014-09-11 18:09                 ` Tamas K Lengyel
2014-09-11 18:39                   ` Andres Lagar Cavilla
2014-09-11 19:06                     ` Andrew Cooper
2014-09-09 10:34 ` [PATCH V6 0/5] Basic guest memory introspection support Jan Beulich
2014-09-09 10:39   ` 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=5410C266.1060007@bitdefender.com \
    --to=rcojocaru@bitdefender.com \
    --cc=andres@lagarcavilla.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=eddie.dong@intel.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jun.nakajima@intel.com \
    --cc=keir@xen.org \
    --cc=kevin.tian@intel.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=tim@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 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).