From: Andy Lutomirski <luto@kernel.org>
To: X86 ML <x86@kernel.org>
Cc: Borislav Petkov <bpetkov@suse.de>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Brian Gerst <brgerst@gmail.com>,
Dave Hansen <dave.hansen@intel.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Andy Lutomirski <luto@kernel.org>
Subject: [PATCH] x86/orc: Don't bail on stack overflow
Date: Sat, 25 Nov 2017 09:28:36 -0800 [thread overview]
Message-ID: <7b2c3ad96fb62afbc095bd7ba8a93022480153cb.1511630836.git.luto@kernel.org> (raw)
If we overflow the stack into a guard page and then try to unwind
it with ORC, it should work perfectly: by construction, there can't
be any meaningful data in the guard page because no writes to the
guard page will have succeeded.
ORC seems entirely capable of unwinding in this situation, except
that it doesn't even try. Adjust its initial stack check so that
it's willing to try unwinding.
I tested this by intentionally overflowing the task stack. The
result is an accurate call trace instead of a trace consisting
purely of '?' entries.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
Hi all-
Ingo, this would have fixed half the debugging problem you had, I think.
To really nail it, we'd want some kind of magic to annotate the trace
so that page_fault (and async_page_fault) entries show CR2 and error_code.
Josh, any ideas of how to do that cleanly? We could easily hard-code it
in the OOPS unwinder, I guess.
arch/x86/kernel/unwind_orc.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
index a3f973b2c97a..7f6e3935666b 100644
--- a/arch/x86/kernel/unwind_orc.c
+++ b/arch/x86/kernel/unwind_orc.c
@@ -553,8 +553,18 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,
}
if (get_stack_info((unsigned long *)state->sp, state->task,
- &state->stack_info, &state->stack_mask))
- return;
+ &state->stack_info, &state->stack_mask)) {
+ /*
+ * We weren't on a valid stack. It's possible that
+ * we overflowed a valid stack into a guard page.
+ * See if the next page up is valid so that we can
+ * generate some kind of backtrace if this happens.
+ */
+ void *next_page = (void *)PAGE_ALIGN((unsigned long)regs->sp);
+ if (get_stack_info(next_page, state->task, &state->stack_info,
+ &state->stack_mask))
+ return;
+ }
/*
* The caller can provide the address of the first frame directly
--
2.13.6
next reply other threads:[~2017-11-25 17:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-25 17:28 Andy Lutomirski [this message]
2017-11-25 18:26 ` Andy Lutomirski
2017-11-25 23:13 ` Thomas Gleixner
2017-11-26 0:16 ` Andy Lutomirski
2017-11-26 2:40 ` Josh Poimboeuf
2017-11-26 4:25 ` Andy Lutomirski
2017-11-26 4:41 ` Josh Poimboeuf
2017-11-26 4:48 ` Josh Poimboeuf
2017-11-26 9:27 ` Thomas Gleixner
2017-11-27 9:38 ` Ingo Molnar
2017-11-27 9:49 ` Ingo Molnar
2017-11-27 12:45 ` Josh Poimboeuf
2017-11-27 13:13 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7b2c3ad96fb62afbc095bd7ba8a93022480153cb.1511630836.git.luto@kernel.org \
--to=luto@kernel.org \
--cc=bpetkov@suse.de \
--cc=brgerst@gmail.com \
--cc=dave.hansen@intel.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome