Skip to contentSkip to conversation

lib/syscall: Clear return values when no stack

PATCH In review Kees Cook 3 participants 3 messages Mar 23, 2017 – Mar 24, 2017 Library code

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 lib/syscall: Clear return values when no stack

Commit aa1f1a639621 ("lib/syscall: Pin the task stack in collect_syscall()") added logic to handle a process stack not existing, but left sp and pc uninitialized, which can be later reported via /proc/$pid/syscall for zombie processes, potentially exposing kernel memory to userspace.

Zombie /proc/$pid/syscall before:
-1 0xffffffff9a060100 0xffff92f42d6ad900

Zombie /proc/$pid/syscall after:
-1 0x0 0x0

Fixes aa1f1a639621 ("lib/syscall: Pin the task stack in collect_syscall()")
---
 lib/syscall.c | 1 +
 1 file changed, 1 insertion(+)
lib/syscall.c +1 -0
index 17d5ff5fa6a3..2c6cd1b5c3ea 100644
@@ -12,6 +12,7 @@ static int collect_syscall(struct task_struct *target, long *callno,
 
 	if (!try_get_task_stack(target)) {
 		/* Task has no stack, so the task isn't in a syscall. */
+		*sp = *pc = 0;
 		*callno = -1;
 		return 0;
 	}
Signature · 6 lines
2.7.4


-- 
Kees Cook
Pixel Security
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Kees Cook

Commit aa1f1a639621 ("lib/syscall: Pin the task stack in collect_syscall()") added logic to handle a process stack not existing, but left sp and pc uninitialized, which can be later reported via /proc/$pid/syscall for zombie processes, potentially exposing kernel memory to userspace.

Zombie /proc/$pid/syscall before:
-1 0xffffffff9a060100 0xffff92f42d6ad900

Quoted 7 lines

Zombie /proc/$pid/syscall after:
-1 0x0 0x0

Fixes aa1f1a639621 ("lib/syscall: Pin the task stack in collect_syscall()")

Whoops!

#2 lore raw
In reply to Kees Cook
lib/syscall: Clear return values when no stack
Commit-ID:  854fbd6e5f60fe99e8e3a569865409fca378f143
Gitweb:     http://git.kernel.org/tip/854fbd6e5f60fe99e8e3a569865409fca378f143
Author:     Kees Cook <[email protected]>
AuthorDate: Thu, 23 Mar 2017 15:46:16 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 24 Mar 2017 07:43:35 +0100

lib/syscall: Clear return values when no stack

Commit:

aa1f1a639621 ("lib/syscall: Pin the task stack in collect_syscall()")

... added logic to handle a process stack not existing, but left sp and pc uninitialized, which can be later reported via /proc/$pid/syscall for zombie processes, potentially exposing kernel memory to userspace.

Zombie /proc/$pid/syscall before:
-1 0xffffffff9a060100 0xffff92f42d6ad900

Zombie /proc/$pid/syscall after:
-1 0x0 0x0

Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes aa1f1a639621 ("lib/syscall: Pin the task stack in collect_syscall()")
---
 lib/syscall.c | 1 +
 1 file changed, 1 insertion(+)
lib/syscall.c +1 -0
index 17d5ff5..2c6cd1b 100644
@@ -12,6 +12,7 @@ static int collect_syscall(struct task_struct *target, long *callno,
 
 	if (!try_get_task_stack(target)) {
 		/* Task has no stack, so the task isn't in a syscall. */
+		*sp = *pc = 0;
 		*callno = -1;
 		return 0;
 	}