[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 02/17] x86: split __{get,put}_user() into "guest" and "unsafe" variants


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 9 Feb 2021 15:46:22 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N9JIbKaduRGh1ym21FJE8LohQOTAqkO2V2Kr77hsM3Q=; b=i0MIdeXXF3NNRlWzULcdrNHZ54QkorOtKn8PAoJDBCwraWRQmU/VLJL6tddWcQnv+FllHsCetCZg/nIFOdqV4aHYt5Lgd7CfU6b4v9hL3A16Tmo01nzWpB5dbTG/6ErhUzJRLW6UNnvFGM6UMX8XBtJFWacMoJZfy7p5IbPTB3TXDBVUoBEGxz9m8zUM1AHtqUltLBmK993B3dhk/xPjt2IeVjcXfkWd7zgtkyV5Db/T5ukzAh1qcWR9T2r1Duo5NvzhKZUesJHD2sWcLUw6UpLqo26Nl5wjWfiCF2uoSpeqaZuWNFRLNR4+KIZC+mrhfaUxZY40Oe1xr7Rv/RndHw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aFITXuqlTYYMKdF+JMvQMBazPDE8W7us8f7E3FN3ufLlxacYVMcROytOotxceQhIXcJiRSw5OTuTHaZoSyyIva39JY5LYmrwcdYU4y7dPmPgxv4tSVStcVuLC2iixEmIcVmuecyllUQlNUPHCDvkJNgNXJ6bCUxS2tERYm3jbrDCr2E3Rws9wTpnaatdKWAaOamuMciVxArjGsSvu/MK1f2+vJBqyx8OcdIJHZlXdBv3oquXpXV+ZhezMauysbG4doUM5Ew8dX1Lf17/ndI5DysZQu/BKwvPpyRFSA69Qczp3WTnDgtR1RqRprc2fxRXH4A4tSASaozcisinUJ7Whw==
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Andrew Cooper" <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Tim Deegan <tim@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>
  • Delivery-date: Tue, 09 Feb 2021 14:46:52 +0000
  • Ironport-sdr: Z/IkgMkbGJyUBjpCsHMCB1dwmcn3cZvER17v5iFt5iBvfDBLokq9tmO1lvutTOOt33rv0cgtS1 GuwN/ckoTHiHFt5xvh4YcM/nhEODcKWINCpwunbs4Nno7ig9MTPdi74OXnbPI7HyZbznqxaHhL N/j6ukVKKErIRoLnRtKKIpY8sik4AGpI8ESYgMG/lViBuhmgUga/JWeSmln6wGmgCONR9I+L5D JrPn+SXEW/0bQFreZyrtMuNTnwfg96x10uWRaTDb56mUt47dowhg2QbEzR0wgq7BHZy4lW3rmP IwU=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, Feb 09, 2021 at 02:15:18PM +0100, Jan Beulich wrote:
> On 09.02.2021 14:07, Roger Pau Monné wrote:
> > On Fri, Feb 05, 2021 at 05:26:33PM +0100, Jan Beulich wrote:
> >> On 05.02.2021 17:18, Roger Pau Monné wrote:
> >>> On Fri, Feb 05, 2021 at 05:13:22PM +0100, Jan Beulich wrote:
> >>>> On 05.02.2021 16:43, Roger Pau Monné wrote:
> >>>>> On Thu, Jan 14, 2021 at 04:04:11PM +0100, Jan Beulich wrote:
> >>>>>> The "guest" variants are intended to work with (potentially) fully 
> >>>>>> guest
> >>>>>> controlled addresses, while the "unsafe" variants are not.
> >>>>>
> >>>>> Just to clarify, both work against user addresses, but guest variants
> >>>>> need to be more careful because the guest provided address can also be
> >>>>> modified?
> >>>>>
> >>>>> I'm trying to understand the difference between "fully guest
> >>>>> controlled" and "guest controlled".
> >>>>
> >>>> Not exactly, not. "unsafe" means access to anything which may
> >>>> fault, guest controlled or not. do_invalid_op()'s reading of
> >>>> the insn stream is a good example - the faulting insn there
> >>>> isn't guest controlled at all, but we still want to be careful
> >>>> when trying to read these bytes, as we don't want to fully
> >>>> trust %rip there.
> > 
> > Oh, I see. It's possible that %rip points to an unmapped address
> > there, and we need to be careful when reading, even if the value of
> > %rip cannot be controlled by the guest and can legitimacy point to
> > Xen's address space.
> > 
> >>> Would it make sense to threat everything as 'guest' accesses for the
> >>> sake of not having this difference?
> >>
> >> That's what we've been doing until now. It is the purpose of
> >> this change to allow the two to behave differently.
> >>
> >>> I think having two accessors it's likely to cause confusion and could
> >>> possibly lead to the wrong one being used in unexpected contexts. Does
> >>> it add a too big performance penalty to always use the most
> >>> restrictive one?
> >>
> >> The problem is the most restrictive one is going to be too
> >> restrictive - we wouldn't be able to access Xen space anymore
> >> e.g. from the place pointed at above as example. This is
> >> because for guest accesses (but not for "unsafe" ones) we're
> >> going to divert them into non-canonical space (and hence make
> >> speculation impossible, as such an access would fault) if it
> >> would touch Xen space.
> > 
> > Yes, I understand now. I think it would have been helpful (for me) to
> > have the first sentence as:
> > 
> > The "guest" variants are intended to work with (potentially) fully guest
> > controlled addresses, while the "unsafe" variants are expected to be
> > used in order to access addresses not under the guest control, but
> > that could trigger faults anyway (like accessing the instruction
> > stream in do_invalid_op).
> 
> I can use some of this, but in particular "access addresses not
> under the guest control" isn't entirely correct. The question isn't
> whether there's a guest control aspect, but which part of the
> address space the addresses are in. See specifically x86/PV: use
> get_unsafe() instead of copy_from_unsafe()" for two pretty good
> examples. The address within the linear page tables are - in a
> way at least - still somewhat guest controlled, but we're
> deliberately accessing Xen virtual addresses there.

OK, could this be somehow added to the commit message then?

Maybe it would be better to have something like:

The "guest" variants are intended to work with addresses belonging to
the guest address space, while the "unsafe" variants should be used
for addresses that fall into the Xen address space.

I think it's important to list exactly how the distinction between the
guest/unsafe accessors is made, or else it's impossible to review that
the changes done here are correct.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.