From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753546AbaEUWhY (ORCPT ); Wed, 21 May 2014 18:37:24 -0400 Received: from terminus.zytor.com ([198.137.202.10]:42924 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753431AbaEUWhV (ORCPT ); Wed, 21 May 2014 18:37:21 -0400 Message-ID: <537D2A6A.2@zytor.com> Date: Wed, 21 May 2014 15:36:26 -0700 From: "H. Peter Anvin" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Andy Lutomirski , Steven Rostedt , "linux-kernel@vger.kernel.org" CC: Linus Torvalds , Ingo Molnar , Thomas Gleixner , Borislav Petkov , Andi Kleen Subject: Re: [RFC] x86_64: A real proposal for iret-less return to kernel References: In-Reply-To: X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/21/2014 11:11 AM, Andy Lutomirski wrote: > On Tue, May 20, 2014 at 5:53 PM, Andy Lutomirski wrote: >> Here's a real proposal for iret-less return. If this is correct, then >> NMIs will never nest, which will probably delete a lot more scariness >> than is added by the code I'm describing. > > OK, here's a case where I'm wrong. An NMI interrupts userspace on a > 16-bit stack. The return from NMI goes through the espfix code. > Something interrupts while on the espfix stack. Boom! Neither return > style is particularly good. > > More generally, if we got interrupted while on the espfix stack, we > need to return back there using IRET. Fortunately, re-enabling NMIs > there in harmless, since we've already switched off the NMI stack. > > This makes me think that maybe the logic should be turned around: have > some RIP ranges on which the kernel stack might be invalid (which > includes the espfix code and some of the syscall code) and use IRET > only on return from NMI, return to nonstandard CS, and return to these > special ranges. The NMI code just needs to never so any of this stuff > unless it switches off the NMI stack first. > > For this to work reliably, we'll probably have to change CS before > calling into EFI code. That should be straightforward. > I think you are onto something here. In particular, the key observation here is that inside the kernel, we can never *both* have an invalid stack *and* be inside an NMI, #MC or #DB handler, even if nested. Now, does this prevent us from using RET in the common case? I'm not sure it is a huge loss since kernel-to-kernel is relatively rare. -hpa