]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.61/mm-mempolicy.c-fix-error-handling-in-set_mempolicy-and-mbind.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 4.4.61 / mm-mempolicy.c-fix-error-handling-in-set_mempolicy-and-mbind.patch
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.
5
6 From: Chris Salls <salls@cs.ucsb.edu>
7
8 commit cf01fb9985e8deb25ccf0ea54d916b8871ae0e62 upstream.
9
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
12 sensitive data.
13
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>
17
18 ---
19 mm/mempolicy.c | 20 ++++++++------------
20 1 file changed, 8 insertions(+), 12 deletions(-)
21
22 --- a/mm/mempolicy.c
23 +++ b/mm/mempolicy.c
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)
27 {
28 - long err = 0;
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;
34
35 if (nmask) {
36 - err = compat_get_bitmap(bm, nmask, nr_bits);
37 + if (compat_get_bitmap(bm, nmask, nr_bits))
38 + return -EFAULT;
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))
42 + return -EFAULT;
43 }
44
45 - if (err)
46 - return -EFAULT;
47 -
48 return sys_set_mempolicy(mode, nm, nr_bits+1);
49 }
50
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)
54 {
55 - long err = 0;
56 unsigned long __user *nm = NULL;
57 unsigned long nr_bits, alloc_size;
58 nodemask_t bm;
59 @@ -1525,14 +1522,13 @@ COMPAT_SYSCALL_DEFINE6(mbind, compat_ulo
60 alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
61
62 if (nmask) {
63 - err = compat_get_bitmap(nodes_addr(bm), nmask, nr_bits);
64 + if (compat_get_bitmap(nodes_addr(bm), nmask, nr_bits))
65 + return -EFAULT;
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))
69 + return -EFAULT;
70 }
71
72 - if (err)
73 - return -EFAULT;
74 -
75 return sys_mbind(start, len, mode, nm, nr_bits+1, flags);
76 }
77