[PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with %cr3

2017-12-16 Thread Sai Praneeth Prakhya
From: Sai Praneeth Use helper function (efi_switch_mm()) to switch to/from efi_mm. We switch to efi_mm before calling 1. efi_set_virtual_address_map() and 2. Invoking any efi_runtime_service() Likewise, we need to switch back to previous mm (mm context stolen by efi_mm) after the above calls ret

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-25 Thread Andy Lutomirski
On Thu, Aug 24, 2017 at 7:36 PM, Sai Praneeth Prakhya wrote: > On Tue, 2017-08-15 at 14:46 -0700, Andy Lutomirski wrote: >> On Tue, Aug 15, 2017 at 12:18 PM, Sai Praneeth Prakhya >> wrote: >> > +/* >> > + * Makes the calling kernel thread switch to/from efi_mm context >> > + * Can be used from Se

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-25 Thread Andy Lutomirski
On Wed, Aug 23, 2017 at 3:52 PM, Sai Praneeth Prakhya wrote: > On Mon, 2017-08-21 at 08:23 -0700, Andy Lutomirski wrote: >> >> > On Aug 21, 2017, at 7:08 AM, Peter Zijlstra wrote: >> > >> >> On Mon, Aug 21, 2017 at 06:56:01AM -0700, Andy Lutomirski wrote: >> >> >> >> >> >>> On Aug 21, 2017, at 3:

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-24 Thread Sai Praneeth Prakhya
On Tue, 2017-08-15 at 14:46 -0700, Andy Lutomirski wrote: > On Tue, Aug 15, 2017 at 12:18 PM, Sai Praneeth Prakhya > wrote: > > +/* > > + * Makes the calling kernel thread switch to/from efi_mm context > > + * Can be used from SetVirtualAddressMap() or during efi runtime calls > > + * (Note: This

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-23 Thread Sai Praneeth Prakhya
On Mon, 2017-08-21 at 08:23 -0700, Andy Lutomirski wrote: > > > On Aug 21, 2017, at 7:08 AM, Peter Zijlstra wrote: > > > >> On Mon, Aug 21, 2017 at 06:56:01AM -0700, Andy Lutomirski wrote: > >> > >> > >>> On Aug 21, 2017, at 3:33 AM, Peter Zijlstra wrote: > > > > Using a kernel th

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-21 Thread Peter Zijlstra
On Mon, Aug 21, 2017 at 06:56:01AM -0700, Andy Lutomirski wrote: > There are two ways this could be a problem. One is that u privileged > user apps shouldn't be able to read from EFI memory. The other is > that, if EFI were to have IO memory mapped at a "user" address, perf > could end up reading

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-21 Thread Ard Biesheuvel
On 21 August 2017 at 16:59, Peter Zijlstra wrote: > On Mon, Aug 21, 2017 at 08:23:10AM -0700, Andy Lutomirski wrote: >> > Ah, but only root can create per-cpu events or attach events to kernel >> > threads (with sensible paranoia levels). >> >> But this may not need to be percpu. If a non root us

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-21 Thread Peter Zijlstra
On Mon, Aug 21, 2017 at 08:23:10AM -0700, Andy Lutomirski wrote: > > Ah, but only root can create per-cpu events or attach events to kernel > > threads (with sensible paranoia levels). > > But this may not need to be percpu. If a non root user can trigger, say, an > EFI variable read in their ow

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-21 Thread Andy Lutomirski
> On Aug 21, 2017, at 7:08 AM, Peter Zijlstra wrote: > >> On Mon, Aug 21, 2017 at 06:56:01AM -0700, Andy Lutomirski wrote: >> >> >>> On Aug 21, 2017, at 3:33 AM, Peter Zijlstra wrote: > Using a kernel thread solves the problem for real. Anything that blindly accesses user m

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-21 Thread Peter Zijlstra
On Mon, Aug 21, 2017 at 06:56:01AM -0700, Andy Lutomirski wrote: > > > > On Aug 21, 2017, at 3:33 AM, Peter Zijlstra wrote: > >> > >> Using a kernel thread solves the problem for real. Anything that > >> blindly accesses user memory in kernel thread context is terminally > >> broken no matter

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-21 Thread Andy Lutomirski
> On Aug 21, 2017, at 3:33 AM, Peter Zijlstra wrote: > >> On Thu, Aug 17, 2017 at 08:52:38AM -0700, Andy Lutomirski wrote: >> On Thu, Aug 17, 2017 at 3:35 AM, Will Deacon wrote: > >>> I'm still concerned that we're treating perf specially here -- are we >>> absolutely sure that nobody else is

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-21 Thread Peter Zijlstra
On Thu, Aug 17, 2017 at 08:52:38AM -0700, Andy Lutomirski wrote: > On Thu, Aug 17, 2017 at 3:35 AM, Will Deacon wrote: > > I'm still concerned that we're treating perf specially here -- are we > > absolutely sure that nobody else is going to attempt user accesses off the > > back of an interrupt?

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-17 Thread Andy Lutomirski
On Thu, Aug 17, 2017 at 3:35 AM, Will Deacon wrote: > On Tue, Aug 15, 2017 at 11:35:41PM +0100, Mark Rutland wrote: >> On Wed, Aug 16, 2017 at 09:14:41AM -0700, Andy Lutomirski wrote: >> > On Wed, Aug 16, 2017 at 5:57 AM, Matt Fleming >> > wrote: >> > > On Wed, 16 Aug, at 12:03:22PM, Mark Rutlan

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-17 Thread Will Deacon
On Tue, Aug 15, 2017 at 11:35:41PM +0100, Mark Rutland wrote: > On Wed, Aug 16, 2017 at 09:14:41AM -0700, Andy Lutomirski wrote: > > On Wed, Aug 16, 2017 at 5:57 AM, Matt Fleming > > wrote: > > > On Wed, 16 Aug, at 12:03:22PM, Mark Rutland wrote: > > >> > > >> I'd expect we'd abort at a higher le

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-16 Thread Mark Rutland
On Wed, Aug 16, 2017 at 09:14:41AM -0700, Andy Lutomirski wrote: > On Wed, Aug 16, 2017 at 5:57 AM, Matt Fleming > wrote: > > On Wed, 16 Aug, at 12:03:22PM, Mark Rutland wrote: > >> > >> I'd expect we'd abort at a higher level, not taking any sample. i.e. > >> we'd have the core overflow handler

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-16 Thread Andy Lutomirski
On Wed, Aug 16, 2017 at 5:57 AM, Matt Fleming wrote: > On Wed, 16 Aug, at 12:03:22PM, Mark Rutland wrote: >> >> I'd expect we'd abort at a higher level, not taking any sample. i.e. >> we'd have the core overflow handler check in_funny_mm(), and if so, skip >> the sample, as with the skid case. > >

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-16 Thread Matt Fleming
On Wed, 16 Aug, at 12:03:22PM, Mark Rutland wrote: > > I'd expect we'd abort at a higher level, not taking any sample. i.e. > we'd have the core overflow handler check in_funny_mm(), and if so, skip > the sample, as with the skid case. FYI, this is my preferred solution for x86 too. -- To unsubsc

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-16 Thread Mark Rutland
On Wed, Aug 16, 2017 at 11:07:10AM +0100, Will Deacon wrote: > On Wed, Aug 16, 2017 at 10:53:38AM +0100, Mark Rutland wrote: > > On Wed, Aug 16, 2017 at 10:31:12AM +0100, Ard Biesheuvel wrote: > > > (+ Mark, Will) > > > > > > On 15 August 2017 at 22:46, Andy Lutomirski wrote: > > > > On Tue, Aug

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-16 Thread Will Deacon
On Wed, Aug 16, 2017 at 10:53:38AM +0100, Mark Rutland wrote: > On Wed, Aug 16, 2017 at 10:31:12AM +0100, Ard Biesheuvel wrote: > > (+ Mark, Will) > > > > On 15 August 2017 at 22:46, Andy Lutomirski wrote: > > > On Tue, Aug 15, 2017 at 12:18 PM, Sai Praneeth Prakhya > > > wrote: > > >> +/* > > >

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-16 Thread Mark Rutland
On Wed, Aug 16, 2017 at 10:31:12AM +0100, Ard Biesheuvel wrote: > (+ Mark, Will) > > On 15 August 2017 at 22:46, Andy Lutomirski wrote: > > On Tue, Aug 15, 2017 at 12:18 PM, Sai Praneeth Prakhya > > wrote: > >> +/* > >> + * Makes the calling kernel thread switch to/from efi_mm context > >> + * C

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-16 Thread Ard Biesheuvel
(+ Mark, Will) On 15 August 2017 at 22:46, Andy Lutomirski wrote: > On Tue, Aug 15, 2017 at 12:18 PM, Sai Praneeth Prakhya > wrote: >> +/* >> + * Makes the calling kernel thread switch to/from efi_mm context >> + * Can be used from SetVirtualAddressMap() or during efi runtime calls >> + * (Note:

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-15 Thread Andy Lutomirski
On Tue, Aug 15, 2017 at 5:23 PM, Sai Praneeth Prakhya wrote: > On Tue, 2017-08-15 at 14:46 -0700, Andy Lutomirski wrote: >> On Tue, Aug 15, 2017 at 12:18 PM, Sai Praneeth Prakhya >> wrote: >> > +/* >> > + * Makes the calling kernel thread switch to/from efi_mm context >> > + * Can be used from Se

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-15 Thread Sai Praneeth Prakhya
On Tue, 2017-08-15 at 14:46 -0700, Andy Lutomirski wrote: > On Tue, Aug 15, 2017 at 12:18 PM, Sai Praneeth Prakhya > wrote: > > +/* > > + * Makes the calling kernel thread switch to/from efi_mm context > > + * Can be used from SetVirtualAddressMap() or during efi runtime calls > > + * (Note: This

Re: [PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-15 Thread Andy Lutomirski
On Tue, Aug 15, 2017 at 12:18 PM, Sai Praneeth Prakhya wrote: > +/* > + * Makes the calling kernel thread switch to/from efi_mm context > + * Can be used from SetVirtualAddressMap() or during efi runtime calls > + * (Note: This routine is heavily inspired from use_mm) > + */ > +void efi_switch_mm(

[PATCH 3/3] x86/efi: Use efi_switch_mm() rather than manually twiddling with cr3

2017-08-15 Thread Sai Praneeth Prakhya
From: Sai Praneeth Use helper function (efi_switch_mm()) to switch to/from efi_mm. We switch to efi_mm before calling 1. efi_set_virtual_address_map() and 2. Invoking any efi_runtime_service() Likewise, we need to switch back to previous mm (mm context stolen by efi_mm) after the above calls ret