Commit 6f9885a3 authored by Josh Poimboeuf's avatar Josh Poimboeuf Committed by Borislav Petkov

x86/unwind/fp: Fix FP unwinding in ret_from_fork

There have been some reports of "bad bp value" warnings printed by the
frame pointer unwinder:

  WARNING: kernel stack regs at 000000005bac7112 in sh:1014 has bad 'bp' value 0000000000000000

This warning happens when unwinding from an interrupt in
ret_from_fork(). If entry code gets interrupted, the state of the
frame pointer (rbp) may be undefined, which can confuse the unwinder,
resulting in warnings like the above.

There's an in_entry_code() check which normally silences such
warnings for entry code. But in this case, ret_from_fork() is getting
interrupted. It recently got moved out of .entry.text, so the
in_entry_code() check no longer works.

It could be moved back into .entry.text, but that would break the
noinstr validation because of the call to schedule_tail().

Instead, initialize each new task's RBP to point to the task's entry
regs via an encoded frame pointer.  That will allow the unwinder to
reach the end of the stack gracefully.

Fixes: b9f6976b ("x86/entry/64: Move non entry code into .text section")
Reported-by: default avatarNaresh Kamboju <naresh.kamboju@linaro.org>
Reported-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/f366bbf5a8d02e2318ee312f738112d0af74d16f.1600103007.git.jpoimboe@redhat.com
parent 09e43968
...@@ -60,12 +60,26 @@ ...@@ -60,12 +60,26 @@
#define FRAME_END "pop %" _ASM_BP "\n" #define FRAME_END "pop %" _ASM_BP "\n"
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
#define ENCODE_FRAME_POINTER \ #define ENCODE_FRAME_POINTER \
"lea 1(%rsp), %rbp\n\t" "lea 1(%rsp), %rbp\n\t"
static inline unsigned long encode_frame_pointer(struct pt_regs *regs)
{
return (unsigned long)regs + 1;
}
#else /* !CONFIG_X86_64 */ #else /* !CONFIG_X86_64 */
#define ENCODE_FRAME_POINTER \ #define ENCODE_FRAME_POINTER \
"movl %esp, %ebp\n\t" \ "movl %esp, %ebp\n\t" \
"andl $0x7fffffff, %ebp\n\t" "andl $0x7fffffff, %ebp\n\t"
static inline unsigned long encode_frame_pointer(struct pt_regs *regs)
{
return (unsigned long)regs & 0x7fffffff;
}
#endif /* CONFIG_X86_64 */ #endif /* CONFIG_X86_64 */
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
...@@ -83,6 +97,11 @@ ...@@ -83,6 +97,11 @@
#define ENCODE_FRAME_POINTER #define ENCODE_FRAME_POINTER
static inline unsigned long encode_frame_pointer(struct pt_regs *regs)
{
return 0;
}
#endif #endif
#define FRAME_BEGIN #define FRAME_BEGIN
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <asm/spec-ctrl.h> #include <asm/spec-ctrl.h>
#include <asm/io_bitmap.h> #include <asm/io_bitmap.h>
#include <asm/proto.h> #include <asm/proto.h>
#include <asm/frame.h>
#include "process.h" #include "process.h"
...@@ -133,7 +134,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg, ...@@ -133,7 +134,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg,
fork_frame = container_of(childregs, struct fork_frame, regs); fork_frame = container_of(childregs, struct fork_frame, regs);
frame = &fork_frame->frame; frame = &fork_frame->frame;
frame->bp = 0; frame->bp = encode_frame_pointer(childregs);
frame->ret_addr = (unsigned long) ret_from_fork; frame->ret_addr = (unsigned long) ret_from_fork;
p->thread.sp = (unsigned long) fork_frame; p->thread.sp = (unsigned long) fork_frame;
p->thread.io_bitmap = NULL; p->thread.io_bitmap = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment