1 From cf01fb9985e8deb25ccf0ea54d916b8871ae0e62 Mon Sep 17 00:00:00 2001
2 From: Chris Salls <salls@cs.ucsb.edu>
3 Date: Fri, 7 Apr 2017 23:48:11 -0700
4 Subject: mm/mempolicy.c: fix error handling in set_mempolicy and mbind.
6 From: Chris Salls <salls@cs.ucsb.edu>
8 commit cf01fb9985e8deb25ccf0ea54d916b8871ae0e62 upstream.
10 In the case that compat_get_bitmap fails we do not want to copy the
11 bitmap to the user as it will contain uninitialized stack data and leak
14 Signed-off-by: Chris Salls <salls@cs.ucsb.edu>
15 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
16 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19 mm/mempolicy.c | 20 ++++++++------------
20 1 file changed, 8 insertions(+), 12 deletions(-)
24 @@ -1492,7 +1492,6 @@ COMPAT_SYSCALL_DEFINE5(get_mempolicy, in
25 COMPAT_SYSCALL_DEFINE3(set_mempolicy, int, mode, compat_ulong_t __user *, nmask,
26 compat_ulong_t, maxnode)
29 unsigned long __user *nm = NULL;
30 unsigned long nr_bits, alloc_size;
31 DECLARE_BITMAP(bm, MAX_NUMNODES);
32 @@ -1501,14 +1500,13 @@ COMPAT_SYSCALL_DEFINE3(set_mempolicy, in
33 alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
36 - err = compat_get_bitmap(bm, nmask, nr_bits);
37 + if (compat_get_bitmap(bm, nmask, nr_bits))
39 nm = compat_alloc_user_space(alloc_size);
40 - err |= copy_to_user(nm, bm, alloc_size);
41 + if (copy_to_user(nm, bm, alloc_size))
48 return sys_set_mempolicy(mode, nm, nr_bits+1);
51 @@ -1516,7 +1514,6 @@ COMPAT_SYSCALL_DEFINE6(mbind, compat_ulo
52 compat_ulong_t, mode, compat_ulong_t __user *, nmask,
53 compat_ulong_t, maxnode, compat_ulong_t, flags)
56 unsigned long __user *nm = NULL;
57 unsigned long nr_bits, alloc_size;
59 @@ -1525,14 +1522,13 @@ COMPAT_SYSCALL_DEFINE6(mbind, compat_ulo
60 alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
63 - err = compat_get_bitmap(nodes_addr(bm), nmask, nr_bits);
64 + if (compat_get_bitmap(nodes_addr(bm), nmask, nr_bits))
66 nm = compat_alloc_user_space(alloc_size);
67 - err |= copy_to_user(nm, nodes_addr(bm), alloc_size);
68 + if (copy_to_user(nm, nodes_addr(bm), alloc_size))
75 return sys_mbind(start, len, mode, nm, nr_bits+1, flags);