Skip to content

Commit

Permalink
mm/mempolicy.c: fix error handling in set_mempolicy and mbind.
Browse files Browse the repository at this point in the history
In the case that compat_get_bitmap fails we do not want to copy the
bitmap to the user as it will contain uninitialized stack data and leak
sensitive data.

Signed-off-by: Chris Salls <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
salls authored and torvalds committed Apr 8, 2017
1 parent 425fffd commit cf01fb9
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions mm/mempolicy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,6 @@ COMPAT_SYSCALL_DEFINE5(get_mempolicy, int __user *, policy,
COMPAT_SYSCALL_DEFINE3(set_mempolicy, int, mode, compat_ulong_t __user *, nmask,
compat_ulong_t, maxnode)
{
long err = 0;
unsigned long __user *nm = NULL;
unsigned long nr_bits, alloc_size;
DECLARE_BITMAP(bm, MAX_NUMNODES);
Expand All @@ -1538,22 +1537,20 @@ COMPAT_SYSCALL_DEFINE3(set_mempolicy, int, mode, compat_ulong_t __user *, nmask,
alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;

if (nmask) {
err = compat_get_bitmap(bm, nmask, nr_bits);
if (compat_get_bitmap(bm, nmask, nr_bits))
return -EFAULT;
nm = compat_alloc_user_space(alloc_size);
err |= copy_to_user(nm, bm, alloc_size);
if (copy_to_user(nm, bm, alloc_size))
return -EFAULT;
}

if (err)
return -EFAULT;

return sys_set_mempolicy(mode, nm, nr_bits+1);
}

COMPAT_SYSCALL_DEFINE6(mbind, compat_ulong_t, start, compat_ulong_t, len,
compat_ulong_t, mode, compat_ulong_t __user *, nmask,
compat_ulong_t, maxnode, compat_ulong_t, flags)
{
long err = 0;
unsigned long __user *nm = NULL;
unsigned long nr_bits, alloc_size;
nodemask_t bm;
Expand All @@ -1562,14 +1559,13 @@ COMPAT_SYSCALL_DEFINE6(mbind, compat_ulong_t, start, compat_ulong_t, len,
alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;

if (nmask) {
err = compat_get_bitmap(nodes_addr(bm), nmask, nr_bits);
if (compat_get_bitmap(nodes_addr(bm), nmask, nr_bits))
return -EFAULT;
nm = compat_alloc_user_space(alloc_size);
err |= copy_to_user(nm, nodes_addr(bm), alloc_size);
if (copy_to_user(nm, nodes_addr(bm), alloc_size))
return -EFAULT;
}

if (err)
return -EFAULT;

return sys_mbind(start, len, mode, nm, nr_bits+1, flags);
}

Expand Down

0 comments on commit cf01fb9

Please sign in to comment.