Skip to content

Commit b73d08c

Browse files
sallsgregkh
authored andcommitted
mm/mempolicy.c: fix error handling in set_mempolicy and mbind.
commit cf01fb9985e8deb25ccf0ea54d916b8871ae0e62 upstream. 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 <salls@cs.ucsb.edu> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2d1af1b commit b73d08c

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

mm/mempolicy.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,6 @@ COMPAT_SYSCALL_DEFINE5(get_mempolicy, int __user *, policy,
14921492
COMPAT_SYSCALL_DEFINE3(set_mempolicy, int, mode, compat_ulong_t __user *, nmask,
14931493
compat_ulong_t, maxnode)
14941494
{
1495-
long err = 0;
14961495
unsigned long __user *nm = NULL;
14971496
unsigned long nr_bits, alloc_size;
14981497
DECLARE_BITMAP(bm, MAX_NUMNODES);
@@ -1501,22 +1500,20 @@ COMPAT_SYSCALL_DEFINE3(set_mempolicy, int, mode, compat_ulong_t __user *, nmask,
15011500
alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
15021501

15031502
if (nmask) {
1504-
err = compat_get_bitmap(bm, nmask, nr_bits);
1503+
if (compat_get_bitmap(bm, nmask, nr_bits))
1504+
return -EFAULT;
15051505
nm = compat_alloc_user_space(alloc_size);
1506-
err |= copy_to_user(nm, bm, alloc_size);
1506+
if (copy_to_user(nm, bm, alloc_size))
1507+
return -EFAULT;
15071508
}
15081509

1509-
if (err)
1510-
return -EFAULT;
1511-
15121510
return sys_set_mempolicy(mode, nm, nr_bits+1);
15131511
}
15141512

15151513
COMPAT_SYSCALL_DEFINE6(mbind, compat_ulong_t, start, compat_ulong_t, len,
15161514
compat_ulong_t, mode, compat_ulong_t __user *, nmask,
15171515
compat_ulong_t, maxnode, compat_ulong_t, flags)
15181516
{
1519-
long err = 0;
15201517
unsigned long __user *nm = NULL;
15211518
unsigned long nr_bits, alloc_size;
15221519
nodemask_t bm;
@@ -1525,14 +1522,13 @@ COMPAT_SYSCALL_DEFINE6(mbind, compat_ulong_t, start, compat_ulong_t, len,
15251522
alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
15261523

15271524
if (nmask) {
1528-
err = compat_get_bitmap(nodes_addr(bm), nmask, nr_bits);
1525+
if (compat_get_bitmap(nodes_addr(bm), nmask, nr_bits))
1526+
return -EFAULT;
15291527
nm = compat_alloc_user_space(alloc_size);
1530-
err |= copy_to_user(nm, nodes_addr(bm), alloc_size);
1528+
if (copy_to_user(nm, nodes_addr(bm), alloc_size))
1529+
return -EFAULT;
15311530
}
15321531

1533-
if (err)
1534-
return -EFAULT;
1535-
15361532
return sys_mbind(start, len, mode, nm, nr_bits+1, flags);
15371533
}
15381534

0 commit comments

Comments
 (0)