xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Wen QI <qiwen@qiwen.name>, xen-devel@lists.xen.org
Subject: Re: Scan guests' page to seek specific instructions
Date: Tue, 27 Oct 2015 13:50:52 +0000	[thread overview]
Message-ID: <562F813C.6030205@citrix.com> (raw)
In-Reply-To: <467E28D4-0618-4E87-A2E2-98D81003BDA7@qiwen.name>

On 26/10/15 22:34, Wen QI wrote:
> Hi,
>
> I am trying to scan guests' pages and check whether they contain specific instructions (e.g., LOCK). I summarize how I did it as follows. Could you please give some suggestions about whether am I on the right direction? Thank you.
>
> In my testing environment, XEN 4.4.0 is deployed. Both Domain-0 and guests are using Ubuntu 14.4 64-bit. The guests are in HVM mode.
>
> 1. In the page fault handler sh_page_fault(), we first judge #PF (regs->error_code), if it contains PFEC_insn_fetch && PFEC_user_mode, then continue to next step.
>
> 2. The virtual address (va, which is from CR3) is converted to MFN.
>
> 3. If the MFN is valid, we get the page address via mfn_to_virt().
>
> 4. Then scan the page's data to check whether specific instructions exist in the page.
>
> To simplify the testing, I temporarily disabled all shadow optimizations by setting SHADOW_OPTIMIZATIONS as 0x0F.
>
> My observations are as follows:
> - In step 2, some virtual addresses can be converted to valid MFN, some cannot.

Why would you expect them all to be valid?  This is how demand paging of
library code typically works.

>
> - In the HVM guest, I run a piece of C code which contains the LOCK instructions. However, in step 4, the instructions cannot be detected.

Why do you expect to ever trap regular usermode execution on a user page?

If you want to do VM Introspection, start with a tool such as libVMI
rather than attempting to implement it from first principles in the
shadow paging code.

~Andrew

      reply	other threads:[~2015-10-27 13:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-26 22:34 Scan guests' page to seek specific instructions Wen QI
2015-10-27 13:50 ` Andrew Cooper [this message]

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=562F813C.6030205@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=qiwen@qiwen.name \
    --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 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).