Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-29 Thread Andy Lutomirski
On Mar 28, 2015 6:17 AM, "Denys Vlasenko" wrote: > > On Sat, Mar 28, 2015 at 10:46 AM, Ingo Molnar wrote: > > * Denys Vlasenko wrote: > >> This is a C function. [...] > > > > Arguably that's a self-inflicted wound of uclibc: nothing keeps it > > from taking advantage of the syscall ABI and

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-29 Thread Andy Lutomirski
On Mar 28, 2015 6:17 AM, Denys Vlasenko vda.li...@googlemail.com wrote: On Sat, Mar 28, 2015 at 10:46 AM, Ingo Molnar mi...@kernel.org wrote: * Denys Vlasenko vda.li...@googlemail.com wrote: This is a C function. [...] Arguably that's a self-inflicted wound of uclibc: nothing keeps it

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Denys Vlasenko
On Sat, Mar 28, 2015 at 10:46 AM, Ingo Molnar wrote: > * Denys Vlasenko wrote: >> This is a C function. [...] > > Arguably that's a self-inflicted wound of uclibc: nothing keeps it > from taking advantage of the syscall ABI and avoiding the double > save/restores. It's not uclibc who calls

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Denys Vlasenko
On Sat, Mar 28, 2015 at 1:39 AM, Linus Torvalds wrote: > What part of "don't leak kernel data" did you have trouble understanding? > > IOW, this is a *security* issue. Stop arguing for crazy shit. We can zero the registers instead of saving/restoring them. push/pop pair takes 1-2 cycles at best,

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Ingo Molnar
* Denys Vlasenko wrote: > On Fri, Mar 27, 2015 at 9:00 PM, Linus Torvalds > wrote: > > On Fri, Mar 27, 2015 at 7:25 AM, Denys Vlasenko wrote: > >> > >> Apparently, users *don't* depend on arithmetic flags > >> to survive over syscall. They also okay with DF flag > >> being cleared. > > > >

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Borislav Petkov
On Fri, Mar 27, 2015 at 01:09:34PM -0700, Linus Torvalds wrote: > I think AMD documented that the sti "interrupt shadow" shadows even > NMI. Hmm, official docs says this: "15.21.5 Interrupt Shadows The x86 architecture defines the notion of an interrupt shadow—a single-instruction window during

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Ingo Molnar
* Linus Torvalds wrote: > On Fri, Mar 27, 2015 at 1:53 PM, Brian Gerst wrote: > >> <-- IRQ. Boom > > > > The sti will delay interrupts for one instruction, and that should include > > NMIs. > > Nope. Intel explicitly documents the NMI case only for mov->ss and popss. > > > The Intel SDM

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Olivier Galibert
Hi, Beware that could be opening the door to information leaks for a very small gain (most syscalls are not getuid). Best, OG. On Sat, Mar 28, 2015 at 1:34 AM, Denys Vlasenko wrote: > On Fri, Mar 27, 2015 at 9:00 PM, Linus Torvalds > wrote: >> On Fri, Mar 27, 2015 at 7:25 AM, Denys

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Ingo Molnar
* Linus Torvalds wrote: > On Fri, Mar 27, 2015 at 1:53 PM, Brian Gerst wrote: > >> <-- IRQ. Boom > > > > The sti will delay interrupts for one instruction, and that should include > > NMIs. > > Nope. Intel explicitly documents the NMI case only for mov->ss and popss. Interestingly, I still

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Denys Vlasenko
On Sat, Mar 28, 2015 at 10:46 AM, Ingo Molnar mi...@kernel.org wrote: * Denys Vlasenko vda.li...@googlemail.com wrote: This is a C function. [...] Arguably that's a self-inflicted wound of uclibc: nothing keeps it from taking advantage of the syscall ABI and avoiding the double

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Denys Vlasenko
On Sat, Mar 28, 2015 at 1:39 AM, Linus Torvalds torva...@linux-foundation.org wrote: What part of don't leak kernel data did you have trouble understanding? IOW, this is a *security* issue. Stop arguing for crazy shit. We can zero the registers instead of saving/restoring them. push/pop pair

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Ingo Molnar
* Linus Torvalds torva...@linux-foundation.org wrote: On Fri, Mar 27, 2015 at 1:53 PM, Brian Gerst brge...@gmail.com wrote: -- IRQ. Boom The sti will delay interrupts for one instruction, and that should include NMIs. Nope. Intel explicitly documents the NMI case only for mov-ss

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Olivier Galibert
Hi, Beware that could be opening the door to information leaks for a very small gain (most syscalls are not getuid). Best, OG. On Sat, Mar 28, 2015 at 1:34 AM, Denys Vlasenko vda.li...@googlemail.com wrote: On Fri, Mar 27, 2015 at 9:00 PM, Linus Torvalds torva...@linux-foundation.org

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Borislav Petkov
On Fri, Mar 27, 2015 at 01:09:34PM -0700, Linus Torvalds wrote: I think AMD documented that the sti interrupt shadow shadows even NMI. Hmm, official docs says this: 15.21.5 Interrupt Shadows The x86 architecture defines the notion of an interrupt shadow—a single-instruction window during

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Ingo Molnar
* Denys Vlasenko vda.li...@googlemail.com wrote: On Fri, Mar 27, 2015 at 9:00 PM, Linus Torvalds torva...@linux-foundation.org wrote: On Fri, Mar 27, 2015 at 7:25 AM, Denys Vlasenko dvlas...@redhat.com wrote: Apparently, users *don't* depend on arithmetic flags to survive over syscall.

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-28 Thread Ingo Molnar
* Linus Torvalds torva...@linux-foundation.org wrote: On Fri, Mar 27, 2015 at 1:53 PM, Brian Gerst brge...@gmail.com wrote: -- IRQ. Boom The sti will delay interrupts for one instruction, and that should include NMIs. Nope. Intel explicitly documents the NMI case only for mov-ss

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Denys Vlasenko
On Fri, Mar 27, 2015 at 9:00 PM, Linus Torvalds wrote: > On Fri, Mar 27, 2015 at 7:25 AM, Denys Vlasenko wrote: >> >> Apparently, users *don't* depend on arithmetic flags >> to survive over syscall. They also okay with DF flag >> being cleared. > > Generally, users probably dont' care about many

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Andy Lutomirski
On Fri, Mar 27, 2015 at 1:31 PM, Linus Torvalds wrote: > On Fri, Mar 27, 2015 at 1:16 PM, Andy Lutomirski wrote: >> >> Does it matter on 32-bit kernels? There's no swapgs, so IRQs should >> still be safe, and we have a real stack pointer before sysexit. > > Fair enough. On 32-bit, the only

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Linus Torvalds
On Fri, Mar 27, 2015 at 1:53 PM, Brian Gerst wrote: >> <-- IRQ. Boom > > The sti will delay interrupts for one instruction, and that should include > NMIs. Nope. Intel explicitly documents the NMI case only for mov->ss and popss. > The Intel SDM states for STI: > "The IF flag and the STI and

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Brian Gerst
On Fri, Mar 27, 2015 at 2:37 PM, Andy Lutomirski wrote: > On Mar 27, 2015 7:26 AM, "Denys Vlasenko" wrote: >> >> Hi, >> >> While running some tests I noticed that EFLAGS >> is not saved across syscalls if I use 32-bit >> userspace, use SYSENTER, and paravirt is active. >> >> Looking at the code,

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Linus Torvalds
On Fri, Mar 27, 2015 at 1:16 PM, Andy Lutomirski wrote: > > Does it matter on 32-bit kernels? There's no swapgs, so IRQs should > still be safe, and we have a real stack pointer before sysexit. Fair enough. On 32-bit, the only worry is the race between "return to user space" and "something set

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Andy Lutomirski
On Fri, Mar 27, 2015 at 1:09 PM, Linus Torvalds wrote: > On Fri, Mar 27, 2015 at 11:37 AM, Andy Lutomirski wrote: >> >> User does sysenter. We end up in native_irq_enable_sysexit. We do: >> >> swapgs >> sti >> >> <-- NMI here can happen on some (all?) cpus, returns successfully >> *with

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Linus Torvalds
On Fri, Mar 27, 2015 at 11:37 AM, Andy Lutomirski wrote: > > User does sysenter. We end up in native_irq_enable_sysexit. We do: > > swapgs > sti > > <-- NMI here can happen on some (all?) cpus, returns successfully > *with interrupts unmasked* I think AMD documented that the sti "interrupt

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Linus Torvalds
On Fri, Mar 27, 2015 at 7:25 AM, Denys Vlasenko wrote: > > Apparently, users *don't* depend on arithmetic flags > to survive over syscall. They also okay with DF flag > being cleared. Generally, users probably dont' care about many registers at all being saved, but it's worth noting that the

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Andy Lutomirski
On Mar 27, 2015 7:26 AM, "Denys Vlasenko" wrote: > > Hi, > > While running some tests I noticed that EFLAGS > is not saved across syscalls if I use 32-bit > userspace, use SYSENTER, and paravirt is active. > > Looking at the code, it's actually clear why that happens. > > /* > * SYSENTER loads

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Borislav Petkov
+ Linus. On Fri, Mar 27, 2015 at 03:25:47PM +0100, Denys Vlasenko wrote: > Hi, > > While running some tests I noticed that EFLAGS > is not saved across syscalls if I use 32-bit > userspace, use SYSENTER, and paravirt is active. > > Looking at the code, it's actually clear why that happens. > >

ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Denys Vlasenko
Hi, While running some tests I noticed that EFLAGS is not saved across syscalls if I use 32-bit userspace, use SYSENTER, and paravirt is active. Looking at the code, it's actually clear why that happens. /* * SYSENTER loads ss, rsp, cs, and rip from previously programmed MSRs. * IF and VM in

ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Denys Vlasenko
Hi, While running some tests I noticed that EFLAGS is not saved across syscalls if I use 32-bit userspace, use SYSENTER, and paravirt is active. Looking at the code, it's actually clear why that happens. /* * SYSENTER loads ss, rsp, cs, and rip from previously programmed MSRs. * IF and VM in

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Borislav Petkov
+ Linus. On Fri, Mar 27, 2015 at 03:25:47PM +0100, Denys Vlasenko wrote: Hi, While running some tests I noticed that EFLAGS is not saved across syscalls if I use 32-bit userspace, use SYSENTER, and paravirt is active. Looking at the code, it's actually clear why that happens. /* *

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Linus Torvalds
On Fri, Mar 27, 2015 at 7:25 AM, Denys Vlasenko dvlas...@redhat.com wrote: Apparently, users *don't* depend on arithmetic flags to survive over syscall. They also okay with DF flag being cleared. Generally, users probably dont' care about many registers at all being saved, but it's worth

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Linus Torvalds
On Fri, Mar 27, 2015 at 11:37 AM, Andy Lutomirski l...@amacapital.net wrote: User does sysenter. We end up in native_irq_enable_sysexit. We do: swapgs sti -- NMI here can happen on some (all?) cpus, returns successfully *with interrupts unmasked* I think AMD documented that the sti

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Linus Torvalds
On Fri, Mar 27, 2015 at 1:16 PM, Andy Lutomirski l...@amacapital.net wrote: Does it matter on 32-bit kernels? There's no swapgs, so IRQs should still be safe, and we have a real stack pointer before sysexit. Fair enough. On 32-bit, the only worry is the race between return to user space and

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Andy Lutomirski
On Fri, Mar 27, 2015 at 1:09 PM, Linus Torvalds torva...@linux-foundation.org wrote: On Fri, Mar 27, 2015 at 11:37 AM, Andy Lutomirski l...@amacapital.net wrote: User does sysenter. We end up in native_irq_enable_sysexit. We do: swapgs sti -- NMI here can happen on some (all?) cpus,

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Andy Lutomirski
On Mar 27, 2015 7:26 AM, Denys Vlasenko dvlas...@redhat.com wrote: Hi, While running some tests I noticed that EFLAGS is not saved across syscalls if I use 32-bit userspace, use SYSENTER, and paravirt is active. Looking at the code, it's actually clear why that happens. /* * SYSENTER

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Linus Torvalds
On Fri, Mar 27, 2015 at 1:53 PM, Brian Gerst brge...@gmail.com wrote: -- IRQ. Boom The sti will delay interrupts for one instruction, and that should include NMIs. Nope. Intel explicitly documents the NMI case only for mov-ss and popss. The Intel SDM states for STI: The IF flag and the

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Andy Lutomirski
On Fri, Mar 27, 2015 at 1:31 PM, Linus Torvalds torva...@linux-foundation.org wrote: On Fri, Mar 27, 2015 at 1:16 PM, Andy Lutomirski l...@amacapital.net wrote: Does it matter on 32-bit kernels? There's no swapgs, so IRQs should still be safe, and we have a real stack pointer before sysexit.

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Brian Gerst
On Fri, Mar 27, 2015 at 2:37 PM, Andy Lutomirski l...@amacapital.net wrote: On Mar 27, 2015 7:26 AM, Denys Vlasenko dvlas...@redhat.com wrote: Hi, While running some tests I noticed that EFLAGS is not saved across syscalls if I use 32-bit userspace, use SYSENTER, and paravirt is active.

Re: ia32_sysenter_target does not preserve EFLAGS

2015-03-27 Thread Denys Vlasenko
On Fri, Mar 27, 2015 at 9:00 PM, Linus Torvalds torva...@linux-foundation.org wrote: On Fri, Mar 27, 2015 at 7:25 AM, Denys Vlasenko dvlas...@redhat.com wrote: Apparently, users *don't* depend on arithmetic flags to survive over syscall. They also okay with DF flag being cleared. Generally,