0 | 0 |
From: Ben Hutchings <ben@decadent.org.uk>
|
1 | |
Date: Thu, 30 Apr 2020 13:31:32 +0100
|
2 | |
Subject: [klibc] alpha: Set sa_restorer for signals and disable executable stack
|
3 | |
Origin: https://git.kernel.org/pub/scm/libs/klibc/klibc.git/commit?id=7f84d11885cf3e9298d53a2714800a8ac9c4dd74
|
|
1 |
Date: Sun, 23 Aug 2020 15:18:19 +0100
|
|
2 |
Subject: [klibc] alpha: Pass restorer to rt_sigaction() and disable executable stack
|
4 | 3 |
|
5 | |
Add a __sigreturn routine and point sa_restorer to it by default, so
|
6 | |
that the kernel doesn't create stack trampolines for signal return.
|
7 | |
With that done, we no longer need an executable stack.
|
|
4 |
alpha does not support the SA_RESTORER flag, but allows specifiying a
|
|
5 |
restorer callback as an additional parameter to rt_sigaction().
|
|
6 |
|
|
7 |
Define an __rt_sigreturn routine and pass that, so that the kernel
|
|
8 |
doesn't create stack trampolines for signal return. With that done,
|
|
9 |
we no longer need an executable stack.
|
8 | 10 |
|
9 | 11 |
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
10 | 12 |
---
|
11 | |
usr/include/arch/alpha/klibc/archconfig.h | 3 +++
|
|
13 |
usr/include/arch/alpha/klibc/archsignal.h | 8 +++++++-
|
12 | 14 |
usr/klibc/arch/alpha/Kbuild | 2 +-
|
13 | 15 |
usr/klibc/arch/alpha/MCONFIG | 5 ++---
|
14 | |
usr/klibc/arch/alpha/sigreturn.S | 16 ++++++++++++++++
|
15 | |
4 files changed, 22 insertions(+), 4 deletions(-)
|
16 | |
create mode 100644 usr/klibc/arch/alpha/sigreturn.S
|
|
16 |
usr/klibc/arch/alpha/rt_sigreturn.S | 18 ++++++++++++++++++
|
|
17 |
usr/klibc/sigaction.c | 2 +-
|
|
18 |
5 files changed, 29 insertions(+), 6 deletions(-)
|
|
19 |
create mode 100644 usr/klibc/arch/alpha/rt_sigreturn.S
|
17 | 20 |
|
18 | |
diff --git a/usr/include/arch/alpha/klibc/archconfig.h b/usr/include/arch/alpha/klibc/archconfig.h
|
19 | |
index 272fee0a..b80d299f 100644
|
20 | |
--- a/usr/include/arch/alpha/klibc/archconfig.h
|
21 | |
+++ b/usr/include/arch/alpha/klibc/archconfig.h
|
22 | |
@@ -12,4 +12,7 @@
|
23 | |
#define _KLIBC_USE_RT_SIG 1
|
24 | |
#define _KLIBC_STATFS_F_TYPE_64 0
|
|
21 |
diff --git a/usr/include/arch/alpha/klibc/archsignal.h b/usr/include/arch/alpha/klibc/archsignal.h
|
|
22 |
index 2193a352..0906f338 100644
|
|
23 |
--- a/usr/include/arch/alpha/klibc/archsignal.h
|
|
24 |
+++ b/usr/include/arch/alpha/klibc/archsignal.h
|
|
25 |
@@ -9,6 +9,12 @@
|
|
26 |
#define _KLIBC_ARCHSIGNAL_H
|
25 | 27 |
|
26 | |
+/* So that we can avoid stack trampolines */
|
27 | |
+#define _KLIBC_NEEDS_SA_RESTORER 1
|
|
28 |
#include <asm/signal.h>
|
|
29 |
-/* No special stuff for this architecture */
|
28 | 30 |
+
|
29 | |
#endif /* _KLIBC_ARCHCONFIG_H */
|
|
31 |
+/*
|
|
32 |
+ * Passed as last parameter to __rt_sigaction(). It is a function
|
|
33 |
+ * that should have type void (void), but syscalls.pl can't parse
|
|
34 |
+ * function types in syscall parameters.
|
|
35 |
+ */
|
|
36 |
+extern void __rt_sigreturn;
|
|
37 |
|
|
38 |
#endif
|
30 | 39 |
diff --git a/usr/klibc/arch/alpha/Kbuild b/usr/klibc/arch/alpha/Kbuild
|
31 | |
index 2e566eb6..eef7cfb4 100644
|
|
40 |
index 2e566eb6..6a62d47d 100644
|
32 | 41 |
--- a/usr/klibc/arch/alpha/Kbuild
|
33 | 42 |
+++ b/usr/klibc/arch/alpha/Kbuild
|
34 | 43 |
@@ -9,7 +9,7 @@
|
|
36 | 45 |
always := crt0.o
|
37 | 46 |
targets := crt0.o
|
38 | 47 |
-klib-y := pipe.o setjmp.o syscall.o sysdual.o
|
39 | |
+klib-y := pipe.o setjmp.o syscall.o sysdual.o sigreturn.o
|
|
48 |
+klib-y := pipe.o setjmp.o syscall.o sysdual.o rt_sigreturn.o
|
40 | 49 |
|
41 | 50 |
# Special CFLAGS for the divide code
|
42 | 51 |
DIVCFLAGS = $(KLIBCREQFLAGS) $(KLIBCARCHREQFLAGS) \
|
|
53 | 62 |
-KLIBCEXECSTACK := y
|
54 | 63 |
+# Kernel uses our sa_restorer for signal return
|
55 | 64 |
+KLIBCEXECSTACK := n
|
56 | |
diff --git a/usr/klibc/arch/alpha/sigreturn.S b/usr/klibc/arch/alpha/sigreturn.S
|
|
65 |
diff --git a/usr/klibc/arch/alpha/rt_sigreturn.S b/usr/klibc/arch/alpha/rt_sigreturn.S
|
57 | 66 |
new file mode 100644
|
58 | |
index 00000000..95415edd
|
|
67 |
index 00000000..e41b5544
|
59 | 68 |
--- /dev/null
|
60 | |
+++ b/usr/klibc/arch/alpha/sigreturn.S
|
61 | |
@@ -0,0 +1,16 @@
|
|
69 |
+++ b/usr/klibc/arch/alpha/rt_sigreturn.S
|
|
70 |
@@ -0,0 +1,18 @@
|
62 | 71 |
+/*
|
63 | 72 |
+ * arch/alpha/sigreturn.S
|
64 | 73 |
+ */
|
65 | 74 |
+
|
|
75 |
+#include <machine/asm.h>
|
66 | 76 |
+#include <asm/unistd.h>
|
67 | 77 |
+
|
68 | 78 |
+ .text
|
69 | 79 |
+ .align 3
|
70 | |
+ .type __sigreturn,@function
|
71 | |
+ .ent __sigreturn,0
|
72 | |
+ .globl __sigreturn
|
73 | |
+__sigreturn:
|
74 | |
+ mov sp,a0 ; struct sigcontext on stack
|
75 | |
+ lda v0,__NR_sigreturn(zero)
|
|
80 |
+ .type __rt_sigreturn,@function
|
|
81 |
+ .ent __rt_sigreturn,0
|
|
82 |
+ .globl __rt_sigreturn
|
|
83 |
+__rt_sigreturn:
|
|
84 |
+ mov sp,a0 # struct sigcontext on stack
|
|
85 |
+ lda v0,__NR_rt_sigreturn(zero)
|
76 | 86 |
+ callsys
|
77 | |
+ .size __sigreturn,.-__sigreturn
|
|
87 |
+ .size __rt_sigreturn,.-__rt_sigreturn
|
|
88 |
+ .end __rt_sigreturn
|
|
89 |
diff --git a/usr/klibc/sigaction.c b/usr/klibc/sigaction.c
|
|
90 |
index 19a8a54b..108c8385 100644
|
|
91 |
--- a/usr/klibc/sigaction.c
|
|
92 |
+++ b/usr/klibc/sigaction.c
|
|
93 |
@@ -47,7 +47,7 @@ int sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
|
|
94 |
rv = __rt_sigaction(sig, act, oact, restorer, sizeof(sigset_t));
|
|
95 |
}
|
|
96 |
# elif defined(__alpha__)
|
|
97 |
- rv = __rt_sigaction(sig, act, oact, sizeof(sigset_t), NULL);
|
|
98 |
+ rv = __rt_sigaction(sig, act, oact, sizeof(sigset_t), &__rt_sigreturn);
|
|
99 |
# else
|
|
100 |
rv = __rt_sigaction(sig, act, oact, sizeof(sigset_t));
|
|
101 |
# endif
|