linux/arch/arm
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
..
boot soc: devicetree updates for v6.10, part 2 2024-05-20 15:11:53 -07:00
common
configs USB / Thunderbolt changes for 6.10-rc1 2024-05-22 11:40:09 -07:00
crypto
include - A series ("kbuild: enable more warnings by default") from Arnd 2024-05-22 18:59:29 -07:00
kernel ARM: 9405/1: ftrace: Don't assume stack frames are contiguous in memory 2024-06-10 12:00:27 +01:00
lib ARM: crypto: use CC_FLAGS_FPU for NEON CFLAGS 2024-05-19 14:36:17 -07:00
mach-actions
mach-alpine
mach-artpec
mach-aspeed
mach-at91
mach-axxia
mach-bcm
mach-berlin
mach-clps711x
mach-davinci
mach-digicolor
mach-dove
mach-ep93xx
mach-exynos
mach-footbridge
mach-gemini
mach-highbank
mach-hisi
mach-hpe
mach-imx
mach-ixp4xx
mach-keystone
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson
mach-milbeaut
mach-mmp
mach-mstar
mach-mv78xx0
mach-mvebu
mach-mxs
mach-nomadik
mach-npcm
mach-omap1
mach-omap2
mach-orion5x
mach-pxa
mach-qcom
mach-realtek
mach-rockchip
mach-rpc
mach-s3c
mach-s5pv210
mach-sa1100
mach-shmobile
mach-socfpga
mach-spear
mach-sti
mach-stm32
mach-sunxi
mach-tegra
mach-ux500
mach-versatile
mach-vt8500
mach-zynq
mm
net
nwfpe
plat-orion
probes
tools mseal: wire up mseal syscall 2024-05-23 19:40:26 -07:00
vdso
vfp
xen
Kbuild
Kconfig
Kconfig-nommu
Kconfig.assembler
Kconfig.debug
Kconfig.platforms
Makefile