Skip to content

Commit 0a264d8

Browse files
jpoimboegregkh
authored andcommitted
x86/unwind/fp: Fix FP unwinding in ret_from_fork
[ Upstream commit 6f9885a ] 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: b9f6976 ("x86/entry/64: Move non entry code into .text section") Reported-by: Naresh Kamboju <[email protected]> Reported-by: Logan Gunthorpe <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/f366bbf5a8d02e2318ee312f738112d0af74d16f.1600103007.git.jpoimboe@redhat.com Signed-off-by: Sasha Levin <[email protected]>
1 parent ce2b5fe commit 0a264d8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

arch/x86/include/asm/frame.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,26 @@
6060
#define FRAME_END "pop %" _ASM_BP "\n"
6161

6262
#ifdef CONFIG_X86_64
63+
6364
#define ENCODE_FRAME_POINTER \
6465
"lea 1(%rsp), %rbp\n\t"
66+
67+
static inline unsigned long encode_frame_pointer(struct pt_regs *regs)
68+
{
69+
return (unsigned long)regs + 1;
70+
}
71+
6572
#else /* !CONFIG_X86_64 */
73+
6674
#define ENCODE_FRAME_POINTER \
6775
"movl %esp, %ebp\n\t" \
6876
"andl $0x7fffffff, %ebp\n\t"
77+
78+
static inline unsigned long encode_frame_pointer(struct pt_regs *regs)
79+
{
80+
return (unsigned long)regs & 0x7fffffff;
81+
}
82+
6983
#endif /* CONFIG_X86_64 */
7084

7185
#endif /* __ASSEMBLY__ */
@@ -83,6 +97,11 @@
8397

8498
#define ENCODE_FRAME_POINTER
8599

100+
static inline unsigned long encode_frame_pointer(struct pt_regs *regs)
101+
{
102+
return 0;
103+
}
104+
86105
#endif
87106

88107
#define FRAME_BEGIN

arch/x86/kernel/process.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <asm/spec-ctrl.h>
4343
#include <asm/io_bitmap.h>
4444
#include <asm/proto.h>
45+
#include <asm/frame.h>
4546

4647
#include "process.h"
4748

@@ -133,7 +134,7 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp,
133134
fork_frame = container_of(childregs, struct fork_frame, regs);
134135
frame = &fork_frame->frame;
135136

136-
frame->bp = 0;
137+
frame->bp = encode_frame_pointer(childregs);
137138
frame->ret_addr = (unsigned long) ret_from_fork;
138139
p->thread.sp = (unsigned long) fork_frame;
139140
p->thread.io_bitmap = NULL;

0 commit comments

Comments
 (0)