From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933420AbaDVRAt (ORCPT ); Tue, 22 Apr 2014 13:00:49 -0400 Received: from mail-vc0-f175.google.com ([209.85.220.175]:55041 "EHLO mail-vc0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932854AbaDVRAr (ORCPT ); Tue, 22 Apr 2014 13:00:47 -0400 MIME-Version: 1.0 In-Reply-To: References: <5355A9E9.9070102@zytor.com> <1dbe8155-58da-45c2-9dc0-d9f4b5a6e643@email.android.com> <20140422112312.GB15882@pd.tnic> <20140422144659.GF15882@pd.tnic> <53569467.1030809@zytor.com> From: Andrew Lutomirski Date: Tue, 22 Apr 2014 10:00:26 -0700 Message-ID: Subject: Re: [PATCH] x86-64: espfix for 64-bit mode *PROTOTYPE* To: Linus Torvalds Cc: "H. Peter Anvin" , Borislav Petkov , "H. Peter Anvin" , Linux Kernel Mailing List , Ingo Molnar , Alexander van Heukelum , Konrad Rzeszutek Wilk , Boris Ostrovsky , Arjan van de Ven , Brian Gerst , Alexandre Julliard , Andi Kleen , Thomas Gleixner Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 22, 2014 at 9:43 AM, Linus Torvalds wrote: > On Tue, Apr 22, 2014 at 9:33 AM, Andrew Lutomirski wrote: >> >> For the espfix_adjust_stack thing, when can it actually need to do >> anything? irqs should be off, I think, and MCE, NMI, and debug >> exceptions use ist, so that leaves just #SS and #GP, I think. How can >> those actually occur? Is there a way to trigger them deliberately >> from userspace? Why do you have three espfix_adjust_stack > > Yes, you can very much trigger GP deliberately. > > The way to do it is to just make an invalid segment descriptor on the > iret stack. Or make it a valid 16-bit one, but make it a code segment > for the stack pointer, or read-only, or whatever. All of which is > trivial to do with a sigretun system call. But you can do it other > ways too - enter with a SS that is valid, but do a load_ldt() system > call that makes it invalid, so that by the time you exit it is no > longer valid etc. > > There's a reason we mark that "iretq" as taking faults with that > > _ASM_EXTABLE(native_iret, bad_iret) > > and that "bad_iret" creates a GP fault. > > And that's a lot of kernel stack. The whole initial GP fault path, > which goes to the C code that finds the exception table etc. See > do_general_protection_fault() and fixup_exception(). My point is that it may be safe to remove the special espfix fixup from #PF, which is probably the most performance-critical piece here, aside from iret itself. --Andy