[klibc] alpha: Pass restorer to rt_sigaction() and disable executable stack
authorBen Hutchings <ben@decadent.org.uk>
Sun, 23 Aug 2020 14:18:19 +0000 (15:18 +0100)
committerThorsten Glaser <tg@mirbsd.de>
Wed, 26 May 2021 22:12:10 +0000 (23:12 +0100)
Origin: https://git.kernel.org/pub/scm/libs/klibc/klibc.git/commit/?id=570ed1e207cbe38ed487c722f8ac7db68e664a94

alpha does not support the SA_RESTORER flag, but allows specifiying a
restorer callback as an additional parameter to rt_sigaction().  We
should do this to avoid needing an executable stack.

* Force the SA_SIGINFO flag on for all signal handlers, so that we can
  always return from them with rt_sigreturn
* Define a __sigreturn() routine that calls rt_sigreturn
* Pass that routine as the last argument to rt_sigaction()
* Set KLIBCEXECSTACK=n

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Gbp-Pq: Name 0004-klibc-alpha-Pass-restorer-to-rt_sigaction-and-disabl.patch

usr/include/arch/alpha/klibc/archconfig.h
usr/klibc/arch/alpha/Kbuild
usr/klibc/arch/alpha/MCONFIG
usr/klibc/arch/alpha/sigreturn.S [new file with mode: 0644]
usr/klibc/sigaction.c

index 272fee0ad3560044257986121329d76e40380f91..9d28db12f0add338ddb0314040ad2eaef984f5c7 100644 (file)
@@ -10,6 +10,8 @@
 #define _KLIBC_ARCHCONFIG_H
 
 #define _KLIBC_USE_RT_SIG 1
+/* We provide our own restorer that call rt_sigreturn() */
+#define _KLIBC_NEEDS_SA_SIGINFO 1
 #define _KLIBC_STATFS_F_TYPE_64 0
 
 #endif                         /* _KLIBC_ARCHCONFIG_H */
index 2e566eb6fbc1de18e482aadf5c8d5a19a357147a..89386aeaddc9d349fd0d9f2a868ba2e18fc85895 100644 (file)
@@ -9,7 +9,7 @@
 
 always  := crt0.o
 targets := crt0.o
-klib-y := pipe.o setjmp.o syscall.o sysdual.o
+klib-y := pipe.o setjmp.o sigreturn.o syscall.o sysdual.o
 
 # Special CFLAGS for the divide code
 DIVCFLAGS = $(KLIBCREQFLAGS) $(KLIBCARCHREQFLAGS) \
index 072adb8574f7b7dcdd5622df6182d0a1c9566891..e71db264253f3dfbcc5f32b706e42ab7da749b0e 100644 (file)
@@ -15,6 +15,5 @@ KLIBCBITSIZE  = 64
 # the binary.
 KLIBCSHAREDFLAGS       = -Ttext-segment 0x1c0000000
 
-# Kernel uses stack trampoline for signal return unless we set
-# sa_restorer
-KLIBCEXECSTACK := y
+# Kernel uses our sa_restorer for signal return
+KLIBCEXECSTACK := n
diff --git a/usr/klibc/arch/alpha/sigreturn.S b/usr/klibc/arch/alpha/sigreturn.S
new file mode 100644 (file)
index 0000000..a979b7a
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * arch/alpha/sigreturn.S
+ */
+
+#include <machine/asm.h>
+#include <asm/unistd.h>
+
+       .text
+       .align  3
+       .type   __sigreturn,@function
+       .ent    __sigreturn,0
+       .globl  __sigreturn
+__sigreturn:
+       mov     sp,a0                   # struct sigcontext on stack
+       lda     v0,__NR_rt_sigreturn(zero)
+       callsys
+       .size   __sigreturn,.-__sigreturn
+       .end    __sigreturn
index dbf8e2202e2f6ed845cd4c27d03e35d313129df2..cd2fdfef4867ee67a275cfbe1da2a47c8ef6b3b3 100644 (file)
@@ -13,7 +13,7 @@ __extern int __rt_sigaction(int, const struct sigaction *, struct sigaction *,
                            void (*)(void), size_t);
 #elif defined(__alpha__)
 __extern int __rt_sigaction(int, const struct sigaction *, struct sigaction *,
-                           size_t, void *);
+                           size_t, void (*)(void));
 #else
 __extern int __rt_sigaction(int, const struct sigaction *, struct sigaction *,
                            size_t);
@@ -52,7 +52,7 @@ int sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
                rv = __rt_sigaction(sig, act, oact, restorer, sizeof(sigset_t));
        }
 # elif defined(__alpha__)
-       rv = __rt_sigaction(sig, act, oact, sizeof(sigset_t), NULL);
+       rv = __rt_sigaction(sig, act, oact, sizeof(sigset_t), &__sigreturn);
 # else
        rv = __rt_sigaction(sig, act, oact, sizeof(sigset_t));
 # endif