Skip to content

Commit cf01fb9

Browse files
sallstorvalds
authored andcommitted
mm/mempolicy.c: fix error handling in set_mempolicy and mbind.
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>
1 parent 425fffd commit cf01fb9

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

Diff for: mm/mempolicy.c

+8-12
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,6 @@ COMPAT_SYSCALL_DEFINE5(get_mempolicy, int __user *, policy,
15291529
COMPAT_SYSCALL_DEFINE3(set_mempolicy, int, mode, compat_ulong_t __user *, nmask,
15301530
compat_ulong_t, maxnode)
15311531
{
1532-
long err = 0;
15331532
unsigned long __user *nm = NULL;
15341533
unsigned long nr_bits, alloc_size;
15351534
DECLARE_BITMAP(bm, MAX_NUMNODES);
@@ -1538,22 +1537,20 @@ COMPAT_SYSCALL_DEFINE3(set_mempolicy, int, mode, compat_ulong_t __user *, nmask,
15381537
alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
15391538

15401539
if (nmask) {
1541-
err = compat_get_bitmap(bm, nmask, nr_bits);
1540+
if (compat_get_bitmap(bm, nmask, nr_bits))
1541+
return -EFAULT;
15421542
nm = compat_alloc_user_space(alloc_size);
1543-
err |= copy_to_user(nm, bm, alloc_size);
1543+
if (copy_to_user(nm, bm, alloc_size))
1544+
return -EFAULT;
15441545
}
15451546

1546-
if (err)
1547-
return -EFAULT;
1548-
15491547
return sys_set_mempolicy(mode, nm, nr_bits+1);
15501548
}
15511549

15521550
COMPAT_SYSCALL_DEFINE6(mbind, compat_ulong_t, start, compat_ulong_t, len,
15531551
compat_ulong_t, mode, compat_ulong_t __user *, nmask,
15541552
compat_ulong_t, maxnode, compat_ulong_t, flags)
15551553
{
1556-
long err = 0;
15571554
unsigned long __user *nm = NULL;
15581555
unsigned long nr_bits, alloc_size;
15591556
nodemask_t bm;
@@ -1562,14 +1559,13 @@ COMPAT_SYSCALL_DEFINE6(mbind, compat_ulong_t, start, compat_ulong_t, len,
15621559
alloc_size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
15631560

15641561
if (nmask) {
1565-
err = compat_get_bitmap(nodes_addr(bm), nmask, nr_bits);
1562+
if (compat_get_bitmap(nodes_addr(bm), nmask, nr_bits))
1563+
return -EFAULT;
15661564
nm = compat_alloc_user_space(alloc_size);
1567-
err |= copy_to_user(nm, nodes_addr(bm), alloc_size);
1565+
if (copy_to_user(nm, nodes_addr(bm), alloc_size))
1566+
return -EFAULT;
15681567
}
15691568

1570-
if (err)
1571-
return -EFAULT;
1572-
15731569
return sys_mbind(start, len, mode, nm, nr_bits+1, flags);
15741570
}
15751571

0 commit comments

Comments
 (0)