From: "Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: xen-devel <xen-devel@lists.xen.org>
Subject: Re: xc_evtchn_status fails with EFAULT on HVM, the same on PV works
Date: Fri, 13 Jan 2017 21:32:23 +0100 [thread overview]
Message-ID: <20170113203223.GO1341@mail-itl> (raw)
In-Reply-To: <f356b4c1-2d56-407a-91c9-e9b0b5622d81@citrix.com>
[-- Attachment #1.1: Type: text/plain, Size: 3681 bytes --]
On Fri, Jan 13, 2017 at 07:54:01PM +0000, Andrew Cooper wrote:
> On 13/01/17 19:40, Marek Marczykowski-Górecki wrote:
> > On Fri, Jan 13, 2017 at 07:27:20PM +0000, Andrew Cooper wrote:
> >> On 13/01/17 18:59, Marek Marczykowski-Górecki wrote:
> >>> On Fri, Jan 13, 2017 at 06:37:06PM +0000, Andrew Cooper wrote:
> >>>> On 13/01/17 18:32, Marek Marczykowski-Górecki wrote:
> >>>>> On Fri, Jan 13, 2017 at 06:15:35PM +0000, Andrew Cooper wrote:
> >>>>>> Can you get the result of this piece of debugging in the failure case?
> >>>>> I've got this:
> >>>>> ** d4v0 CFG(24, 00007f794bd07004, 1) = 24
> >>>> Silly question (and I really hope the answer isn't yes, but I have a
> >>>> sinking feeling it is).
> >>>>
> >>>> Is the guest in question using SMAP? If so, does disabling SMAP fix the
> >>>> problem?
> >>> How can I check that? If looking at 0x200000 CR4 bit in `xl debug-keys
> >>> v` output enough, then yes - it's enabled. And booting hypervisor with
> >>> smap=0 "fixed" the problem.
> >> :(, although now I think about it, there might be a quick option.
> >>
> >>> So, what would be the correct solution? I'd prefer not to disable SMAP
> >>> "just" for this reason...
> >> For the quick option, the privcmd driver in Linux needs a stac()/clac()
> >> pair around the actual hypercall invocation, to whitelist userspace
> >> memory accesses as being ok.
> >>
> >> Something like this (completely untested)
> >>
> >> andrewcoop@andrewcoop:/local/linux.git/arch/x86$ git diff
> >> diff --git a/arch/x86/include/asm/xen/hypercall.h
> >> b/arch/x86/include/asm/xen/hypercall.h
> >> index a12a047..e1b2af9e 100644
> >> --- a/arch/x86/include/asm/xen/hypercall.h
> >> +++ b/arch/x86/include/asm/xen/hypercall.h
> >> @@ -214,10 +214,12 @@ privcmd_call(unsigned call,
> >> __HYPERCALL_DECLS;
> >> __HYPERCALL_5ARG(a1, a2, a3, a4, a5);
> >>
> >> + stac();
> >> asm volatile("call *%[call]"
> >> : __HYPERCALL_5PARAM
> >> : [call] "a" (&hypercall_page[call])
> >> : __HYPERCALL_CLOBBER5);
> >> + clac();
> >>
> >> return (long)__res;
> >> }
> > Is there any option to do that from hypervisor side? For example somehow
> > modify copy_from_guest/copy_to_guest? I'm not always controlling the VM
> > kernel (for example sometimes I need to cope with the one from Debian
> > stable).
>
> Not really. (I mean - there is, but it involves deliberately breaking
> SMAP support in Xen.)
>
> This is a guest kernel bug. The guest kernel has used SMAP to say
> "please disallow all userspace accesses", and Xen is respecting this
> when trying to follow the pointer in the hypercall.
Hmm, if that's the case, isn't the above patch also effectively breaking
SMAP? I see the purpose of SMAP is to prevent _accidental_ access to
arbitrary, guest controlled memory. For example because of some memory
corruption bug in the hypervisor. If such a bug could be triggered using
a hypercall, then the above patch also makes SMAP useless. Patching
copy_from_guest/copy_to_guest on the other hand would only allow such
guest controlled memory access when hypervisor is really supposed to
access guest memory.
> This bug doesn't
> manifest for PV guests, and you are probably the first person to do any
> serious hypercall work from HVM userspace.
That's interesting. I'm just trying to use slightly modified
libxenchan...
--
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
[-- Attachment #2: Type: text/plain, Size: 127 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-01-13 20:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-13 17:31 xc_evtchn_status fails with EFAULT on HVM, the same on PV works Marek Marczykowski-Górecki
2017-01-13 17:38 ` Andrew Cooper
2017-01-13 18:03 ` Marek Marczykowski-Górecki
2017-01-13 18:15 ` Andrew Cooper
2017-01-13 18:32 ` Marek Marczykowski-Górecki
2017-01-13 18:37 ` Andrew Cooper
2017-01-13 18:59 ` Marek Marczykowski-Górecki
2017-01-13 19:27 ` Andrew Cooper
2017-01-13 19:40 ` Marek Marczykowski-Górecki
2017-01-13 19:54 ` Andrew Cooper
2017-01-13 20:32 ` Marek Marczykowski-Górecki [this message]
2017-01-14 1:47 ` Andrew Cooper
2017-01-14 2:52 ` Marek Marczykowski-Górecki
2017-01-16 12:17 ` Jan Beulich
2017-01-16 23:06 ` Marek Marczykowski-Górecki
2017-01-16 23:41 ` Andrew Cooper
2017-06-22 8:23 ` Marek Marczykowski-Górecki
2017-06-22 8:27 ` Andrew Cooper
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=20170113203223.GO1341@mail-itl \
--to=marmarek@invisiblethingslab.com \
--cc=andrew.cooper3@citrix.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.