sched: Fix information leak in sys_sched_getattr()
authorVegard Nossum <[email protected]>
Sun, 16 Feb 2014 21:24:17 +0000 (22:24 +0100)
committerThomas Gleixner <[email protected]>
Fri, 21 Feb 2014 20:27:10 +0000 (21:27 +0100)
We're copying the on-stack structure to userspace, but forgot to give
the right number of bytes to copy. This allows the calling process to
obtain up to PAGE_SIZE bytes from the stack (and possibly adjacent
kernel memory).

This fix copies only as much as we actually have on the stack
(attr->size defaults to the size of the struct) and leaves the rest of
the userspace-provided buffer untouched.

Found using kmemcheck + trinity.

Fixes: d50dde5a10f30 ("sched: Add new scheduler syscalls to support an extended scheduling parameters ABI")
Cc: Dario Faggioli <[email protected]>
Cc: Juri Lelli <[email protected]>
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Vegard Nossum <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Thomas Gleixner <[email protected]>
kernel/sched/core.c

index 33d030a133d2b0511701deb79f6b993197639818..a6e7470166c7e6ad19fdef5ba7e359fa98a00c8a 100644 (file)
@@ -3786,7 +3786,7 @@ static int sched_read_attr(struct sched_attr __user *uattr,
                attr->size = usize;
        }
 
-       ret = copy_to_user(uattr, attr, usize);
+       ret = copy_to_user(uattr, attr, attr->size);
        if (ret)
                return -EFAULT;