ORC fixes
Subsystems (4)
v2 cover ORC fixes
v2:
- Dropped three patches which technically weren't fixes. Will post them later as part of another patch set with more improvements.
- Removed show_iret_regs() declaration [mbenes]
- Added Miroslav Reviewed-by, Linus Reported-by
v1 was here:
https://lkml.kernel.org/r/[email protected]
Jann Horn (1):
x86/entry/64: Fix unwind hints in rewind_stack_do_exit()
Josh Poimboeuf (9):
objtool: Fix stack offset tracking for indirect CFAs x86/entry/64: Fix unwind hints in register clearing code x86/entry/64: Fix unwind hints in kernel exit path x86/entry/64: Fix unwind hints in __switch_to_asm() x86/unwind/orc: Convert global variables to static x86/unwind: Prevent false warnings for non-current tasks x86/unwind/orc: Prevent unwinding before ORC initialization x86/unwind/orc: Fix error path for bad ORC entry type x86/unwind/orc: Fix premature unwind stoppage due to IRET frames
Miroslav Benes (1):
x86/unwind/orc: Don't skip the first frame for inactive tasks
arch/x86/entry/calling.h | 40 ++++++------ arch/x86/entry/entry_64.S | 14 ++--- arch/x86/include/asm/unwind.h | 2 +- arch/x86/kernel/dumpstack_64.c | 3 +- arch/x86/kernel/unwind_frame.c | 3 + arch/x86/kernel/unwind_orc.c | 111 ++++++++++++++++++++++----------- tools/objtool/check.c | 2 +- 7 files changed, 108 insertions(+), 67 deletions(-)
Signature · 1 line
2.21.1
PATCH v2 1/11 objtool: Fix stack offset tracking for indirect CFAs
When the current frame address (CFA) is stored on the stack (i.e., cfa->base == CFI_SP_INDIRECT), objtool neglects to adjust the stack offset when there are subsequent pushes or pops. This results in bad ORC data at the end of the ENTER_IRQ_STACK macro, when it puts the previous stack pointer on the stack and does a subsequent push.
This fixes the following unwinder warning:
WARNING: can't dereference registers at 00000000f0a6bdba for ip interrupt_entry+0x9f/0xa0
--- tools/objtool/check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/objtool/check.c +1 -1
@@ -1550,7 +1550,7 @@ static int update_cfi_state_regs(struct instruction *insn, {struct cfi_reg *cfa = &cfi->cfa; -if (cfa->base !=CFI_SP ) +if (cfa->base !=CFI_SP && cfa->base !=CFI_SP_INDIRECT )return 0 ;/* push */
Signature · 1 line
2.21.1
[tip: x86/urgent] objtool: Fix stack offset tracking for indirect CFAs
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: d8dd25a461e4eec7190cb9d66616aceacc5110ad Gitweb: https://git.kernel.org/tip/d8dd25a461e4eec7190cb9d66616aceacc5110ad Author: Josh Poimboeuf <[email protected]> AuthorDate: Sat, 25 Apr 2020 05:03:00 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 25 Apr 2020 12:22:27 +02:00
objtool: Fix stack offset tracking for indirect CFAs
When the current frame address (CFA) is stored on the stack (i.e., cfa->base == CFI_SP_INDIRECT), objtool neglects to adjust the stack offset when there are subsequent pushes or pops. This results in bad ORC data at the end of the ENTER_IRQ_STACK macro, when it puts the previous stack pointer on the stack and does a subsequent push.
This fixes the following unwinder warning:
WARNING: can't dereference registers at 00000000f0a6bdba for ip interrupt_entry+0x9f/0xa0
--- tools/objtool/check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/objtool/check.c +1 -1
@@ -1449,7 +1449,7 @@ static int update_insn_state_regs(struct instruction *insn, struct insn_state *sstruct cfi_reg *cfa = &state->cfa;struct stack_op *op = &insn->stack_op; -if (cfa->base !=CFI_SP ) +if (cfa->base !=CFI_SP && cfa->base !=CFI_SP_INDIRECT )return 0 ;/* push */
PATCH v2 2/11 x86/entry/64: Fix unwind hints in register clearing code
In reply to Josh PoimboeufThe PUSH_AND_CLEAR_REGS macro zeroes each register immediately after pushing it. If an NMI or exception hits after a register is cleared, but before the UNWIND_HINT_REGS annotation, the ORC unwinder will wrongly think the previous value of the register was zero. This can confuse the unwinding process and cause it to exit early.
Because ORC is simpler than DWARF, there are a limited number of unwind annotation states, so it's not possible to add an individual unwind hint after each push/clear combination. Instead, the register clearing instructions need to be consolidated and moved to after the UNWIND_HINT_REGS annotation.
--- arch/x86/entry/calling.h | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-)
arch/x86/entry/calling.h +21 -19
@@ -98,13 +98,6 @@ For 32-bit we have the following conventions - kernel is built with#define SIZEOF_PTREGS 21*8 .macro PUSH_AND_CLEAR_REGS rdx=%rdx rax=%rax save_ret=0 -/* -* Push registers and sanitize registers of values that a -* speculation attack might otherwise want to exploit. The -* lower registers are likely clobbered well before they -* could be put to use in a speculative execution gadget. -* Interleave XOR with PUSH for better uop scheduling: -*/ .if \save_ret pushq %rsi /* pt_regs->si */ movq 8(%rsp), %rsi /* temporarily store the return address in %rsi */
@@ -114,34 +107,43 @@ For 32-bit we have the following conventions - kernel is built with pushq %rsi/* pt_regs->si */ .endif pushq \rdx /* pt_regs->dx */ - xorl %edx, %edx /* nospec dx */ pushq %rcx /* pt_regs->cx */ - xorl %ecx, %ecx /* nospec cx */ pushq \rax /* pt_regs->ax */ pushq %r8 /* pt_regs->r8 */ - xorl %r8d, %r8d /* nospec r8 */ pushq %r9 /* pt_regs->r9 */ - xorl %r9d, %r9d /* nospec r9 */ pushq %r10 /* pt_regs->r10 */ - xorl %r10d, %r10d /* nospec r10 */ pushq %r11 /* pt_regs->r11 */ - xorl %r11d, %r11d /* nospec r11*/ pushq %rbx /* pt_regs->rbx */ - xorl %ebx, %ebx /* nospec rbx*/ pushq %rbp /* pt_regs->rbp */ - xorl %ebp, %ebp /* nospec rbp*/ pushq %r12 /* pt_regs->r12 */ - xorl %r12d, %r12d /* nospec r12*/ pushq %r13 /* pt_regs->r13 */ - xorl %r13d, %r13d /* nospec r13*/ pushq %r14 /* pt_regs->r14 */ - xorl %r14d, %r14d /* nospec r14*/ pushq %r15 /* pt_regs->r15 */ - xorl %r15d, %r15d /* nospec r15*/UNWIND_HINT_REGS + .if \save_ret pushq %rsi /* return address on top of stack */ .endif + +/* +* Sanitize registers of values that a speculation attack might +* otherwise want to exploit. The lower registers are likely clobbered +* well before they could be put to use in a speculative execution +* gadget. +*/ + xorl %edx, %edx /* nospec dx */ + xorl %ecx, %ecx /* nospec cx */ + xorl %r8d, %r8d /* nospec r8 */ + xorl %r9d, %r9d /* nospec r9 */ + xorl %r10d, %r10d /* nospec r10 */ + xorl %r11d, %r11d /* nospec r11 */ + xorl %ebx, %ebx /* nospec rbx */ + xorl %ebp, %ebp /* nospec rbp */ + xorl %r12d, %r12d /* nospec r12 */ + xorl %r13d, %r13d /* nospec r13 */ + xorl %r14d, %r14d /* nospec r14 */ + xorl %r15d, %r15d /* nospec r15 */ + .endm .macro POP_REGS pop_rdi=1 skip_r11rcx=0
Signature · 1 line
2.21.1
[tip: x86/urgent] x86/entry/64: Fix unwind hints in register clearing code
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 06a9750edcffa808494d56da939085c35904e618 Gitweb: https://git.kernel.org/tip/06a9750edcffa808494d56da939085c35904e618 Author: Josh Poimboeuf <[email protected]> AuthorDate: Sat, 25 Apr 2020 05:03:01 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 25 Apr 2020 12:22:27 +02:00
x86/entry/64: Fix unwind hints in register clearing code
The PUSH_AND_CLEAR_REGS macro zeroes each register immediately after pushing it. If an NMI or exception hits after a register is cleared, but before the UNWIND_HINT_REGS annotation, the ORC unwinder will wrongly think the previous value of the register was zero. This can confuse the unwinding process and cause it to exit early.
Because ORC is simpler than DWARF, there are a limited number of unwind annotation states, so it's not possible to add an individual unwind hint after each push/clear combination. Instead, the register clearing instructions need to be consolidated and moved to after the UNWIND_HINT_REGS annotation.
--- arch/x86/entry/calling.h | 40 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-)
arch/x86/entry/calling.h +21 -19
@@ -98,13 +98,6 @@ For 32-bit we have the following conventions - kernel is built with#define SIZEOF_PTREGS 21*8 .macro PUSH_AND_CLEAR_REGS rdx=%rdx rax=%rax save_ret=0 -/* -* Push registers and sanitize registers of values that a -* speculation attack might otherwise want to exploit. The -* lower registers are likely clobbered well before they -* could be put to use in a speculative execution gadget. -* Interleave XOR with PUSH for better uop scheduling: -*/ .if \save_ret pushq %rsi /* pt_regs->si */ movq 8(%rsp), %rsi /* temporarily store the return address in %rsi */
@@ -114,34 +107,43 @@ For 32-bit we have the following conventions - kernel is built with pushq %rsi/* pt_regs->si */ .endif pushq \rdx /* pt_regs->dx */ - xorl %edx, %edx /* nospec dx */ pushq %rcx /* pt_regs->cx */ - xorl %ecx, %ecx /* nospec cx */ pushq \rax /* pt_regs->ax */ pushq %r8 /* pt_regs->r8 */ - xorl %r8d, %r8d /* nospec r8 */ pushq %r9 /* pt_regs->r9 */ - xorl %r9d, %r9d /* nospec r9 */ pushq %r10 /* pt_regs->r10 */ - xorl %r10d, %r10d /* nospec r10 */ pushq %r11 /* pt_regs->r11 */ - xorl %r11d, %r11d /* nospec r11*/ pushq %rbx /* pt_regs->rbx */ - xorl %ebx, %ebx /* nospec rbx*/ pushq %rbp /* pt_regs->rbp */ - xorl %ebp, %ebp /* nospec rbp*/ pushq %r12 /* pt_regs->r12 */ - xorl %r12d, %r12d /* nospec r12*/ pushq %r13 /* pt_regs->r13 */ - xorl %r13d, %r13d /* nospec r13*/ pushq %r14 /* pt_regs->r14 */ - xorl %r14d, %r14d /* nospec r14*/ pushq %r15 /* pt_regs->r15 */ - xorl %r15d, %r15d /* nospec r15*/UNWIND_HINT_REGS + .if \save_ret pushq %rsi /* return address on top of stack */ .endif + +/* +* Sanitize registers of values that a speculation attack might +* otherwise want to exploit. The lower registers are likely clobbered +* well before they could be put to use in a speculative execution +* gadget. +*/ + xorl %edx, %edx /* nospec dx */ + xorl %ecx, %ecx /* nospec cx */ + xorl %r8d, %r8d /* nospec r8 */ + xorl %r9d, %r9d /* nospec r9 */ + xorl %r10d, %r10d /* nospec r10 */ + xorl %r11d, %r11d /* nospec r11 */ + xorl %ebx, %ebx /* nospec rbx */ + xorl %ebp, %ebp /* nospec rbp */ + xorl %r12d, %r12d /* nospec r12 */ + xorl %r13d, %r13d /* nospec r13 */ + xorl %r14d, %r14d /* nospec r14 */ + xorl %r15d, %r15d /* nospec r15 */ + .endm .macro POP_REGS pop_rdi=1 skip_r11rcx=0
PATCH v2 3/11 x86/entry/64: Fix unwind hints in kernel exit path
In reply to Josh PoimboeufIn swapgs_restore_regs_and_return_to_usermode, after the stack is switched to the trampoline stack, the existing UNWIND_HINT_REGS hint is no longer valid, which can result in the following ORC unwinder warning:
WARNING: can't dereference registers at 000000003aeb0cdd for ip swapgs_restore_regs_and_return_to_usermode+0x93/0xa0
For full correctness, we could try to add complicated unwind hints so the unwinder could continue to find the registers, but when when it's this close to kernel exit, unwind hints aren't really needed anymore and it's fine to just use an empty hint which tells the unwinder to stop.
For consistency, also move the UNWIND_HINT_EMPTY in entry_SYSCALL_64_after_hwframe to a similar location.
--- arch/x86/entry/entry_64.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/entry/entry_64.S +2 -1
@@ -249,7 +249,6 @@ SYM_INNER_LABEL(entry_SYSCALL_64_after_hwframe, SYM_L_GLOBAL) */ syscall_return_via_sysret: /* rcx and r11 are already restored (see code above) */ - UNWIND_HINT_EMPTY POP_REGS pop_rdi=0 skip_r11rcx=1 /*
@@ -258,6 +257,7 @@ syscall_return_via_sysret: */ movq %rsp, %rdi movq PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %rsp + UNWIND_HINT_EMPTY pushq RSP-RDI(%rdi) /* RSP */ pushq (%rdi) /* RDI */
@@ -637,6 +637,7 @@ SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_usermode, SYM_L_GLOBAL) */ movq %rsp, %rdi movq PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %rsp + UNWIND_HINT_EMPTY /* Copy the IRET frame to the trampoline stack. */ pushq 6*8(%rdi) /* SS */
Signature · 1 line
2.21.1
[tip: x86/urgent] x86/entry/64: Fix unwind hints in kernel exit path
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 1fb143634a38095b641a3a21220774799772dc4c Gitweb: https://git.kernel.org/tip/1fb143634a38095b641a3a21220774799772dc4c Author: Josh Poimboeuf <[email protected]> AuthorDate: Sat, 25 Apr 2020 05:03:02 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 25 Apr 2020 12:22:27 +02:00
x86/entry/64: Fix unwind hints in kernel exit path
In swapgs_restore_regs_and_return_to_usermode, after the stack is switched to the trampoline stack, the existing UNWIND_HINT_REGS hint is no longer valid, which can result in the following ORC unwinder warning:
WARNING: can't dereference registers at 000000003aeb0cdd for ip swapgs_restore_regs_and_return_to_usermode+0x93/0xa0
For full correctness, we could try to add complicated unwind hints so the unwinder could continue to find the registers, but when when it's this close to kernel exit, unwind hints aren't really needed anymore and it's fine to just use an empty hint which tells the unwinder to stop.
For consistency, also move the UNWIND_HINT_EMPTY in entry_SYSCALL_64_after_hwframe to a similar location.
--- arch/x86/entry/entry_64.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/entry/entry_64.S +2 -1
@@ -249,7 +249,6 @@ SYM_INNER_LABEL(entry_SYSCALL_64_after_hwframe, SYM_L_GLOBAL) */ syscall_return_via_sysret: /* rcx and r11 are already restored (see code above) */ - UNWIND_HINT_EMPTY POP_REGS pop_rdi=0 skip_r11rcx=1 /*
@@ -258,6 +257,7 @@ syscall_return_via_sysret: */ movq %rsp, %rdi movq PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %rsp + UNWIND_HINT_EMPTY pushq RSP-RDI(%rdi) /* RSP */ pushq (%rdi) /* RDI */
@@ -637,6 +637,7 @@ SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_usermode, SYM_L_GLOBAL) */ movq %rsp, %rdi movq PER_CPU_VAR(cpu_tss_rw + TSS_sp0), %rsp + UNWIND_HINT_EMPTY /* Copy the IRET frame to the trampoline stack. */ pushq 6*8(%rdi) /* SS */
PATCH v2 4/11 x86/entry/64: Fix unwind hints in __switch_to_asm()
In reply to Josh PoimboeufUNWIND_HINT_FUNC has some limitations: specifically, it doesn't reset all the registers to undefined. This causes objtool to get confused about the RBP push in __switch_to_asm(), resulting in bad ORC data.
While __switch_to_asm() does do some stack magic, it's otherwise a normal callable-from-C function, so just annotate it as a function, which makes objtool happy and allows it to produces the correct hints automatically.
--- arch/x86/entry/entry_64.S | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/entry/entry_64.S +2 -3
@@ -279,8 +279,7 @@ SYM_CODE_END(entry_SYSCALL_64) * %rdi: prev task * %rsi: next task */ -SYM_CODE_START(__switch_to_asm) - UNWIND_HINT_FUNC +SYM_FUNC_START(__switch_to_asm) /* * Save callee-saved registers * This must match the order in inactive_task_frame
@@ -321,7 +320,7 @@ SYM_CODE_START(__switch_to_asm) popq %rbp jmp __switch_to -SYM_CODE_END(__switch_to_asm) +SYM_FUNC_END(__switch_to_asm) /* * A newly forked process directly context switches into this address.
Signature · 1 line
2.21.1
[tip: x86/urgent] x86/entry/64: Fix unwind hints in __switch_to_asm()
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 96c64806b4bf35f5edb465cafa6cec490e424a30 Gitweb: https://git.kernel.org/tip/96c64806b4bf35f5edb465cafa6cec490e424a30 Author: Josh Poimboeuf <[email protected]> AuthorDate: Sat, 25 Apr 2020 05:03:03 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 25 Apr 2020 12:22:28 +02:00
x86/entry/64: Fix unwind hints in __switch_to_asm()
UNWIND_HINT_FUNC has some limitations: specifically, it doesn't reset all the registers to undefined. This causes objtool to get confused about the RBP push in __switch_to_asm(), resulting in bad ORC data.
While __switch_to_asm() does do some stack magic, it's otherwise a normal callable-from-C function, so just annotate it as a function, which makes objtool happy and allows it to produces the correct hints automatically.
--- arch/x86/entry/entry_64.S | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/entry/entry_64.S +2 -3
@@ -279,8 +279,7 @@ SYM_CODE_END(entry_SYSCALL_64) * %rdi: prev task * %rsi: next task */ -SYM_CODE_START(__switch_to_asm) - UNWIND_HINT_FUNC +SYM_FUNC_START(__switch_to_asm) /* * Save callee-saved registers * This must match the order in inactive_task_frame
@@ -321,7 +320,7 @@ SYM_CODE_START(__switch_to_asm) popq %rbp jmp __switch_to -SYM_CODE_END(__switch_to_asm) +SYM_FUNC_END(__switch_to_asm) /* * A newly forked process directly context switches into this address.
PATCH v2 5/11 x86/entry/64: Fix unwind hints in rewind_stack_do_exit()
In reply to Josh PoimboeufFrom: Jann Horn <[email protected]>
The leaq instruction in rewind_stack_do_exit moves the stack pointer directly below the pt_regs at the top of the task stack before calling do_exit(). Tell the unwinder to expect pt_regs.
--- arch/x86/entry/entry_64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/entry/entry_64.S +1 -1
@@ -1739,7 +1739,7 @@ SYM_CODE_START(rewind_stack_do_exit) movq PER_CPU_VAR(cpu_current_top_of_stack), %rax leaq -PTREGS_SIZE(%rax), %rsp - UNWIND_HINT_FUNC sp_offset=PTREGS_SIZE + UNWIND_HINT_REGS call do_exit SYM_CODE_END(rewind_stack_do_exit)
Signature · 1 line
2.21.1
[tip: x86/urgent] x86/entry/64: Fix unwind hints in rewind_stack_do_exit()
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: f977df7b7ca45a4ac4b66d30a8931d0434c394b1 Gitweb: https://git.kernel.org/tip/f977df7b7ca45a4ac4b66d30a8931d0434c394b1 Author: Jann Horn <[email protected]> AuthorDate: Sat, 25 Apr 2020 05:03:04 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 25 Apr 2020 12:22:28 +02:00
x86/entry/64: Fix unwind hints in rewind_stack_do_exit()
The LEAQ instruction in rewind_stack_do_exit() moves the stack pointer directly below the pt_regs at the top of the task stack before calling do_exit(). Tell the unwinder to expect pt_regs.
--- arch/x86/entry/entry_64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/entry/entry_64.S +1 -1
@@ -1739,7 +1739,7 @@ SYM_CODE_START(rewind_stack_do_exit) movq PER_CPU_VAR(cpu_current_top_of_stack), %rax leaq -PTREGS_SIZE(%rax), %rsp - UNWIND_HINT_FUNC sp_offset=PTREGS_SIZE + UNWIND_HINT_REGS call do_exit SYM_CODE_END(rewind_stack_do_exit)
PATCH v2 6/11 x86/unwind/orc: Convert global variables to static
In reply to Josh PoimboeufThese variables aren't used outside of unwind_orc.c, make them static.
Also annotate some of them with '__ro_after_init', as applicable.
--- arch/x86/kernel/unwind_orc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/kernel/unwind_orc.c +5 -5
@@ -15,12 +15,12 @@ extern int __stop_orc_unwind_ip[];extern struct orc_entry __start_orc_unwind[];extern struct orc_entry __stop_orc_unwind[]; -static DEFINE_MUTEX (sort_mutex); -int *cur_orc_ip_table = __start_orc_unwind_ip; -struct orc_entry *cur_orc_table = __start_orc_unwind; +static bool orc_init__ro_after_init ; +static unsigned int lookup_num_blocks__ro_after_init ; -unsigned int lookup_num_blocks; -bool orc_init; +static DEFINE_MUTEX (sort_mutex); +static int *cur_orc_ip_table = __start_orc_unwind_ip; +static struct orc_entry *cur_orc_table = __start_orc_unwind;static inline unsigned long orc_ip (const int *ip) {
Signature · 1 line
2.21.1
[tip: x86/urgent] x86/unwind/orc: Convert global variables to static
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 153eb2223c794251b28400f3f74862e090d23f16 Gitweb: https://git.kernel.org/tip/153eb2223c794251b28400f3f74862e090d23f16 Author: Josh Poimboeuf <[email protected]> AuthorDate: Sat, 25 Apr 2020 05:03:05 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 25 Apr 2020 12:22:28 +02:00
x86/unwind/orc: Convert global variables to static
These variables aren't used outside of unwind_orc.c, make them static.
Also annotate some of them with '__ro_after_init', as applicable.
--- arch/x86/kernel/unwind_orc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/kernel/unwind_orc.c +5 -5
@@ -15,12 +15,12 @@ extern int __stop_orc_unwind_ip[];extern struct orc_entry __start_orc_unwind[];extern struct orc_entry __stop_orc_unwind[]; -static DEFINE_MUTEX (sort_mutex); -int *cur_orc_ip_table = __start_orc_unwind_ip; -struct orc_entry *cur_orc_table = __start_orc_unwind; +static bool orc_init__ro_after_init ; +static unsigned int lookup_num_blocks__ro_after_init ; -unsigned int lookup_num_blocks; -bool orc_init; +static DEFINE_MUTEX (sort_mutex); +static int *cur_orc_ip_table = __start_orc_unwind_ip; +static struct orc_entry *cur_orc_table = __start_orc_unwind;static inline unsigned long orc_ip (const int *ip) {
Re: [PATCH v2 06/11] x86/unwind/orc: Convert global variables to static
In reply to Josh PoimboeufQuoted 3 lines · On Sat, 25 Apr 2020 05:03:05 -0500 Josh Poimboeuf <[email protected]> wrote:
These variables aren't used outside of
unwind_orc.c, make them static.Also annotate some of them with '
__ro_after_init', as applicable.
So it appears that crash uses "lookup_num_blocks" to be able to do back-traces with the ORC unwinder. But because it's now static, crash can no longer do that.
Is it possible to make lookup_num_blocks global again?
/* Not static so that the crash utility can access it */ unsigned int lookup_num_blocks __ro_after_init;
-- Steve
Quoted 29 lines
Signed-off-by Josh Poimboeuf <[email protected]>Reviewed-by Miroslav Benes <[email protected]>--- arch/x86/kernel/unwind_orc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)arch/x86/kernel/unwind_orc.c +5
-5@@ -15,12 +15,12 @@ extern int __stop_orc_unwind_ip[];extern struct orc_entry __start_orc_unwind[];extern struct orc_entry __stop_orc_unwind[]; -static DEFINE_MUTEX (sort_mutex); -int *cur_orc_ip_table = __start_orc_unwind_ip; -struct orc_entry *cur_orc_table = __start_orc_unwind; +static bool orc_init__ro_after_init ; +static unsigned int lookup_num_blocks__ro_after_init ; -unsigned int lookup_num_blocks; -bool orc_init; +static DEFINE_MUTEX (sort_mutex); +static int *cur_orc_ip_table = __start_orc_unwind_ip; +static struct orc_entry *cur_orc_table = __start_orc_unwind;static inline unsigned long orc_ip (const int *ip) {
Josh Poimboeuf
maintainerRe: [PATCH v2 06/11] x86/unwind/orc: Convert global variables to static
Quoted 10 lines · Steven Rostedt
Quoted 3 lines · On Sat, 25 Apr 2020 05:03:05 -0500 Josh Poimboeuf <[email protected]> wrote:
These variables aren't used outside of
unwind_orc.c, make them static.Also annotate some of them with '
__ro_after_init', as applicable.So it appears that crash uses "
lookup_num_blocks" to be able to do back-traces with the ORC unwinder. But because it's now static, crash can no longer do that.
Hm, but why? Even a static variable has a known address.
Signature · 1 line
Josh
Re: [PATCH v2 06/11] x86/unwind/orc: Convert global variables to static
Quoted 6 lines · On Wed, 28 Feb 2024 16:03:09 -0800 Josh Poimboeuf <[email protected]> wrote:
Quoted 5 lines · Steven Rostedt
Quoted 2 lines · On Sat, 25 Apr 2020 05:03:05 -0500 Josh Poimboeuf <[email protected]> wrote:
These variables aren't used outside of
unwind_orc.c, make them static.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Also annotate some of them with '
__ro_after_init', as applicable.So it appears that crash uses "
lookup_num_blocks" to be able to do back-traces with the ORC unwinder. But because it's now static, crash can no longer do that.Hm, but why? Even a static variable has a known address.
I'm guessing because we don't have the full dwarf info?
-- Steve
Josh Poimboeuf
maintainerRe: [PATCH v2 06/11] x86/unwind/orc: Convert global variables to static
Quoted 11 lines · Steven Rostedt
Quoted 8 lines · On Wed, 28 Feb 2024 16:03:09 -0800 Josh Poimboeuf <[email protected]> wrote:
Quoted 7 lines · Steven Rostedt
Quoted 3 lines · On Sat, 25 Apr 2020 05:03:05 -0500 Josh Poimboeuf <[email protected]> wrote:
These variables aren't used outside of
unwind_orc.c, make them static.Also annotate some of them with '
__ro_after_init', as applicable.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
So it appears that crash uses "
lookup_num_blocks" to be able to do back-traces with the ORC unwinder. But because it's now static, crash can no longer do that.Hm, but why? Even a static variable has a known address.
I'm guessing because we don't have the full dwarf info?
DWARF isn't needed for that. Even the symbol table has it (as does System.map). For both globals and statics.
Signature · 1 line
Josh
Re: [PATCH v2 06/11] x86/unwind/orc: Convert global variables to static
Quoted 2 lines · On Wed, 28 Feb 2024 16:42:52 -0800 Josh Poimboeuf <[email protected]> wrote:
DWARF isn't needed for that. Even the symbol table has it (as does System.map). For both globals and statics.
Interesting enough, it is reported that if lookup_num_blocks is global, crash returns the proper value. If it is static, it just returns "1", which is incorrect (the correct value is around 60K).
-- Steve
Re: [PATCH v2 06/11] x86/unwind/orc: Convert global variables to static
In reply to Josh PoimboeufQuoted 4 lines · On Wed, 28 Feb 2024 16:42:52 -0800 Josh Poimboeuf <[email protected]> wrote:
Quoted 1 line
I'm guessing because we don't have the full dwarf info?
DWARF isn't needed for that. Even the symbol table has it (as does System.map). For both globals and statics.
It is in System.map, but I guess the real issue is that the compiler can optimize it out. That is, the number is never set as it is static and the compiler doesn't need to do anything to make it valid. To the compiler, the number is just a local variable. I'm not exactly sure how it does that, as it sets the value in one function and uses it in another. But clang appears to not be setting it when it is static.
Either removing static or making it volatile makes it work again.
Thoughts?
-- Steve
PATCH v2 7/11 x86/unwind: Prevent false warnings for non-current tasks
In reply to Josh PoimboeufThere's some daring kernel code out there which dumps the stack of another task without first making sure the task is inactive. If the task happens to be running while the unwinder is reading the stack, unusual unwinder warnings can result.
There's no race-free way for the unwinder to know whether such a warning is legitimate, so just disable unwinder warnings for all non-current tasks.
--- arch/x86/kernel/dumpstack_64.c | 3 ++- arch/x86/kernel/unwind_frame.c | 3 +++ arch/x86/kernel/unwind_orc.c | 40 +++++++++++++++++++--------------- 3 files changed, 28 insertions(+), 18 deletions(-)
arch/x86/kernel/dumpstack_64.c +2 -1
@@ -183,7 +183,8 @@ int get_stack_info(unsigned long *stack, struct task_struct *task,*/ if (visit_mask) {if (*visit_mask & (1UL << info->type)) { -printk_deferred_once (KERN_WARNING "WARNING: stack recursion on stack type %d\n" , info->type); +if (task == current) +printk_deferred_once (KERN_WARNING "WARNING: stack recursion on stack type %d\n" , info->type); goto unknown; } *visit_mask |=1UL << info->type;
arch/x86/kernel/unwind_frame.c +3 -0
@@ -344,6 +344,9 @@ bool unwind_next_frame(struct unwind_state *state)if (IS_ENABLED (CONFIG_X86_32 )) goto the_end; +if (state->task != current) + goto the_end; +if (state->regs) { printk_deferred_once(KERN_WARNING "WARNING: kernel stack regs at %p in %s:%d has bad 'bp' value %p\n",
arch/x86/kernel/unwind_orc.c +23 -17
@@ -8,7 +8,13 @@#include <asm/orc_lookup.h> #define orc_warn (fmt, ...) \ - printk_deferred_once(KERN_WARNING pr_fmt("WARNING: " fmt), ##__VA_ARGS__) + printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__) + +#define orc_warn_current(args...) \ +({ \ + if (state->task == current) \ + orc_warn(args); \ +})extern int __start_orc_unwind_ip[];extern int __stop_orc_unwind_ip[];
@@ -446,8 +452,8 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_REG_R10 :if (!state->regs || !state->full_regs) { -orc_warn ("missing regs for base reg R10 at ip %pB\n" , - (void *)state->ip); +orc_warn_current ("missing R10 value at %pB\n" , + (void *)state->ip); goto err; } sp = state->regs->r10;
@@ -455,8 +461,8 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_REG_R13 :if (!state->regs || !state->full_regs) { -orc_warn ("missing regs for base reg R13 at ip %pB\n" , - (void *)state->ip); +orc_warn_current ("missing R13 value at %pB\n" , + (void *)state->ip); goto err; } sp = state->regs->r13;
@@ -464,8 +470,8 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_REG_DI :if (!state->regs || !state->full_regs) { -orc_warn ("missing regs for base reg DI at ip %pB\n" , - (void *)state->ip); +orc_warn_current ("missing RDI value at %pB\n" , + (void *)state->ip); goto err; } sp = state->regs->di;
@@ -473,15 +479,15 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_REG_DX :if (!state->regs || !state->full_regs) { -orc_warn ("missing regs for base reg DX at ip %pB\n" , - (void *)state->ip); +orc_warn_current ("missing DX value at %pB\n" , + (void *)state->ip); goto err; } sp = state->regs->dx;break ;default : -orc_warn ("unknown SP base reg %d for ip %pB\n" , +orc_warn ("unknown SP base reg %d at %pB\n" , orc->sp_reg, (void *)state->ip); goto err; }
@@ -509,8 +515,8 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_TYPE_REGS :if (!deref_stack_regs (state, sp, &state->ip, &state->sp)) { -orc_warn ("can't dereference registers at %p for ip %pB\n" , - (void *)sp, (void *)orig_ip); +orc_warn_current ("can't access registers at %pB\n" , + (void *)orig_ip); goto err; }
@@ -521,8 +527,8 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_TYPE_REGS_IRET :if (!deref_stack_iret_regs (state, sp, &state->ip, &state->sp)) { -orc_warn ("can't dereference iret registers at %p for ip %pB\n" , - (void *)sp, (void *)orig_ip); +orc_warn_current ("can't access iret registers at %pB\n" , + (void *)orig_ip); goto err; }
@@ -532,7 +538,7 @@ bool unwind_next_frame(struct unwind_state *state)break ;default : -orc_warn ("unknown .orc_unwind entry type %d for ip %pB\n" , +orc_warn ("unknown .orc_unwind entry type %d at %pB\n" , orc->type, (void *)orig_ip);break ; }
@@ -564,8 +570,8 @@ bool unwind_next_frame(struct unwind_state *state)if (state->stack_info.type == prev_type &&on_stack (&state->stack_info, (void *)state->sp,sizeof (long )) && state->sp <= prev_sp) { -orc_warn ("stack going in the wrong direction? ip=%pB\n" , - (void *)orig_ip); +orc_warn_current ("stack going in the wrong direction? at %pB\n" , + (void *)orig_ip); goto err; }
Signature · 1 line
2.21.1
[tip: x86/urgent] x86/unwind: Prevent false warnings for non-current tasks
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: b08418b54831255a7e3700d6bf7dfc2bdae25cd7 Gitweb: https://git.kernel.org/tip/b08418b54831255a7e3700d6bf7dfc2bdae25cd7 Author: Josh Poimboeuf <[email protected]> AuthorDate: Sat, 25 Apr 2020 05:03:06 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 25 Apr 2020 12:22:28 +02:00
x86/unwind: Prevent false warnings for non-current tasks
There's some daring kernel code out there which dumps the stack of another task without first making sure the task is inactive. If the task happens to be running while the unwinder is reading the stack, unusual unwinder warnings can result.
There's no race-free way for the unwinder to know whether such a warning is legitimate, so just disable unwinder warnings for all non-current tasks.
--- arch/x86/kernel/dumpstack_64.c | 3 +- arch/x86/kernel/unwind_frame.c | 3 ++- arch/x86/kernel/unwind_orc.c | 40 ++++++++++++++++++--------------- 3 files changed, 28 insertions(+), 18 deletions(-)
arch/x86/kernel/dumpstack_64.c +2 -1
@@ -183,7 +183,8 @@ recursion_check:*/ if (visit_mask) {if (*visit_mask & (1UL << info->type)) { -printk_deferred_once (KERN_WARNING "WARNING: stack recursion on stack type %d\n" , info->type); +if (task == current) +printk_deferred_once (KERN_WARNING "WARNING: stack recursion on stack type %d\n" , info->type); goto unknown; } *visit_mask |=1UL << info->type;
arch/x86/kernel/unwind_frame.c +3 -0
@@ -344,6 +344,9 @@ bad_address:if (IS_ENABLED (CONFIG_X86_32 )) goto the_end; +if (state->task != current) + goto the_end; +if (state->regs) { printk_deferred_once(KERN_WARNING "WARNING: kernel stack regs at %p in %s:%d has bad 'bp' value %p\n",
arch/x86/kernel/unwind_orc.c +23 -17
@@ -8,7 +8,13 @@#include <asm/orc_lookup.h> #define orc_warn (fmt, ...) \ - printk_deferred_once(KERN_WARNING pr_fmt("WARNING: " fmt), ##__VA_ARGS__) + printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__) + +#define orc_warn_current(args...) \ +({ \ + if (state->task == current) \ + orc_warn(args); \ +})extern int __start_orc_unwind_ip[];extern int __stop_orc_unwind_ip[];
@@ -446,8 +452,8 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_REG_R10 :if (!state->regs || !state->full_regs) { -orc_warn ("missing regs for base reg R10 at ip %pB\n" , - (void *)state->ip); +orc_warn_current ("missing R10 value at %pB\n" , + (void *)state->ip); goto err; } sp = state->regs->r10;
@@ -455,8 +461,8 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_REG_R13 :if (!state->regs || !state->full_regs) { -orc_warn ("missing regs for base reg R13 at ip %pB\n" , - (void *)state->ip); +orc_warn_current ("missing R13 value at %pB\n" , + (void *)state->ip); goto err; } sp = state->regs->r13;
@@ -464,8 +470,8 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_REG_DI :if (!state->regs || !state->full_regs) { -orc_warn ("missing regs for base reg DI at ip %pB\n" , - (void *)state->ip); +orc_warn_current ("missing RDI value at %pB\n" , + (void *)state->ip); goto err; } sp = state->regs->di;
@@ -473,15 +479,15 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_REG_DX :if (!state->regs || !state->full_regs) { -orc_warn ("missing regs for base reg DX at ip %pB\n" , - (void *)state->ip); +orc_warn_current ("missing DX value at %pB\n" , + (void *)state->ip); goto err; } sp = state->regs->dx;break ;default : -orc_warn ("unknown SP base reg %d for ip %pB\n" , +orc_warn ("unknown SP base reg %d at %pB\n" , orc->sp_reg, (void *)state->ip); goto err; }
@@ -509,8 +515,8 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_TYPE_REGS :if (!deref_stack_regs (state, sp, &state->ip, &state->sp)) { -orc_warn ("can't dereference registers at %p for ip %pB\n" , - (void *)sp, (void *)orig_ip); +orc_warn_current ("can't access registers at %pB\n" , + (void *)orig_ip); goto err; }
@@ -521,8 +527,8 @@ bool unwind_next_frame(struct unwind_state *state)case ORC_TYPE_REGS_IRET :if (!deref_stack_iret_regs (state, sp, &state->ip, &state->sp)) { -orc_warn ("can't dereference iret registers at %p for ip %pB\n" , - (void *)sp, (void *)orig_ip); +orc_warn_current ("can't access iret registers at %pB\n" , + (void *)orig_ip); goto err; }
@@ -532,7 +538,7 @@ bool unwind_next_frame(struct unwind_state *state)break ;default : -orc_warn ("unknown .orc_unwind entry type %d for ip %pB\n" , +orc_warn ("unknown .orc_unwind entry type %d at %pB\n" , orc->type, (void *)orig_ip);break ; }
@@ -564,8 +570,8 @@ bool unwind_next_frame(struct unwind_state *state)if (state->stack_info.type == prev_type &&on_stack (&state->stack_info, (void *)state->sp,sizeof (long )) && state->sp <= prev_sp) { -orc_warn ("stack going in the wrong direction? ip=%pB\n" , - (void *)orig_ip); +orc_warn_current ("stack going in the wrong direction? at %pB\n" , + (void *)orig_ip); goto err; }
PATCH v2 8/11 x86/unwind/orc: Don't skip the first frame for inactive tasks
In reply to Josh PoimboeufFrom: Miroslav Benes <[email protected]>
When unwinding an inactive task, the ORC unwinder skips the first frame by default. If both the 'regs' and 'first_frame' parameters of unwind_start() are NULL, 'state->sp' and 'first_frame' are later initialized to the same value for an inactive task. Given there is a "less than or equal to" comparison used at the end of __unwind_start() for skipping stack frames, the first frame is skipped.
Drop the equal part of the comparison and make the behavior equivalent to the frame pointer unwinder.
--- arch/x86/kernel/unwind_orc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/unwind_orc.c +1 -1
@@ -657,7 +657,7 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,/* Otherwise, skip ahead to the user-specified starting frame: */ while (!unwind_done (state) && (!on_stack (&state->stack_info, first_frame,sizeof (long )) || - state->sp <= (unsigned long )first_frame)) + state->sp < (unsigned long )first_frame))unwind_next_frame (state);return ;
Signature · 1 line
2.21.1
[tip: x86/urgent] x86/unwind/orc: Don't skip the first frame for inactive tasks
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: f1d9a2abff66aa8156fbc1493abed468db63ea48 Gitweb: https://git.kernel.org/tip/f1d9a2abff66aa8156fbc1493abed468db63ea48 Author: Miroslav Benes <[email protected]> AuthorDate: Sat, 25 Apr 2020 05:03:07 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 25 Apr 2020 12:22:29 +02:00
x86/unwind/orc: Don't skip the first frame for inactive tasks
When unwinding an inactive task, the ORC unwinder skips the first frame by default. If both the 'regs' and 'first_frame' parameters of unwind_start() are NULL, 'state->sp' and 'first_frame' are later initialized to the same value for an inactive task. Given there is a "less than or equal to" comparison used at the end of __unwind_start() for skipping stack frames, the first frame is skipped.
Drop the equal part of the comparison and make the behavior equivalent to the frame pointer unwinder.
--- arch/x86/kernel/unwind_orc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/unwind_orc.c +1 -1
@@ -657,7 +657,7 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,/* Otherwise, skip ahead to the user-specified starting frame: */ while (!unwind_done (state) && (!on_stack (&state->stack_info, first_frame,sizeof (long )) || - state->sp <= (unsigned long )first_frame)) + state->sp < (unsigned long )first_frame))unwind_next_frame (state);return ;
PATCH v2 9/11 x86/unwind/orc: Prevent unwinding before ORC initialization
In reply to Josh PoimboeufIf the unwinder is called before the ORC data has been initialized, orc_find() returns NULL, and it tries to fall back to using frame pointers. This can cause some unexpected warnings during boot.
Move the 'orc_init' check from orc_find() to __unwind_init(), so that it doesn't even try to unwind from an uninitialized state.
--- arch/x86/kernel/unwind_orc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/unwind_orc.c +3 -3
@@ -148,9 +148,6 @@ static struct orc_entry *orc_find(unsigned long ip) {static struct orc_entry *orc; -if (!orc_init) -return NULL ; -if (ip ==0 )return &null_orc_entry;
@@ -591,6 +588,9 @@ EXPORT_SYMBOL_GPL(unwind_next_frame);void __unwind_start (struct unwind_state *state,struct task_struct *task,struct pt_regs *regs,unsigned long *first_frame) { +if (!orc_init) + goto done; +memset (state,0 ,sizeof (*state)); state->task = task;
Signature · 1 line
2.21.1
Re: [PATCH v2 09/11] x86/unwind/orc: Prevent unwinding before ORC initialization
Quoted 10 lines · Josh Poimboeuf
If the unwinder is called before the ORC data has been initialized,
orc_find()returns NULL, and it tries to fall back to using frame pointers. This can cause some unexpected warnings during boot.Move the '
orc_init' check fromorc_find()to__unwind_init(), so that it doesn't even try to unwind from an uninitialized state.Fixes ee9f8fce9964 ("x86/unwind: Add the ORC unwinder")Signed-off-by Josh Poimboeuf <[email protected]>Reviewed-by Miroslav Benes <[email protected]>
I got a weird error when sending this one:
4.7.1 Error: too much mail from 10.10.114.29
If anybody didn't get it, let me know and I can bounce it.
Quoted 31 lines
--- arch/x86/kernel/unwind_orc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/x86/kernel/unwind_orc.c +3
-3@@ -148,9 +148,6 @@ static struct orc_entry *orc_find(unsigned long ip) {static struct orc_entry *orc; -if (!orc_init) -return NULL ; -if (ip ==0 )return &null_orc_entry;@@ -591,6 +588,9 @@ EXPORT_SYMBOL_GPL(unwind_next_frame);void __unwind_start (struct unwind_state *state,struct task_struct *task,struct pt_regs *regs,unsigned long *first_frame) { +if (!orc_init) + goto done; +memset (state,0 ,sizeof (*state)); state->task = task;Signature · 1 line
2.21.1
Signature · 1 line
Josh
[tip: x86/urgent] x86/unwind/orc: Prevent unwinding before ORC initialization
In reply to Josh PoimboeufThe following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 98d0c8ebf77e0ba7c54a9ae05ea588f0e9e3f46e Gitweb: https://git.kernel.org/tip/98d0c8ebf77e0ba7c54a9ae05ea588f0e9e3f46e Author: Josh Poimboeuf <[email protected]> AuthorDate: Sat, 25 Apr 2020 05:03:08 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 25 Apr 2020 12:22:29 +02:00
x86/unwind/orc: Prevent unwinding before ORC initialization
If the unwinder is called before the ORC data has been initialized, orc_find() returns NULL, and it tries to fall back to using frame pointers. This can cause some unexpected warnings during boot.
Move the 'orc_init' check from orc_find() to __unwind_init(), so that it doesn't even try to unwind from an uninitialized state.
--- arch/x86/kernel/unwind_orc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/unwind_orc.c +3 -3
@@ -148,9 +148,6 @@ static struct orc_entry *orc_find(unsigned long ip) {static struct orc_entry *orc; -if (!orc_init) -return NULL ; -if (ip ==0 )return &null_orc_entry;
@@ -591,6 +588,9 @@ EXPORT_SYMBOL_GPL(unwind_next_frame);void __unwind_start (struct unwind_state *state,struct task_struct *task,struct pt_regs *regs,unsigned long *first_frame) { +if (!orc_init) + goto done; +memset (state,0 ,sizeof (*state)); state->task = task;
PATCH v2 10/11 x86/unwind/orc: Fix error path for bad ORC entry type
In reply to Josh PoimboeufIf the ORC entry type is unknown, nothing else can be done other than reporting an error. Exit the function instead of breaking out of the switch statement.
--- arch/x86/kernel/unwind_orc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/unwind_orc.c +1 -1
@@ -537,7 +537,7 @@ bool unwind_next_frame(struct unwind_state *state)default :orc_warn ("unknown .orc_unwind entry type %d at %pB\n" , orc->type, (void *)orig_ip); -break ; + goto err; }/* Find BP: */
Signature · 1 line
2.21.1
[tip: x86/urgent] x86/unwind/orc: Fix error path for bad ORC entry type
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: a0f81bf26888048100bf017fadf438a5bdffa8d8 Gitweb: https://git.kernel.org/tip/a0f81bf26888048100bf017fadf438a5bdffa8d8 Author: Josh Poimboeuf <[email protected]> AuthorDate: Sat, 25 Apr 2020 05:06:13 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 25 Apr 2020 12:22:29 +02:00
x86/unwind/orc: Fix error path for bad ORC entry type
If the ORC entry type is unknown, nothing else can be done other than reporting an error. Exit the function instead of breaking out of the switch statement.
--- arch/x86/kernel/unwind_orc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/unwind_orc.c +1 -1
@@ -537,7 +537,7 @@ bool unwind_next_frame(struct unwind_state *state)default :orc_warn ("unknown .orc_unwind entry type %d at %pB\n" , orc->type, (void *)orig_ip); -break ; + goto err; }/* Find BP: */
PATCH v2 11/11 x86/unwind/orc: Fix premature unwind stoppage due to IRET frames
In reply to Josh PoimboeufThe following execution path is possible:
fsnotify()
[ realign the stack and store previous SP in R10 ] <IRQ>
[ only IRET regs saved ] common_interrupt()
interrupt_entry()
<NMI>
[ full pt_regs saved ]
...
[ unwind stack ]
When the unwinder goes through the NMI and the IRQ on the stack, and then sees fsnotify(), it doesn't have access to the value of R10, because it only has the five IRET registers. So the unwind stops prematurely.
However, because the interrupt_entry() code is careful not to clobber R10 before saving the full regs, the unwinder should be able to read R10 from the previously saved full pt_regs associated with the NMI.
Handle this case properly. When encountering an IRET regs frame immediately after a full pt_regs frame, use the pt_regs as a backup which can be used to get the C register values.
Also, note that a call frame resets the 'prev_regs' value, because a function is free to clobber the registers. For this fix to work, the IRET and full regs frames must be adjacent, with no FUNC frames in between. So replace the FUNC hint in interrupt_entry() with an IRET_REGS hint.
--- arch/x86/entry/entry_64.S | 4 +-- arch/x86/include/asm/unwind.h | 2 +- arch/x86/kernel/unwind_orc.c | 51 +++++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 14 deletions(-)
arch/x86/entry/entry_64.S +2 -2
@@ -511,7 +511,7 @@ SYM_CODE_END(spurious_entries_start) * +----------------------------------------------------+ */ SYM_CODE_START(interrupt_entry) - UNWIND_HINT_FUNC + UNWIND_HINT_IRET_REGS offset=16 ASM_CLAC cld
@@ -543,9 +543,9 @@ SYM_CODE_START(interrupt_entry) pushq 5*8(%rdi) /* regs->eflags */ pushq 4*8(%rdi) /* regs->cs */ pushq 3*8(%rdi) /* regs->ip */ + UNWIND_HINT_IRET_REGS pushq 2*8(%rdi) /* regs->orig_ax */ pushq 8(%rdi) /* return address */ - UNWIND_HINT_FUNC movq (%rdi), %rdi jmp 2f
arch/x86/include/asm/unwind.h +1 -1
@@ -19,7 +19,7 @@ struct unwind_state {#if defined(CONFIG_UNWINDER_ORC )bool signal, full_regs;unsigned long sp, bp, ip; -struct pt_regs *regs; +struct pt_regs *regs, *prev_regs;#elif defined(CONFIG_UNWINDER_FRAME_POINTER )bool got_irq;unsigned long *bp, *orig_sp, ip;
arch/x86/kernel/unwind_orc.c +40 -11
114 lines not on this page · raw message
Signature · 1 line
2.21.1
[tip: x86/urgent] x86/unwind/orc: Fix premature unwind stoppage due to IRET frames
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 81b67439d147677d844d492fcbd03712ea438f42 Gitweb: https://git.kernel.org/tip/81b67439d147677d844d492fcbd03712ea438f42 Author: Josh Poimboeuf <[email protected]> AuthorDate: Sat, 25 Apr 2020 05:06:14 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Sat, 25 Apr 2020 12:22:29 +02:00
x86/unwind/orc: Fix premature unwind stoppage due to IRET frames
The following execution path is possible:
fsnotify()
[ realign the stack and store previous SP in R10 ] <IRQ>
[ only IRET regs saved ] common_interrupt()
interrupt_entry()
<NMI>
[ full pt_regs saved ]
...
[ unwind stack ]
When the unwinder goes through the NMI and the IRQ on the stack, and then sees fsnotify(), it doesn't have access to the value of R10, because it only has the five IRET registers. So the unwind stops prematurely.
However, because the interrupt_entry() code is careful not to clobber R10 before saving the full regs, the unwinder should be able to read R10 from the previously saved full pt_regs associated with the NMI.
Handle this case properly. When encountering an IRET regs frame immediately after a full pt_regs frame, use the pt_regs as a backup which can be used to get the C register values.
Also, note that a call frame resets the 'prev_regs' value, because a function is free to clobber the registers. For this fix to work, the IRET and full regs frames must be adjacent, with no FUNC frames in between. So replace the FUNC hint in interrupt_entry() with an IRET_REGS hint.
--- arch/x86/entry/entry_64.S | 4 +-- arch/x86/include/asm/unwind.h | 2 +- arch/x86/kernel/unwind_orc.c | 51 ++++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 14 deletions(-)
arch/x86/entry/entry_64.S +2 -2
@@ -511,7 +511,7 @@ SYM_CODE_END(spurious_entries_start) * +----------------------------------------------------+ */ SYM_CODE_START(interrupt_entry) - UNWIND_HINT_FUNC + UNWIND_HINT_IRET_REGS offset=16 ASM_CLAC cld
@@ -543,9 +543,9 @@ SYM_CODE_START(interrupt_entry) pushq 5*8(%rdi) /* regs->eflags */ pushq 4*8(%rdi) /* regs->cs */ pushq 3*8(%rdi) /* regs->ip */ + UNWIND_HINT_IRET_REGS pushq 2*8(%rdi) /* regs->orig_ax */ pushq 8(%rdi) /* return address */ - UNWIND_HINT_FUNC movq (%rdi), %rdi jmp 2f
arch/x86/include/asm/unwind.h +1 -1
@@ -19,7 +19,7 @@ struct unwind_state {#if defined(CONFIG_UNWINDER_ORC )bool signal, full_regs;unsigned long sp, bp, ip; -struct pt_regs *regs; +struct pt_regs *regs, *prev_regs;#elif defined(CONFIG_UNWINDER_FRAME_POINTER )bool got_irq;unsigned long *bp, *orig_sp, ip;
arch/x86/kernel/unwind_orc.c +40 -11
114 lines not on this page · raw message
Quoted 23 lines · Josh Poimboeuf
v2:
- Dropped three patches which technically weren't fixes. Will post them later as part of another patch set with more improvements.
- Removedshow_iret_regs()declaration [mbenes]
- Added Miroslav Reviewed-by, Linus Reported-byv1 was here:
https://lkml.kernel.org/r/[email protected]Jann Horn (1):
x86/entry/64: Fix unwind hints inrewind_stack_do_exit()Josh Poimboeuf (9):
objtool: Fix stack offset tracking for indirect CFAs x86/entry/64: Fix unwind hints in register clearing code x86/entry/64: Fix unwind hints in kernel exit path x86/entry/64: Fix unwind hints in__switch_to_asm()x86/unwind/orc: Convert global variables to static x86/unwind: Prevent false warnings for non-current tasks x86/unwind/orc: Prevent unwinding before ORC initialization x86/unwind/orc: Fix error path for bad ORC entry type x86/unwind/orc: Fix premature unwind stoppage due to IRET frames
Quoted 2 lines
Miroslav Benes (1):
x86/unwind/orc: Don't skip the first frame for inactive tasks
Thanks for doing this. These ORC handling bugs IMHO look serious and widespread enough to warrant x86/urgent treatment, and the v2 series is fixes-only.
Any objections against targeting v5.7-rc3 with this, assuming that there's no problems found during review and it passes about a week of testing?
Thanks,
Ingo
Quoted 29 lines · Ingo Molnar
Quoted 23 lines · Josh Poimboeuf
v2:
- Dropped three patches which technically weren't fixes. Will post them later as part of another patch set with more improvements.
- Removedshow_iret_regs()declaration [mbenes]
- Added Miroslav Reviewed-by, Linus Reported-byv1 was here:
https://lkml.kernel.org/r/[email protected]Jann Horn (1):
x86/entry/64: Fix unwind hints inrewind_stack_do_exit()Josh Poimboeuf (9):
objtool: Fix stack offset tracking for indirect CFAs x86/entry/64: Fix unwind hints in register clearing code x86/entry/64: Fix unwind hints in kernel exit path x86/entry/64: Fix unwind hints in__switch_to_asm()x86/unwind/orc: Convert global variables to static x86/unwind: Prevent false warnings for non-current tasks x86/unwind/orc: Prevent unwinding before ORC initialization x86/unwind/orc: Fix error path for bad ORC entry type x86/unwind/orc: Fix premature unwind stoppage due to IRET framesQuoted 2 lines
Miroslav Benes (1):
x86/unwind/orc: Don't skip the first frame for inactive tasks
Quoted 7 lines
Thanks for doing this. These ORC handling bugs IMHO look serious and widespread enough to warrant x86/urgent treatment, and the v2 series is fixes-only.
Any objections against targeting v5.7-rc3 with this, assuming that there's no problems found during review and it passes about a week of testing?
Hi Ingo,
Due to other distractions, I unfortunately have been sitting on some of these fixes for several months -- notice some of the long Reported-by chains :-/
They're good small localized fixes and I would agree it makes sense to target x86/urgent.
Thanks!
Signature · 1 line
Josh
Quoted 6 lines · Josh Poimboeuf
Quoted 3 lines
Any objections against targeting v5.7-rc3 with this, assuming that there's no problems found during review and it passes about a week of testing?
Hi Ingo,
Quoted 8 lines
Due to other distractions, I unfortunately have been sitting on some of these fixes for several months -- notice some of the long Reported-by chains :-/
They're good small localized fixes and I would agree it makes sense to target x86/urgent.
Thanks!
Ok, I've merged them for x86/urgent - with the small tweak to the merge plan that it would be for -rc4 next week - the patches are too fresh for -rc3 IMO.
Thanks,
Ingo