Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1430346 > unrolled thread
| Started by | Andy Lutomirski <luto@kernel.org> |
|---|---|
| First post | 2016-06-24 06:30 +0200 |
| Last post | 2016-06-24 17:40 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v4 11/16] x86/dumpstack: When OOPSing, rewind the stack before do_exit Andy Lutomirski <luto@kernel.org> - 2016-06-24 06:30 +0200
Re: [PATCH v4 11/16] x86/dumpstack: When OOPSing, rewind the stack before do_exit Brian Gerst <brgerst@gmail.com> - 2016-06-24 17:40 +0200
Re: [PATCH v4 11/16] x86/dumpstack: When OOPSing, rewind the stack before do_exit Josh Poimboeuf <jpoimboe@redhat.com> - 2016-06-24 17:50 +0200
Re: [PATCH v4 11/16] x86/dumpstack: When OOPSing, rewind the stack before do_exit Josh Poimboeuf <jpoimboe@redhat.com> - 2016-06-24 17:40 +0200
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2016-06-24 06:30 +0200 |
| Subject | [PATCH v4 11/16] x86/dumpstack: When OOPSing, rewind the stack before do_exit |
| Message-ID | <rNqUG-3pa-13@gated-at.bofh.it> |
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 <luto@kernel.org>
---
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..0b56666e6039 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-PTREGS_SIZE(%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..b846875aeea6 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-PTREGS_SIZE(%rax), %rsp
+
+ call do_exit
+1: jmp 1b
+END(rewind_stack_do_exit)
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index 70d5aae8b8f7..4592bc4ed3e1 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -226,6 +226,8 @@ unsigned long oops_begin(void)
EXPORT_SYMBOL_GPL(oops_begin);
NOKPROBE_SYMBOL(oops_begin);
+extern void __noreturn rewind_stack_do_exit(int signr);
+
void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
{
if (regs && kexec_should_crash(current))
@@ -245,12 +247,15 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
return;
if (in_interrupt())
panic("Fatal exception in interrupt");
- if (((current_stack_pointer() ^ (current_top_of_stack() - 1))
- & ~(THREAD_SIZE - 1)) != 0)
- panic("Fatal exception on special stack");
if (panic_on_oops)
panic("Fatal exception");
- do_exit(signr);
+
+ /*
+ * We're not going to return, but we might be on an IST stack or
+ * have very little stack space left. Rewind the stack and kill
+ * the task.
+ */
+ rewind_stack_do_exit(signr);
}
NOKPROBE_SYMBOL(oops_end);
--
2.5.5
[toc] | [next] | [standalone]
| From | Brian Gerst <brgerst@gmail.com> |
|---|---|
| Date | 2016-06-24 17:40 +0200 |
| Subject | Re: [PATCH v4 11/16] x86/dumpstack: When OOPSing, rewind the stack before do_exit |
| Message-ID | <rNBn4-1op-21@gated-at.bofh.it> |
| In reply to | #1430346 |
On Fri, Jun 24, 2016 at 11:30 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote: > On Thu, Jun 23, 2016 at 09:23:06PM -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 <luto@kernel.org> >> --- >> 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..0b56666e6039 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-PTREGS_SIZE(%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..b846875aeea6 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 > > s/ebp/rbp/g/ ? No, this quirk of the x86-64 instruction set will zero-extend to 64-bits without needing a REX prefix. -- Brian Gerst
[toc] | [prev] | [next] | [standalone]
| From | Josh Poimboeuf <jpoimboe@redhat.com> |
|---|---|
| Date | 2016-06-24 17:50 +0200 |
| Subject | Re: [PATCH v4 11/16] x86/dumpstack: When OOPSing, rewind the stack before do_exit |
| Message-ID | <rNBwK-1xi-5@gated-at.bofh.it> |
| In reply to | #1430767 |
On Fri, Jun 24, 2016 at 11:35:13AM -0400, Brian Gerst wrote: > On Fri, Jun 24, 2016 at 11:30 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote: > > On Thu, Jun 23, 2016 at 09:23:06PM -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 <luto@kernel.org> > >> --- > >> 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..0b56666e6039 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-PTREGS_SIZE(%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..b846875aeea6 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 > > > > s/ebp/rbp/g/ ? > > No, this quirk of the x86-64 instruction set will zero-extend to > 64-bits without needing a REX prefix. Ah, so it makes the instruction smaller. And I see that gcc also does the same. In that case: Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com> -- Josh
[toc] | [prev] | [next] | [standalone]
| From | Josh Poimboeuf <jpoimboe@redhat.com> |
|---|---|
| Date | 2016-06-24 17:40 +0200 |
| Subject | Re: [PATCH v4 11/16] x86/dumpstack: When OOPSing, rewind the stack before do_exit |
| Message-ID | <rNBn4-1op-23@gated-at.bofh.it> |
| In reply to | #1430346 |
On Thu, Jun 23, 2016 at 09:23:06PM -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 <luto@kernel.org> > --- > 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..0b56666e6039 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-PTREGS_SIZE(%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..b846875aeea6 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 s/ebp/rbp/g/ ? -- Josh
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web