Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Denys Vlasenko
On Thu, Apr 23, 2015 at 8:52 PM, Borislav Petkov wrote: > On Thu, Apr 23, 2015 at 11:24:14AM -0700, Andy Lutomirski wrote: >> That nails it. We really do leak segment limits to other tasks on AMD >> chips. I see at least two questions we should answer before fixing >> this: > > Ok, WTF is going

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Andy Lutomirski
On Thu, Apr 23, 2015 at 11:52 AM, Borislav Petkov wrote: > On Thu, Apr 23, 2015 at 11:24:14AM -0700, Andy Lutomirski wrote: >> That nails it. We really do leak segment limits to other tasks on AMD >> chips. I see at least two questions we should answer before fixing >> this: > > Ok, WTF is going

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Borislav Petkov
On Thu, Apr 23, 2015 at 11:24:14AM -0700, Andy Lutomirski wrote: > That nails it. We really do leak segment limits to other tasks on AMD > chips. I see at least two questions we should answer before fixing > this: Ok, WTF is going on?! Even this trivial test case causes a Bus Error: --- static

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Linus Torvalds
On Thu, Apr 23, 2015 at 11:24 AM, Andy Lutomirski wrote: > > 1. Do we consider this to be enough of a security issue that we want > to fix it for 64-bit userspace as well? > > 2. Do we fix it at sysret time (at the cost of an ss read even in the > best case on AMD chips) or at context switch time

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Andy Lutomirski
On Thu, Apr 23, 2015 at 10:14 AM, Borislav Petkov wrote: > On Thu, Apr 23, 2015 at 09:50:17AM -0700, Andy Lutomirski wrote: >> On Thu, Apr 23, 2015 at 9:41 AM, Denys Vlasenko >> wrote: >> > An alternative fix would be, if we decided to schedule >> > in an interrupt, check %ss for zero and reload

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Borislav Petkov
On Thu, Apr 23, 2015 at 09:50:17AM -0700, Andy Lutomirski wrote: > On Thu, Apr 23, 2015 at 9:41 AM, Denys Vlasenko > wrote: > > An alternative fix would be, if we decided to schedule > > in an interrupt, check %ss for zero and reload it > > with __KERNEL_DS before schedule. > > For anyone who has

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Andy Lutomirski
On Thu, Apr 23, 2015 at 9:41 AM, Denys Vlasenko wrote: > An alternative fix would be, if we decided to schedule > in an interrupt, check %ss for zero and reload it > with __KERNEL_DS before schedule. For anyone who has the right hardware (not me!), a possible reproducer is here: https://git.kern

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Denys Vlasenko
An alternative fix would be, if we decided to schedule in an interrupt, check %ss for zero and reload it with __KERNEL_DS before schedule. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Andy Lutomirski
On Thu, Apr 23, 2015 at 3:44 AM, Borislav Petkov wrote: > On Thu, Apr 23, 2015 at 12:26:43PM +0200, Denys Vlasenko wrote: >> Yes. It loads *selector*. AMD docs say that selector is loaded as you say, >> but *cached descriptor* of SS (which is a different entity) is not modified. >> >> If *cached d

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Denys Vlasenko
On 04/23/2015 02:01 PM, Brian Gerst wrote: > The patch does appear to fix the crash. Thanks for testing it. I changed the patch a bit and sent it to Ingo. Can you test that one and confirm that it also works? -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Brian Gerst
On Thu, Apr 23, 2015 at 7:46 AM, Denys Vlasenko wrote: > On 04/23/2015 01:28 PM, Brian Gerst wrote: >>> Looking at the error message: >>> Unhandled exception: stack overflow in 32-bit code (0xf779bc07). Register dump: CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b EIP:f779bc

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Denys Vlasenko
On 04/23/2015 01:28 PM, Brian Gerst wrote: >> Looking at the error message: >> >>> Unhandled exception: stack overflow in 32-bit code (0xf779bc07). >>> Register dump: >>> CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b >>> EIP:f779bc07 ESP:00aed60c EBP:00aed750 EFLAGS:00010216( R- -- I -A-P-

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Brian Gerst
On Thu, Apr 23, 2015 at 5:20 AM, Denys Vlasenko wrote: > On 04/23/2015 09:37 AM, Brian Gerst wrote: >> On Tue, Mar 31, 2015 at 8:38 AM, tip-bot for Denys Vlasenko >> wrote: >>> Commit-ID: e7d6eefaaa443130079d73cd05039d90b3db7a4a >>> Gitweb: >>> http://git.kernel.org/tip/e7d6eefaaa443130079d

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Denys Vlasenko
On 04/23/2015 09:37 AM, Brian Gerst wrote: > This patch unfortunately is causing Wine to break on some applications: > > Unhandled exception: stack overflow in 32-bit code (0xf779bc07). > Register dump: > CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b > EIP:f779bc07 ESP:00aed60c EBP:00aed750 EF

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Brian Gerst
On Thu, Apr 23, 2015 at 5:56 AM, Borislav Petkov wrote: > On Thu, Apr 23, 2015 at 11:20:56AM +0200, Denys Vlasenko wrote: >> * what if %ss before syscall was NOT the usual value of 0x2b, but some >> other segment, not the typical 0-base, 0x limit 32-bit expand-up one? >> Not restoring prop

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Denys Vlasenko
On 04/23/2015 12:44 PM, Borislav Petkov wrote: > On Thu, Apr 23, 2015 at 12:26:43PM +0200, Denys Vlasenko wrote: >> Yes. It loads *selector*. AMD docs say that selector is loaded as you say, >> but *cached descriptor* of SS (which is a different entity) is not modified. >> >> If *cached descriptor*

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Borislav Petkov
On Thu, Apr 23, 2015 at 12:26:43PM +0200, Denys Vlasenko wrote: > Yes. It loads *selector*. AMD docs say that selector is loaded as you say, > but *cached descriptor* of SS (which is a different entity) is not modified. > > If *cached descriptor* is invalid, in 32-bit mode stack ops > will fail. (

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Denys Vlasenko
On 04/23/2015 12:18 PM, Borislav Petkov wrote: > On Thu, Apr 23, 2015 at 11:56:21AM +0200, Denys Vlasenko wrote: >> The fix can look like this (untested): >> >> >> diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S >> index 0c302d0..9f4c232 100644 >> --- a/arch/x86/ia32/ia32entry.S

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Borislav Petkov
On Thu, Apr 23, 2015 at 11:56:21AM +0200, Denys Vlasenko wrote: > The fix can look like this (untested): > > > diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S > index 0c302d0..9f4c232 100644 > --- a/arch/x86/ia32/ia32entry.S > +++ b/arch/x86/ia32/ia32entry.S > @@ -198,6 +198,18

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Denys Vlasenko
On 04/23/2015 10:49 AM, Andy Lutomirski wrote: > On Thu, Apr 23, 2015 at 12:37 AM, Brian Gerst wrote: >> On Tue, Mar 31, 2015 at 8:38 AM, tip-bot for Denys Vlasenko >> wrote: >>> Commit-ID: e7d6eefaaa443130079d73cd05039d90b3db7a4a >>> Gitweb: >>> http://git.kernel.org/tip/e7d6eefaaa44313007

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Borislav Petkov
On Thu, Apr 23, 2015 at 11:20:56AM +0200, Denys Vlasenko wrote: > * what if %ss before syscall was NOT the usual value of 0x2b, but some > other segment, not the typical 0-base, 0x limit 32-bit expand-up one? > Not restoring proper %ss would not go well. > [but then, Intel CPUs work, and ol

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Borislav Petkov
On Thu, Apr 23, 2015 at 01:49:50AM -0700, Andy Lutomirski wrote: > I'm pretty sure that this is at least a little bit wrong. It makes no > sense for me for syscall to set SS.DPL=0 and for sysret to leave > SS.DPL=0. It had better at least change DPL to 3. (Except... don't > they mean RPL? Why i

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Denys Vlasenko
On 04/23/2015 10:49 AM, Andy Lutomirski wrote: > Would fixing this be as simple as changing this code in > arch/x86/kernel/process.c: > > __visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, cpu_tss) = { > .x86_tss = { > .sp0 = TOP_OF_INIT_STACK, > #ifdef CONFIG_X86_3

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Denys Vlasenko
On 04/23/2015 09:37 AM, Brian Gerst wrote: > On Tue, Mar 31, 2015 at 8:38 AM, tip-bot for Denys Vlasenko > wrote: >> Commit-ID: e7d6eefaaa443130079d73cd05039d90b3db7a4a >> Gitweb: >> http://git.kernel.org/tip/e7d6eefaaa443130079d73cd05039d90b3db7a4a >> Author: Denys Vlasenko >> AuthorDa

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Andy Lutomirski
On Thu, Apr 23, 2015 at 1:49 AM, Andy Lutomirski wrote: > > I'm curious whether we can somehow end up in the kernel without a > sensible SS. What happens if we have SS = 0? > > Try this on for size: > > 1. Wine process does syscall > 2. Context switch to any other task > 3. Interrupt (software or

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Andy Lutomirski
On Thu, Apr 23, 2015 at 12:37 AM, Brian Gerst wrote: > On Tue, Mar 31, 2015 at 8:38 AM, tip-bot for Denys Vlasenko > wrote: >> Commit-ID: e7d6eefaaa443130079d73cd05039d90b3db7a4a >> Gitweb: >> http://git.kernel.org/tip/e7d6eefaaa443130079d73cd05039d90b3db7a4a >> Author: Denys Vlasenko

Re: [tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-04-23 Thread Brian Gerst
On Tue, Mar 31, 2015 at 8:38 AM, tip-bot for Denys Vlasenko wrote: > Commit-ID: e7d6eefaaa443130079d73cd05039d90b3db7a4a > Gitweb: http://git.kernel.org/tip/e7d6eefaaa443130079d73cd05039d90b3db7a4a > Author: Denys Vlasenko > AuthorDate: Fri, 27 Mar 2015 11:48:17 -0700 > Committer: Ingo

[tip:x86/vdso] x86/vdso32/syscall.S: Do not load __USER32_DS to %ss

2015-03-31 Thread tip-bot for Denys Vlasenko
Commit-ID: e7d6eefaaa443130079d73cd05039d90b3db7a4a Gitweb: http://git.kernel.org/tip/e7d6eefaaa443130079d73cd05039d90b3db7a4a Author: Denys Vlasenko AuthorDate: Fri, 27 Mar 2015 11:48:17 -0700 Committer: Ingo Molnar CommitDate: Tue, 31 Mar 2015 10:45:15 +0200 x86/vdso32/syscall.S: Do