linux-user/sh4: fix unwinding through vdso signal trampolines
cover linux-user/sh4: fix unwinding through vdso signal trampolines
Unwinding through a signal handler with the sh4 vdso is broken in two
ways: libunwind no longer recognizes the trampolines, since they don't use the kernel's instruction sequence, and libgcc applies the sigreturn CFA to rt_sigreturn frames. Patch 3 aligns the trampolines like the kernel does.
Matt Turner (3):
linux-user/sh4: use the kernel's sigreturn trampoline sequence in the
vdso
linux-user/sh4: fix vdso CFA for rt_sigreturn frames linux-user/sh4: align the vdso sigreturn trampolines
linux-user/sh4/vdso-be.so | Bin 2704 -> 2724 bytes linux-user/sh4/vdso-le.so | Bin 2704 -> 2724 bytes linux-user/sh4/vdso.S | 31 ++++++++++++++++++++++--------- 3 files changed, 22 insertions(+), 9 deletions(-)
Signature · 1 line
2.54.0
PATCH 1/3 linux-user/sh4: use the kernel's sigreturn trampoline sequence in the vdso
With the vdso, default_sigreturn and default_rt_sigreturn point at __kernel_sigreturn and __kernel_rt_sigreturn and setup_sigtramp() is no longer used. The vdso trampolines load the syscall number with mov.l instead of the kernel's mov.w/trapa/or r0,r0 sequence, which undoes commit 9ac5aa7227 ("linux-user/sh4: Fix setup_sigtramp to match Linux kernel trampoline pattern"): libunwind's unw_is_signal_frame() no longer recognizes the signal frame, so unwinding through a signal handler stops there.
Use the sequence from the kernel's own vdso,arch/sh/kernel/vsyscall/vsyscall-sigreturn.S.
--- linux-user/sh4/vdso-be.so | Bin 2704 -> 2720 bytes linux-user/sh4/vdso-le.so | Bin 2704 -> 2720 bytes linux-user/sh4/vdso.S | 26 ++++++++++++++++++-------- 3 files changed, 18 insertions(+), 8 deletions(-)
linux-user/sh4/vdso-be.so binary +0 -0
linux-user/sh4/vdso-le.so binary +0 -0
linux-user/sh4/vdso.S +18 -8
@@ -43,6 +43,22 @@ vdso_syscall __vdso_clock_gettime64, __NR_clock_gettime64 vdso_syscall __vdso_clock_getres, __NR_clock_getres vdso_syscall __vdso_gettimeofday, __NR_gettimeofday +/* + * Same instruction sequence as the kernel's + * arch/sh/kernel/vsyscall/vsyscall-sigreturn.S. libunwind matches these + * bytes to recognize a signal frame. + */ +.macro sigreturn_tramp nr + mov.w 1f, r3 + trapa #0x10 + or r0, r0 + or r0, r0 + or r0, r0 + or r0, r0 + or r0, r0 +1: .word \nr +.endm + /* * Signal return trampolines. *
@@ -122,20 +138,14 @@ vdso_syscall __vdso_gettimeofday, __NR_gettimeofday sigreturn_region_start: __kernel_sigreturn: - mov.l 1f, r3 - trapa #0x10 - .align 2 -1: .long __NR_sigreturn + sigreturn_tramp __NR_sigreturn endf __kernel_sigreturn /* Update CFA base for the rt_sigreturn frame layout. */ .cfi_def_cfa_offset RT_SIGFRAME_SC_OFFSET __kernel_rt_sigreturn: - mov.l 2f, r3 - trapa #0x10 - .align 2 -2: .long __NR_rt_sigreturn + sigreturn_tramp __NR_rt_sigreturn endf __kernel_rt_sigreturn sigreturn_region_end:
Signature · 1 line
2.54.0
Re: [PATCH 1/3] linux-user/sh4: use the kernel's sigreturn trampoline sequence in the vdso
Quoted 12 lines · Matt Turner
With the vdso,
default_sigreturnanddefault_rt_sigreturnpoint at__kernel_sigreturnand__kernel_rt_sigreturnandsetup_sigtramp()is no longer used. The vdso trampolines load the syscall number with mov.l instead of the kernel's mov.w/trapa/or r0,r0 sequence, which undoes commit9ac5aa7227("linux-user/sh4: Fixsetup_sigtrampto match Linux kernel trampoline pattern"): libunwind'sunw_is_signal_frame()no longer recognizes the signal frame, so unwinding through a signal handler stops there.Use the sequence from the kernel's own vdso,
arch/sh/kernel/vsyscall/vsyscall-sigreturn.S.
Quoted 8 lines
Fixes 975bd51a88 ("linux-user/sh4: add VDSO support for sh4 and sh4eb")Signed-off-by Matt Turner <[email protected]>--- linux-user/sh4/vdso-be.so | Bin 2704 -> 2720 bytes linux-user/sh4/vdso-le.so | Bin 2704 -> 2720 bytes linux-user/sh4/vdso.S | 26 ++++++++++++++++++-------- 3 files changed, 18 insertions(+), 8 deletions(-)
For the whole series:
Series applied to the linux-user-next git tree.
Thanks!
Helge
PATCH 2/3 linux-user/sh4: fix vdso CFA for rt_sigreturn frames
In reply to Matt TurnerThe unwinder looks up a return address as IP - 1 (hence the nop before sigreturn_region_start). For a frame returning to __kernel_rt_sigreturn that is the last byte of __kernel_sigreturn, which still has the sigreturn CFA, so the rt_sigreturn frame is unwound with the wrong sigcontext offset. _Unwind_Backtrace() from an SA_SIGINFO handler stops after three frames.
Add a nop after .cfi_def_cfa_offset, as linux-user/i386/vdso.S does.
--- linux-user/sh4/vdso-be.so | Bin 2720 -> 2720 bytes linux-user/sh4/vdso-le.so | Bin 2720 -> 2720 bytes linux-user/sh4/vdso.S | 3 ++- 3 files changed, 2 insertions(+), 1 deletion(-)
linux-user/sh4/vdso-be.so binary +0 -0
linux-user/sh4/vdso-le.so binary +0 -0
linux-user/sh4/vdso.S +2 -1
@@ -141,8 +141,9 @@ __kernel_sigreturn: sigreturn_tramp __NR_sigreturn endf __kernel_sigreturn - /* Update CFA base for the rt_sigreturn frame layout. */ + /* rt_sigreturn frame layout; nop for the same reason as above. */ .cfi_def_cfa_offset RT_SIGFRAME_SC_OFFSET + nop __kernel_rt_sigreturn: sigreturn_tramp __NR_rt_sigreturn
Signature · 1 line
2.54.0
PATCH 3/3 linux-user/sh4: align the vdso sigreturn trampolines
In reply to Matt Turnerlibunwind's unw_is_signal_frame() reads the trampoline as 32-bit words, but __kernel_sigreturn is only 2-byte aligned. Align both trampolines to 4 bytes, as the kernel's vsyscall-sigreturn.S does (with .balign 32).
--- linux-user/sh4/vdso-be.so | Bin 2720 -> 2724 bytes linux-user/sh4/vdso-le.so | Bin 2720 -> 2724 bytes linux-user/sh4/vdso.S | 2 ++ 3 files changed, 2 insertions(+)
linux-user/sh4/vdso-be.so binary +0 -0
linux-user/sh4/vdso-le.so binary +0 -0
linux-user/sh4/vdso.S +2 -0
@@ -135,6 +135,7 @@ vdso_syscall __vdso_gettimeofday, __NR_gettimeofday .cfi_offset 24, SC_FPSCR nop + .balign 4 sigreturn_region_start: __kernel_sigreturn:
@@ -144,6 +145,7 @@ endf __kernel_sigreturn /* rt_sigreturn frame layout; nop for the same reason as above. */ .cfi_def_cfa_offset RT_SIGFRAME_SC_OFFSET nop + .balign 4 __kernel_rt_sigreturn: sigreturn_tramp __NR_rt_sigreturn
Signature · 1 line
2.54.0
Re: [PATCH 3/3] linux-user/sh4: align the vdso sigreturn trampolines
Quoted 10 lines · Matt Turner
libunwind's
unw_is_signal_frame()reads the trampoline as 32-bit words, but__kernel_sigreturnis only 2-byte aligned. Align both trampolines to 4 bytes, as the kernel'svsyscall-sigreturn.Sdoes (with .balign 32).Signed-off-by Matt Turner <[email protected]>--- linux-user/sh4/vdso-be.so | Bin 2720 -> 2724 bytes linux-user/sh4/vdso-le.so | Bin 2720 -> 2724 bytes linux-user/sh4/vdso.S | 2 ++ 3 files changed, 2 insertions(+)
Re: [PATCH 3/3] linux-user/sh4: align the vdso sigreturn trampolines
In reply to Matt TurnerQuoted 10 lines · Matt Turner
libunwind's
unw_is_signal_frame()reads the trampoline as 32-bit words, but__kernel_sigreturnis only 2-byte aligned. Align both trampolines to 4 bytes, as the kernel'svsyscall-sigreturn.Sdoes (with .balign 32).Signed-off-by Matt Turner <[email protected]>--- linux-user/sh4/vdso-be.so | Bin 2720 -> 2724 bytes linux-user/sh4/vdso-le.so | Bin 2720 -> 2724 bytes linux-user/sh4/vdso.S | 2 ++ 3 files changed, 2 insertions(+)
Shouldn't this one be picked up for 11.1.x stable branch too, like the other 2 in this series?
Thanks,
/mjt
Re: [PATCH 3/3] linux-user/sh4: align the vdso sigreturn trampolines
Quoted 13 lines · Michael Tokarev
Quoted 10 lines · Matt Turner
libunwind's
unw_is_signal_frame()reads the trampoline as 32-bit words, but__kernel_sigreturnis only 2-byte aligned. Align both trampolines to 4 bytes, as the kernel'svsyscall-sigreturn.Sdoes (with .balign 32).Signed-off-by Matt Turner <[email protected]>--- linux-user/sh4/vdso-be.so | Bin 2720 -> 2724 bytes linux-user/sh4/vdso-le.so | Bin 2720 -> 2724 bytes linux-user/sh4/vdso.S | 2 ++ 3 files changed, 2 insertions(+)
Quoted 2 lines
Shouldn't this one be picked up for 11.1.x stable branch too, like the other 2 in this series?
Yes please (and thanks!)