original_kernel/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
Makefile
arch_timer.c
armksyms.c
asm-offsets.c
atags.h
atags_compat.c
atags_parse.c
atags_proc.c
bios32.c
bugs.c
cpuidle.c
crash_dump.c
debug.S
devtree.c
dma.c
early_printk.c
efi.c
elf.c
entry-armv.S
entry-common.S
entry-ftrace.S
entry-header.S
entry-v7m.S
fiq.c
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
head-nommu.S
head.S
head.h
hibernate.c
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
isa.c
iwmmxt.S
iwmmxt.h
jump_label.c
kgdb.c
machine_kexec.c
module-plts.c
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
perf_event_v7.c
perf_event_xscale.c
perf_regs.c
phys2virt.S
process.c
psci_smp.c
ptrace.c
reboot.c
reboot.h
relocate_kernel.S
return_address.c
setup.c
signal.c
signal.h
sigreturn_codes.S
sleep.S
smccc-call.S
smp.c
smp_scu.c
smp_tlb.c
smp_twd.c
spectre.c
stacktrace.c
suspend.c
swp_emulate.c
sys_arm.c
sys_oabi-compat.c
tcm.c
thumbee.c
time.c
topology.c
traps.c
unwind.c
v7m.c
vdso.c
vmcore_info.c
vmlinux-xip.lds.S
vmlinux.lds.S
xscale-cp0.c