x86/unwind: Create stack frames for saved syscall registers
authorJosh Poimboeuf <jpoimboe@redhat.com>
Thu, 20 Oct 2016 16:34:41 +0000 (11:34 -0500)
committerIngo Molnar <mingo@kernel.org>
Fri, 21 Oct 2016 07:26:04 +0000 (09:26 +0200)
The entry code doesn't encode the pt_regs pointer for syscalls.  But the
pt_regs are always at the same location, so we can add a manual check
for them.

A later patch prints them as part of the oops stack dump.  They could be
useful, for example, to determine the arguments to a system call.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/e176aa9272930cd3f51fda0b94e2eae356677da4.1476973742.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/kernel/unwind_frame.c

index 2221ab1678c52cee3cf653365f7d94283e8e5864..579542736b7edbf6e00abfcbbfc4f4c95a1b5e1f 100644 (file)
@@ -24,6 +24,14 @@ unsigned long unwind_get_return_address(struct unwind_state *state)
 }
 EXPORT_SYMBOL_GPL(unwind_get_return_address);
 
+static bool is_last_task_frame(struct unwind_state *state)
+{
+       unsigned long bp = (unsigned long)state->bp;
+       unsigned long regs = (unsigned long)task_pt_regs(state->task);
+
+       return bp == regs - FRAME_HEADER_SIZE;
+}
+
 /*
  * This determines if the frame pointer actually contains an encoded pointer to
  * pt_regs on the stack.  See ENCODE_FRAME_POINTER.
@@ -71,6 +79,33 @@ bool unwind_next_frame(struct unwind_state *state)
        if (state->regs && user_mode(state->regs))
                goto the_end;
 
+       if (is_last_task_frame(state)) {
+               regs = task_pt_regs(state->task);
+
+               /*
+                * kthreads (other than the boot CPU's idle thread) have some
+                * partial regs at the end of their stack which were placed
+                * there by copy_thread_tls().  But the regs don't have any
+                * useful information, so we can skip them.
+                *
+                * This user_mode() check is slightly broader than a PF_KTHREAD
+                * check because it also catches the awkward situation where a
+                * newly forked kthread transitions into a user task by calling
+                * do_execve(), which eventually clears PF_KTHREAD.
+                */
+               if (!user_mode(regs))
+                       goto the_end;
+
+               /*
+                * We're almost at the end, but not quite: there's still the
+                * syscall regs frame.  Entry code doesn't encode the regs
+                * pointer for syscalls, so we have to set it manually.
+                */
+               state->regs = regs;
+               state->bp = NULL;
+               return true;
+       }
+
        /* get the next frame pointer */
        if (state->regs)
                next_bp = (unsigned long *)state->regs->bp;