From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755019AbcFPRuk (ORCPT ); Thu, 16 Jun 2016 13:50:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56391 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754021AbcFPRui (ORCPT ); Thu, 16 Jun 2016 13:50:38 -0400 Date: Thu, 16 Jun 2016 12:50:36 -0500 From: Josh Poimboeuf To: Andy Lutomirski Cc: "linux-kernel@vger.kernel.org" , x86@kernel.org, Borislav Petkov , Nadav Amit , Kees Cook , Brian Gerst , "kernel-hardening@lists.openwall.com" , Linus Torvalds Subject: Re: [PATCH 08/13] x86/dumpstack: When OOPSing, rewind the stack before do_exit Message-ID: <20160616175036.uoks47kizfavkwzk@treble> References: <4e7adb96a576c6ff12d6cc2a972b2bf44ed2319a.1466036668.git.luto@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4e7adb96a576c6ff12d6cc2a972b2bf44ed2319a.1466036668.git.luto@kernel.org> User-Agent: Mutt/1.6.0.1 (2016-04-01) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 16 Jun 2016 17:50:38 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 15, 2016 at 05:28:30PM -0700, Andy Lutomirski wrote: > If we call do_exit with a clean stack, we greatly reduce the risk of > recursive oopses due to stack overflow in do_exit, and we allow > do_exit to work even if we OOPS from an IST stack. The latter gives > us a much better chance of surviving long enough after we detect a > stack overflow to write out our logs. > > I intentionally separated this from the preceding patch that > disables do_exit-on-OOPS on IST stacks. This way, if we need to > revert this patch, we still end up in an acceptable state wrt stack > overflow handling. > > Signed-off-by: Andy Lutomirski > --- > arch/x86/entry/entry_32.S | 11 +++++++++++ > arch/x86/entry/entry_64.S | 11 +++++++++++ > arch/x86/kernel/dumpstack.c | 13 +++++++++---- > 3 files changed, 31 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S > index 983e5d3a0d27..1499db695a88 100644 > --- a/arch/x86/entry/entry_32.S > +++ b/arch/x86/entry/entry_32.S > @@ -1153,3 +1153,14 @@ ENTRY(async_page_fault) > jmp error_code > END(async_page_fault) > #endif > + > +ENTRY(rewind_stack_do_exit) > + /* Prevent any naive code from trying to unwind to our caller. */ > + xorl %ebp, %ebp > + > + movl PER_CPU_VAR(cpu_current_top_of_stack), %esi > + leal -TOP_OF_KERNEL_STACK_PADDING-PT_OLDSS(%esi), %esp > + > + call do_exit > +1: jmp 1b > +END(rewind_stack_do_exit) > diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S > index 9ee0da1807ed..394cad73e890 100644 > --- a/arch/x86/entry/entry_64.S > +++ b/arch/x86/entry/entry_64.S > @@ -1423,3 +1423,14 @@ ENTRY(ignore_sysret) > mov $-ENOSYS, %eax > sysret > END(ignore_sysret) > + > +ENTRY(rewind_stack_do_exit) > + /* Prevent any naive code from trying to unwind to our caller. */ > + xorl %ebp, %ebp > + > + movq PER_CPU_VAR(cpu_current_top_of_stack), %rax > + leaq -TOP_OF_KERNEL_STACK_PADDING-SS(%rax), %rsp I think this should be: leaq -TOP_OF_KERNEL_STACK_PADDING-SIZEOF_PTREGS, %rsp That way when it calls do_exit(), the stack frame will be placed at the conventional spot where a smart unwinder would expect to find it. -- Josh