linux/arch/arm/kernel
Ard Biesheuvel e3cf20e5c6 ARM: 9405/1: ftrace: Don't assume stack frames are contiguous in memory
The frame pointer unwinder relies on a standard layout of the stack
frame, consisting of (in downward order)

   Calling frame:
     PC   <---------+
     LR             |
     SP             |
     FP             |
     .. locals ..   |
   Callee frame:    |
     PC             |
     LR             |
     SP             |
     FP   ----------+

where after storing its previous value on the stack, FP is made to point
at the location of PC in the callee stack frame, using the canonical
prologue:

   mov     ip, sp
   stmdb   sp!, {fp, ip, lr, pc}
   sub     fp, ip, #4

The ftrace code assumes that this activation record is pushed first, and
that any stack space for locals is allocated below this. Strict
adherence to this would imply that the caller's value of SP at the time
of the function call can always be obtained by adding 4 to FP (which
points to PC in the callee frame).

However, recent versions of GCC appear to deviate from this rule, and so
the only reliable way to obtain the caller's value of SP is to read it
from the activation record. Since this involves a read from memory
rather than simple arithmetic, we need to use the uaccess API here which
protects against inadvertent data aborts resulting from attempts to
dereference bogus FP values.

The plain uaccess API is ftrace instrumented itself, so to avoid
unbounded recursion, use the __get_kernel_nofault() primitive directly.

Closes: https://lore.kernel.org/all/alp44tukzo6mvcwl4ke4ehhmojrqnv6xfcdeuliybxfjfvgd3e@gpjvwj33cc76

Closes: https://lore.kernel.org/all/d870c149-4363-43de-b0ea-7125dec5608e@broadcom.com/

Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reported-by: Justin Chen <justin.chen@broadcom.com>
Tested-by: Thorsten Scherer <t.scherer@eckelmann.de>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
2024-06-10 12:00:27 +01:00
..
.gitignore
arch_timer.c
armksyms.c
asm-offsets.c ARM: 9358/2: Implement PAN for LPAE by TTBR0 page table walks disablement 2024-04-18 12:10:46 +01:00
atags.h
atags_compat.c
atags_parse.c vgacon: clean up global screen_info instances 2023-10-17 10:17:02 +02:00
atags_proc.c atags_proc: Add __counted_by for struct buffer and use struct_size() 2023-12-02 12:32:07 -08:00
bios32.c PCI: Introduce pci_dev_for_each_resource() 2023-04-04 10:43:52 -05:00
bugs.c ARM: cpu: Switch to arch_cpu_finalize_init() 2023-06-16 10:15:59 +02:00
cpuidle.c ARM: cpuidle: Drop of_device.h include 2023-04-13 17:46:34 -05:00
crash_dump.c
debug.S
devtree.c ARM: 9322/1: Explicitly include correct DT includes 2023-10-05 16:15:42 +01:00
dma.c
early_printk.c
efi.c vgacon: clean up global screen_info instances 2023-10-17 10:17:02 +02:00
elf.c
entry-armv.S Merge branch 'devel-stable' into for-next 2023-08-14 12:18:06 +01:00
entry-common.S ARM: ptrace: Restore syscall restart tracing 2023-08-16 13:58:49 -07:00
entry-ftrace.S ARM: 9382/1: ftrace: Define ftrace_stub_graph 2024-04-18 12:12:18 +01:00
entry-header.S
entry-v7m.S ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
fiq.c ARM: 9315/1: fiq: include asm/mach/irq.h for prototypes 2023-06-19 09:36:00 +01:00
fiqasm.S
ftrace.c ARM: 9405/1: ftrace: Don't assume stack frames are contiguous in memory 2024-06-10 12:00:27 +01:00
head-common.S
head-inflate-data.c ARM: 9310/1: xip-kernel: add __inflate_kernel_data prototype 2023-06-19 09:35:56 +01:00
head-nommu.S ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
head.h ARM: 9310/1: xip-kernel: add __inflate_kernel_data prototype 2023-06-19 09:35:56 +01:00
head.S ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
hibernate.c ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
hw_breakpoint.c ARM development updates for v6.10-rc1 2024-05-17 08:53:47 -07:00
hyp-stub.S
insn.c
io.c
irq.c fix missing vmalloc.h includes 2024-04-25 20:55:49 -07:00
isa.c arm: Remove now superfluous sentinel elem from ctl_table arrays 2023-10-10 15:22:02 -07:00
iwmmxt.h
iwmmxt.S ARM: 9352/1: iwmmxt: Remove support for PJ4/PJ4B cores 2024-02-26 10:16:31 +00:00
jump_label.c
kgdb.c
machine_kexec.c arch, crash: move arch_crash_save_vmcoreinfo() out to file vmcore_info.c 2024-02-23 17:48:25 -08:00
Makefile ARM updates for v6.9-rc1 2024-03-23 09:17:03 -07:00
module-plts.c ARM: module: Use module_init_layout_section() to spot init sections 2023-08-03 13:42:02 -07:00
module.c arch: make execmem setup available regardless of CONFIG_MODULES 2024-05-14 00:31:44 -07:00
opcodes.c
paravirt.c
patch.c
perf_callchain.c
perf_event_v6.c ARM: SoC code changes for 6.8 2024-01-11 11:42:53 -08:00
perf_event_v7.c arm: pmu: Move error message and -EOPNOTSUPP to individual PMUs 2023-12-12 09:46:22 +00:00
perf_event_xscale.c arm: perf: Remove PMU locking 2023-12-05 12:40:59 +00:00
perf_regs.c
phys2virt.S
process.c ARM: kernel: Get rid of thread_info::used_cp[] array 2023-05-17 15:08:22 +02:00
psci_smp.c
ptrace.c ARM updates for v6.6-rc1 2023-08-31 12:49:10 -07:00
reboot.c
reboot.h
relocate_kernel.S
return_address.c
setup.c arm, crash: wrap crash dumping code into crash related ifdefs 2024-02-23 17:48:24 -08:00
signal.c x86/shstk: Add user control-protection fault handler 2023-08-02 15:01:50 -07:00
signal.h
sigreturn_codes.S
sleep.S ARM: 9381/1: kasan: clear stale stack poison 2024-04-29 14:11:25 +01:00
smccc-call.S
smp.c nmi_backtrace: allow excluding an arbitrary CPU 2023-08-18 10:19:00 -07:00
smp_scu.c
smp_tlb.c
smp_twd.c
spectre.c
stacktrace.c
suspend.c ARM: 9358/2: Implement PAN for LPAE by TTBR0 page table walks disablement 2024-04-18 12:10:46 +01:00
swp_emulate.c
sys_arm.c ARM: 9309/1: add missing syscall prototypes 2023-06-19 09:35:55 +01:00
sys_oabi-compat.c ARM: 9309/1: add missing syscall prototypes 2023-06-19 09:35:55 +01:00
tcm.c ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
thumbee.c
time.c
topology.c sched/balancing: Rename rebalance_domains() => sched_balance_domains() 2024-03-12 11:59:59 +01:00
traps.c fix missing vmalloc.h includes 2024-04-25 20:55:49 -07:00
unwind.c ARM: 9349/1: unwind: Add missing "Call trace:" line 2024-02-24 16:47:19 +00:00
v7m.c
vdso.c vdso/ARM: Make union vdso_data_store available for all architectures 2024-02-20 20:56:00 +01:00
vmcore_info.c arch, crash: move arch_crash_save_vmcoreinfo() out to file vmcore_info.c 2024-02-23 17:48:25 -08:00
vmlinux-xip.lds.S ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
vmlinux.lds.S ARM: mm: Make virt_to_pfn() a static inline 2023-05-29 11:27:08 +02:00
xscale-cp0.c ARM: iwmmxt: Use undef hook to enable coprocessor for task 2023-05-17 15:08:22 +02:00