|
Message-ID: <CAPcyv4i5oORdk-Fzypxw_+gCLUa8f=w1e_n0=47P7uHR-jT6GQ@mail.gmail.com> Date: Tue, 6 Feb 2018 12:37:54 -0800 From: Dan Williams <dan.j.williams@...el.com> To: Linus Torvalds <torvalds@...ux-foundation.org> Cc: Luis Henriques <lhenriques@...e.com>, Linux Kernel Mailing List <linux-kernel@...r.kernel.org>, linux-arch <linux-arch@...r.kernel.org>, Kernel Hardening <kernel-hardening@...ts.openwall.com>, Greg KH <gregkh@...uxfoundation.org>, X86 ML <x86@...nel.org>, Ingo Molnar <mingo@...hat.com>, Andy Lutomirski <luto@...nel.org>, "H. Peter Anvin" <hpa@...or.com>, Thomas Gleixner <tglx@...utronix.de>, Andrew Morton <akpm@...ux-foundation.org>, Alan Cox <alan@...ux.intel.com> Subject: Re: [PATCH v4 07/10] x86: narrow out of bounds syscalls to sys_read under speculation On Tue, Feb 6, 2018 at 12:26 PM, Linus Torvalds <torvalds@...ux-foundation.org> wrote: > On Tue, Feb 6, 2018 at 11:48 AM, Dan Williams <dan.j.williams@...el.com> wrote: >> >> Just to clarify, when you say "this patch" you mean: >> >> 2fbd7af5af86 x86/syscall: Sanitize syscall table de-references >> under speculation >> >> ...not this early MASK_NOSPEC version of the patch, right? > > I suspect not. If that patch is broken, the system wouldn't even boot. > > That said, looking at 2fbd7af5af86, I do note that the code generation > is horribly stupid. > > It's due to two different issues: > > (a) the x86 asm constraints for that inline asm is nasty, and > requires a register for 'size', even though an immediate works just > fine. > > (b) the "cmp" is inside the asm, so gcc can't combine it with the > *other* cmp in the C code. > > Fixing (a) is easy: > > +++ b/arch/x86/include/asm/barrier.h > @@ -43 +43 @@ static inline unsigned long > array_index_mask_nospec(unsigned long index, > - :"r"(size),"r" (index) > + :"ir"(size),"r" (index) > > but fixing (b) looks fundamentally hard. Gcc generates (for do_syscall()): > > cmpq $332, %rbp #, nr > ja .L295 #, > cmp $333,%rbp > sbb %rax,%rax; #, nr, mask > > note how it completely pointlessly does the comparison twice, even > though it could have just done > > cmp $333,%rbp > jae .L295 #, > sbb %rax,%rax; #, nr, mask > > Ho humm. Sad. Are there any compilers that would miscompile: mask = 0 - (index < size); That might be a way to improve the assembly.
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.