glibc/sysdeps
Raoni Fassina Firmino 5ee506ed35 powerpc64: Workaround sigtramp vdso return call
A not so recent kernel change[1] changed how the trampoline
`__kernel_sigtramp_rt64` is used to call signal handlers.

This was exposed on the test misc/tst-sigcontext-get_pc

Before kernel 5.9, the kernel set LR to the trampoline address and
jumped directly to the signal handler, and at the end the signal
handler, as any other function, would `blr` to the address set.  In
other words, the trampoline was executed just at the end of the signal
handler and the only thing it did was call sigreturn.  But since
kernel 5.9 the kernel set CTRL to the signal handler and calls to the
trampoline code, the trampoline then `bctrl` to the address in CTRL,
setting the LR to the next instruction in the middle of the
trampoline, when the signal handler returns, the rest of the
trampoline code executes the same code as before.

Here is the full trampoline code as of kernel 5.11.0-rc5 for
reference:

    V_FUNCTION_BEGIN(__kernel_sigtramp_rt64)
    .Lsigrt_start:
            bctrl   /* call the handler */
            addi    r1, r1, __SIGNAL_FRAMESIZE
            li      r0,__NR_rt_sigreturn
            sc
    .Lsigrt_end:
    V_FUNCTION_END(__kernel_sigtramp_rt64)

This new behavior breaks how `backtrace()` uses to detect the
trampoline frame to correctly reconstruct the stack frame when it is
called from inside a signal handling.

This workaround rely on the fact that the trampoline code is at very
least two (maybe 3?) instructions in size (as it is in the 32 bits
version, only on `li` and `sc`), so it is safe to check the return
address be in the range __kernel_sigtramp_rt64 .. + 4.

[1] subject: powerpc/64/signal: Balance return predictor stack in signal trampoline
    commit: 0138ba5783ae0dcc799ad401a1e8ac8333790df9
    url: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0138ba5783ae0dcc799ad401a1e8ac8333790df9

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-01-28 13:57:50 -03:00
..
aarch64 aarch64: Fix the list of tested IFUNC variants [BZ #26818] 2021-01-25 16:15:54 +00:00
alpha Remove dbl-64/wordsize-64 (part 2) 2021-01-07 15:26:26 +00:00
arc ARC: nofpu: Regenerate ulps 2021-01-17 16:39:45 -08:00
arm Update arm libm-test-ulps. 2021-01-18 20:22:51 +00:00
csky Update C-SKY libm-test-ulps 2021-01-23 19:00:00 +00:00
generic Use <startup.h> in __libc_init_secure 2021-01-19 09:55:47 -08:00
gnu Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
hppa Update hppa libm-test-ulps 2021-01-18 14:23:10 +00:00
htl Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
hurd Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
i386 configure: Check for static PIE support 2021-01-21 15:54:50 +00:00
ia64 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
ieee754 math: Add BZ#18980 fix back on dbl-64 cosh 2021-01-11 16:56:33 -03:00
m68k Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
mach Revert "linux: Move {f}xstat{at} to compat symbols" for static build 2021-01-21 14:11:53 -03:00
microblaze Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
mips Update MIPS libm-test-ulps. 2021-01-18 21:36:00 +00:00
nios2 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
nptl Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
posix posix: consume less entropy on tempname 2021-01-12 09:50:54 -03:00
powerpc powerpc64: Workaround sigtramp vdso return call 2021-01-28 13:57:50 -03:00
pthread Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
riscv riscv: Initialize $gp before resolving the IRELATIVE relocation 2021-01-10 21:25:16 -05:00
s390 Remove dbl-64/wordsize-64 (part 2) 2021-01-07 15:26:26 +00:00
sh Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
sparc Remove dbl-64/wordsize-64 (part 2) 2021-01-07 15:26:26 +00:00
unix linux: mips: Fix getdents64 fallback on mips64-n32 2021-01-22 15:44:41 -03:00
wordsize-32 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wordsize-64 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
x86 Fix misplaced const 2021-01-25 15:09:02 +01:00
x86_64 configure: Check for static PIE support 2021-01-21 15:54:50 +00:00