Skip to contentSkip to conversation

signal: initialize k_sigaction in sys_signal()

PATCH In review Henry Martin 2 participants 2 messages Nov 23 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 signal: initialize k_sigaction in sys_signal()

sys_signal() builds a struct k_sigaction on the stack and only sets sa_handler, sa_flags and sa_mask. sa_restorer (and, on sparc, ka_restorer) keep whatever the previous syscall left at the same stack slot, and do_sigaction() stores the whole struct into sighand->action[sig - 1].

A 32-bit process can read sa_restorer back through compat rt_sigaction(oact), which always copies it to userspace. The leaked low 32 bits are stale kernel stack content, in practice a kernel text return address, so the two syscalls reveal the KASLR slide.

Zero-initialize the whole struct so the fix also covers architectures that keep the restorer in ka_restorer.

This issue was discovered by Tencent CodeBuddy Security.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 kernel/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/signal.c +1 -1
index dd770e68faee..460dd4d1d548 100644
@@ -4894,7 +4894,7 @@ SYSCALL_DEFINE1(ssetmask, int, newmask)
  */
 SYSCALL_DEFINE2(signal, int, sig, __sighandler_t, handler)
 {
-	struct k_sigaction new_sa, old_sa;
+	struct k_sigaction new_sa = { }, old_sa;
 	int ret;
 
 	new_sa.sa.sa_handler = handler;
Signature · 1 line
2.53.0
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Henry Martin

Zero-initialize the whole struct so the fix also covers architectures that keep the restorer in ka_restorer.

...

kernel/signal.c SYSCALL_DEFINE1(ssetmask, int, newmask) · line 4898

Quoted 5 lines

SYSCALL_DEFINE2(signal, int, sig, __sighandler_t, handler) {

kernel/signal.c +1 -1
-	struct k_sigaction new_sa, old_sa;
+	struct k_sigaction new_sa = { }, old_sa;
 	int ret;