public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* siginfo memory leak?
@ 2016-05-23 11:16 Michal Hocko
  2016-05-23 12:43 ` Martin Schwidefsky
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Michal Hocko @ 2016-05-23 11:16 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Aleksa Sarai, LKML, Martin Schwidefsky, Heiko Carstens,
	linux-s390, Ingo Molnar, Thomas Gleixner, H. Peter Anvin, x86

Hi,
Aleksa has reported that strace tells a bogus si_errno while debugging
something on s390:
[pid 20799] --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_errno=2510266, si_addr=0x100000000000000}

A quick look into do_sigsegv shows that siginfo is not completely
initialized and it indeed might leak the previous stack content
which will later gets to userspace. So unless I am missing something
we need something like the trivial patch below. I have tried to look
around and it seems that this is not the only place...

x86 do_error_trap doesn't do any initialization at all! It is hard to
tell other places. I have checked some and most of them do some
(partial) initialization.

So my primary question is whether we want to fix all those potential
places one by one or come up with something more systematic (e.g. a
macro to declare on stack siginfo). Btw. I am not even sure partial
initializations are correct and memset should be used unconditioanlly
(e.g. fill_sigtrap_info does do that).
---
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
index 791a4146052c..41913fac14e4 100644
--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -248,6 +248,7 @@ static noinline void do_sigsegv(struct pt_regs *regs, int si_code)
 	si.si_signo = SIGSEGV;
 	si.si_code = si_code;
 	si.si_addr = (void __user *)(regs->int_parm_long & __FAIL_ADDR_MASK);
+	si.si_errno = 0;
 	force_sig_info(SIGSEGV, &si, current);
 }
 
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index ade185a46b1d..f8b66ddbb47d 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -286,6 +286,7 @@ static void do_error_trap(struct pt_regs *regs, long error_code, char *str,
 
 	if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) !=
 			NOTIFY_STOP) {
+		memset(&info, 0, sizeof(info));
 		conditional_sti(regs);
 		do_trap(trapnr, signr, str, regs, error_code,
 			fill_trap_info(regs, signr, trapnr, &info));
 
-- 
Michal Hocko
SUSE Labs

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-05-23 17:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-23 11:16 siginfo memory leak? Michal Hocko
2016-05-23 12:43 ` Martin Schwidefsky
2016-05-23 13:05   ` Michal Hocko
2016-05-23 13:29     ` Martin Schwidefsky
2016-05-23 13:34       ` Michal Hocko
2016-05-23 13:43 ` [PATCH] s390: fix info leak in do_sigsegv Michal Hocko
2016-05-23 14:47   ` Martin Schwidefsky
2016-05-23 13:54 ` [PATCH] x86: fix potential memleak in do_error_trap Michal Hocko
2016-05-23 15:33   ` Oleg Nesterov
2016-05-23 17:47     ` Michal Hocko
2016-05-23 15:42 ` siginfo memory leak? Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox