linux-brain/arch/x86/kernel
Jiri Slaby f7e7de28d1 x86/unwind/orc: Fix inactive tasks with stack pointer in %sp on GCC 10 compiled kernels
[ Upstream commit f2ac57a4c49d40409c21c82d23b5706df9b438af ]

GCC 10 optimizes the scheduler code differently than its predecessors.

When CONFIG_DEBUG_SECTION_MISMATCH=y, the Makefile forces GCC not
to inline some functions (-fno-inline-functions-called-once). Before GCC
10, "no-inlined" __schedule() starts with the usual prologue:

  push %bp
  mov %sp, %bp

So the ORC unwinder simply picks stack pointer from %bp and
unwinds from __schedule() just perfectly:

  $ cat /proc/1/stack
  [<0>] ep_poll+0x3e9/0x450
  [<0>] do_epoll_wait+0xaa/0xc0
  [<0>] __x64_sys_epoll_wait+0x1a/0x20
  [<0>] do_syscall_64+0x33/0x40
  [<0>] entry_SYSCALL_64_after_hwframe+0x44/0xa9

But now, with GCC 10, there is no %bp prologue in __schedule():

  $ cat /proc/1/stack
  <nothing>

The ORC entry of the point in __schedule() is:

  sp:sp+88 bp:last_sp-48 type:call end:0

In this case, nobody subtracts sizeof "struct inactive_task_frame" in
__unwind_start(). The struct is put on the stack by __switch_to_asm() and
only then __switch_to_asm() stores %sp to task->thread.sp. But we start
unwinding from a point in __schedule() (stored in frame->ret_addr by
'call') and not in __switch_to_asm().

So for these example values in __unwind_start():

  sp=ffff94b50001fdc8 bp=ffff8e1f41d29340 ip=__schedule+0x1f0

The stack is:

  ffff94b50001fdc8: ffff8e1f41578000 # struct inactive_task_frame
  ffff94b50001fdd0: 0000000000000000
  ffff94b50001fdd8: ffff8e1f41d29340
  ffff94b50001fde0: ffff8e1f41611d40 # ...
  ffff94b50001fde8: ffffffff93c41920 # bx
  ffff94b50001fdf0: ffff8e1f41d29340 # bp
  ffff94b50001fdf8: ffffffff9376cad0 # ret_addr (and end of the struct)

0xffffffff9376cad0 is __schedule+0x1f0 (after the call to
__switch_to_asm).  Now follow those 88 bytes from the ORC entry (sp+88).
The entry is correct, __schedule() really pushes 48 bytes (8*7) + 32 bytes
via subq to store some local values (like 4U below). So to unwind, look
at the offset 88-sizeof(long) = 0x50 from here:

  ffff94b50001fe00: ffff8e1f41578618
  ffff94b50001fe08: 00000cc000000255
  ffff94b50001fe10: 0000000500000004
  ffff94b50001fe18: 7793fab6956b2d00 # NOTE (see below)
  ffff94b50001fe20: ffff8e1f41578000
  ffff94b50001fe28: ffff8e1f41578000
  ffff94b50001fe30: ffff8e1f41578000
  ffff94b50001fe38: ffff8e1f41578000
  ffff94b50001fe40: ffff94b50001fed8
  ffff94b50001fe48: ffff8e1f41577ff0
  ffff94b50001fe50: ffffffff9376cf12

Here                ^^^^^^^^^^^^^^^^ is the correct ret addr from
__schedule(). It translates to schedule+0x42 (insn after a call to
__schedule()).

BUT, unwind_next_frame() tries to take the address starting from
0xffff94b50001fdc8. That is exactly from thread.sp+88-sizeof(long) =
0xffff94b50001fdc8+88-8 = 0xffff94b50001fe18, which is garbage marked as
NOTE above. So this quits the unwinding as 7793fab6956b2d00 is obviously
not a kernel address.

There was a fix to skip 'struct inactive_task_frame' in
unwind_get_return_address_ptr in the following commit:

  187b96db5ca7 ("x86/unwind/orc: Fix unwind_get_return_address_ptr() for inactive tasks")

But we need to skip the struct already in the unwinder proper. So
subtract the size (increase the stack pointer) of the structure in
__unwind_start() directly. This allows for removal of the code added by
commit 187b96db5ca7 completely, as the address is now at
'(unsigned long *)state->sp - 1', the same as in the generic case.

[ mingo: Cleaned up the changelog a bit, for better readability. ]

Fixes: ee9f8fce99 ("x86/unwind: Add the ORC unwinder")
Bug: https://bugzilla.suse.com/show_bug.cgi?id=1176907
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20201014053051.24199-1-jslaby@suse.cz
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-11-05 11:43:12 +01:00
..
acpi x86: ACPI: fix CPU hotplug deadlock 2020-04-23 10:36:38 +02:00
apic x86/ioapic: Unbreak check_timer() 2020-10-01 13:18:22 +02:00
cpu x86/mce: Make mce_rdmsrl() panic on an inaccessible MSR 2020-10-29 09:58:03 +01:00
fpu x86/fpu: Allow multiple bits in clearcpuid= parameter 2020-10-29 09:57:29 +01:00
kprobes kretprobe: Prevent triggering kretprobe from within kprobe_flush_task 2020-06-24 17:50:52 +02:00
.gitignore
alternative.c x86: Correct misc typos 2019-09-02 14:02:59 +02:00
amd_gart_64.c dma-mapping: provide a better default ->get_required_mask 2019-09-04 11:13:19 +02:00
amd_nb.c x86/amd_nb: Add AMD family 17h model 60h PCI IDs 2020-06-22 09:31:17 +02:00
apb_timer.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441 2019-06-05 17:37:17 +02:00
aperture_64.c x86/gart: Exclude GART aperture from kcore 2019-03-23 12:11:49 +01:00
apm_32.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 118 2019-05-24 17:39:02 +02:00
asm-offsets_32.c x86/entry/32: Load task stack from x86_tss.sp1 in SYSENTER handler 2018-07-20 01:11:36 +02:00
asm-offsets_64.c Merge branch 'x86-apic-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-09-17 12:04:39 -07:00
asm-offsets.c x86/paravirt: Make read_cr2() CALLEE_SAVE 2019-07-17 23:17:37 +02:00
audit_64.c
bootflag.c
check.c x86/headers: Fix -Wmissing-prototypes warning 2018-11-23 07:59:59 +01:00
cpuid.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 142 2019-05-30 11:25:17 -07:00
crash_dump_32.c
crash_dump_64.c fs/core/vmcore: Move sev_active() reference to x86 arch code 2019-08-09 22:52:10 +10:00
crash.c x86/kdump: Always reserve the low 1M when the crashkernel option is specified 2020-10-01 13:17:18 +02:00
devicetree.c x86/headers: Fix -Wmissing-prototypes warning 2018-11-23 07:59:59 +01:00
doublefault.c x86/doublefault/32: Fix stack canaries in the double fault handler 2019-11-29 10:09:51 +01:00
dumpstack_32.c x86/irq/32: Rename hard/softirq_stack to hard/softirq_stack_ptr 2019-04-17 15:24:18 +02:00
dumpstack_64.c x86/dumpstack/64: Don't evaluate exception stacks before setup 2019-11-05 00:51:35 +01:00
dumpstack.c x86/dumpstack: Indicate PREEMPT_RT in dumps 2019-07-31 19:03:36 +02:00
e820.c x86/e820: Use proper booleans instead of 0/1 2019-07-16 23:13:49 +02:00
early_printk.c efi/x86: Convert x86 EFI earlyprintk into generic earlycon implementation 2019-02-04 08:27:30 +01:00
early-quirks.c x86/intel: Disable HPET on Intel Ice Lake platforms 2020-01-12 12:21:13 +01:00
ebda.c
eisa.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 243 2019-06-19 17:09:07 +02:00
espfix_64.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
ftrace_32.S x86/stackframe/32: Provide consistent pt_regs 2019-06-25 10:23:47 +02:00
ftrace_64.S x86/stackframe, x86/ftrace: Add pt_regs frame annotations 2019-06-25 10:23:47 +02:00
ftrace.c The main changes in this release include: 2019-07-18 11:51:00 -07:00
head_32.S x86/pti/32: Size initial_page_table correctly 2019-11-29 10:09:52 +01:00
head_64.S x86/irq/64: Update stale comment 2019-07-22 10:54:27 +02:00
head32.c x86/boot: Mostly revert commit ae7e1238e6 ("Add ACPI RSDP address to setup_header") 2018-11-20 09:43:10 +01:00
head64.c x86/boot/64: Make level2_kernel_pgt pages invalid outside kernel area 2019-10-11 18:38:15 +02:00
hpet.c x86/hpet: Undo the early counter is counting check 2019-07-25 12:21:32 +02:00
hw_breakpoint.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
i8237.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
i8253.c x86/timer: Skip PIT initialization on modern chipsets 2019-06-29 11:35:35 +02:00
i8259.c x86/i8259: Use printk_deferred() to prevent deadlock 2020-08-05 09:59:52 +02:00
idt.c x86/idt: Keep spurious entries unset in system_vectors 2020-06-24 17:50:43 +02:00
ima_arch.c x86/ima: use correct identifier for SetupMode variable 2020-02-28 17:22:18 +01:00
io_delay.c x86/io_delay: Define IO_DELAY macros in C instead of Kconfig 2019-05-24 08:46:06 +02:00
ioport.c x86: Lock down IO port access when the kernel is locked down 2019-08-19 21:54:16 -07:00
irq_32.c x86/irq: Move IS_ERR_OR_NULL() check into common do_IRQ() code 2019-08-19 23:19:06 +02:00
irq_64.c x86: fix vmap arguments in map_irq_stack 2020-06-22 09:30:57 +02:00
irq_work.c
irq.c x86/irq: Check for VECTOR_UNUSED directly 2019-08-19 23:19:07 +02:00
irqflags.S x86/paravirt: Make native_save_fl() extern inline 2018-07-03 10:56:27 +02:00
irqinit.c x86/irq/32: Handle irq stack allocation failure proper 2019-04-17 15:31:42 +02:00
itmt.c proc/sysctl: add shared variables for range check 2019-07-18 17:08:07 -07:00
jailhouse.c x86: Add "nopv" parameter to disable PV extensions 2019-07-17 08:09:58 +02:00
jump_label.c x86/jump_label: Make tp_vec_nr static 2019-06-25 09:22:14 +02:00
kdebugfs.c Driver Core and debugfs changes for 5.3-rc1 2019-07-12 12:24:03 -07:00
kexec-bzimage64.c Merge branch 'next-lockdown' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security 2019-09-28 08:14:15 -07:00
kgdb.c x86/apic: Provide and use helper for send_IPI_allbutself() 2019-07-25 16:12:00 +02:00
ksysfs.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 428 2019-06-05 17:37:16 +02:00
kvm.c * s390: ioctl hardening, selftests 2019-09-18 09:49:13 -07:00
kvmclock.c x86: kvmguest: use TSC clocksource if invariant TSC is exposed 2019-02-20 22:48:52 +01:00
ldt.c x86: Convert some slow-path static_cpu_has() callers to boot_cpu_has() 2019-04-08 12:13:34 +02:00
livepatch.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 13 2019-05-21 11:28:45 +02:00
machine_kexec_32.c x86/mm: Remove set_pages_x() and set_pages_nx() 2019-09-03 09:26:37 +02:00
machine_kexec_64.c Merge branch 'x86-kdump-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-07-09 11:52:34 -07:00
Makefile Merge branch 'x86-paravirt-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-07-08 17:34:44 -07:00
mmconf-fam10h_64.c
module.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
mpparse.c x86/boot: Fix memory leak in default_get_smp_config() 2019-07-16 23:13:48 +02:00
msr.c x86/msr: Restrict MSR access when the kernel is locked down 2019-08-19 21:54:16 -07:00
nmi_selftest.c
nmi.c x86/nmi: Fix nmi_handle() duration miscalculation 2020-10-29 09:57:30 +01:00
paravirt_patch.c x86/paravirt: Standardize 'insn_buff' variable names 2019-04-29 16:05:49 +02:00
paravirt-spinlocks.c x86/paravirt: Use a single ops structure 2018-09-03 16:50:35 +02:00
paravirt.c x86/paravirt: Drop {read,write}_cr8() hooks 2019-07-22 10:12:33 +02:00
pci-calgary_64.c dma-mapping: explicitly wire up ->mmap and ->get_sgtable 2019-09-04 11:13:18 +02:00
pci-dma.c x86/dma: Get rid of iommu_pass_through 2019-08-23 10:11:01 +02:00
pci-iommu_table.c x86/iommu: Use NULL instead of 0 2018-08-02 14:33:19 +02:00
pci-swiotlb.c dma-mapping: fix filename references 2019-09-03 08:36:30 +02:00
pcspeaker.c x86/platform/pcspeaker: Use PTR_ERR_OR_ZERO() to fix ptr_ret.cocci warning 2018-07-24 09:46:42 +02:00
perf_regs.c perf/x86/regs: Check reserved bits 2019-06-24 19:19:24 +02:00
platform-quirks.c x86/i8237: Register device based on FADT legacy boot flag 2018-04-27 16:44:29 +02:00
pmem.c
probe_roms.c
process_32.c x86/stackframe/32: Provide consistent pt_regs 2019-06-25 10:23:47 +02:00
process_64.c x86/fsgsbase/64: Fix NULL deref in 86_fsgsbase_read_task 2020-08-19 08:16:22 +02:00
process.c x86/speculation: Prevent rogue cross-process SSBD shutdown 2020-06-17 16:40:25 +02:00
process.h x86: Use the correct SPDX License Identifier in headers 2019-10-01 20:31:35 +02:00
ptrace.c x86/ptrace: Mark expected switch fall-through 2019-08-07 15:12:01 +02:00
pvclock.c x86/vdso: Switch to generic vDSO implementation 2019-06-22 21:21:10 +02:00
quirks.c x86/PCI: Remove superfluous returns from void functions 2019-08-20 09:54:36 +02:00
reboot_fixups_32.c
reboot.c x86/reboot/quirks: Add MacBook6,1 reboot quirk 2020-06-17 16:40:25 +02:00
relocate_kernel_32.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 230 2019-06-19 17:09:06 +02:00
relocate_kernel_64.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 230 2019-06-19 17:09:06 +02:00
resource.c
rtc.c x86: Convert x86_platform_ops to timespec64 2018-05-19 14:03:14 +02:00
setup_percpu.c x86/irq/64: Split the IRQ stack into its own pages 2019-04-17 15:37:02 +02:00
setup.c dma-mapping: fix filename references 2019-09-03 08:36:30 +02:00
signal_compat.c
signal.c x86: use static_cpu_has in uaccess region to avoid instrumentation 2019-07-12 11:05:42 -07:00
smp.c x86/smp: Move smp_function_call implementations into IPI code 2019-07-25 16:12:01 +02:00
smpboot.c x86/hotplug: Silence APIC only after all interrupts are migrated 2020-09-03 11:27:06 +02:00
stacktrace.c x86/stacktrace: Fix reliable check for empty user task stacks 2020-08-05 09:59:51 +02:00
step.c
sys_x86_64.c x86/compat: Adjust in_compat_syscall() to generic code under !COMPAT 2018-11-01 12:59:25 +01:00
sysfb_efi.c x86/sysfb_efi: Add quirks for some devices with swapped width and height 2019-07-22 10:47:11 +02:00
sysfb_simplefb.c x86/sysfb: Fix check for bad VRAM size 2020-02-24 08:36:29 +01:00
sysfb.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
tboot.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 335 2019-06-05 17:37:06 +02:00
tce_64.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
time.c x86_64: Fix jiffies ODR violation 2020-06-17 16:40:24 +02:00
tls.c x86/tls: Fix possible spectre-v1 in do_get_thread_area() 2019-06-27 23:48:04 +02:00
tls.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 193 2019-05-30 11:29:21 -07:00
topology.c x86/topology: Make DEBUG_HOTPLUG_CPU0 pr_info() more descriptive 2019-04-19 19:42:57 +02:00
trace_clock.c
tracepoint.c x86/kernel: Fix more -Wmissing-prototypes warnings 2018-12-08 12:24:35 +01:00
traps.c x86/mm, tracing: Fix CR2 corruption 2019-07-17 23:17:38 +02:00
tsc_msr.c x86/tsr: Fix tsc frequency enumeration bug on Lightning Mountain SoC 2020-08-21 13:05:36 +02:00
tsc_sync.c
tsc.c x86/tsc: Respect tsc command line paraemeter for clocksource_tsc_early 2019-11-05 01:24:56 +01:00
umip.c x86/umip: Add emulation (spoofing) for UMIP covered instructions in 64-bit processes as well 2019-09-10 08:36:16 +02:00
unwind_frame.c x86/stackframe/32: Provide consistent pt_regs 2019-06-25 10:23:47 +02:00
unwind_guess.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
unwind_orc.c x86/unwind/orc: Fix inactive tasks with stack pointer in %sp on GCC 10 compiled kernels 2020-11-05 11:43:12 +01:00
uprobes.c uprobes/x86: Fix detection of 32-bit user mode 2019-08-26 15:55:09 +02:00
verify_cpu.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 230 2019-06-19 17:09:06 +02:00
vm86_32.c signal: Remove task parameter from force_sig 2019-05-27 09:36:28 -05:00
vmlinux.lds.S x86, vmlinux.lds: Page-align end of ..page_aligned sections 2020-07-29 10:18:45 +02:00
vsmp_64.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 346 2019-06-05 17:37:08 +02:00
x86_init.c x86/timer: Don't skip PIT setup when APIC is disabled or in legacy mode 2020-02-11 04:35:52 -08:00