History

make 'user_access_begin()' do 'access_ok()'

Originally, the rule used to be that you'd have to do access_ok() separately, and then user_access_begin() before actually doing the direct (optimized) user access. But experience has shown that people then decide not to do access_ok() at all, and instead rely on it being implied by other operations or similar. Which makes it very hard to verify that the access has actually been range-checked. If you use the unsafe direct user accesses, hardware features (either SMAP - Supervisor Mode Access Protection - on x86, or PAN - Privileged Access Never - on ARM) do force you to use user_access_begin(). But nothing really forces the range check. By putting the range check into user_access_begin(), we actually force people to do the right thing (tm), and the range check vill be visible near the actual accesses. We have way too long a history of people trying to avoid them.

Linus Torvalds committed 7 years ago

Commit 594cc251 parent 0b2c8f87 files · +36 −20Browse files

Showing the changes to kernel (2 of 7 files). Show all

Unified · Split

2 files
  1. kernel/compat.c +2 −4
  2. kernel/exit.c +2 −4
kernel/compat.c+2−4
@@ -354,10 +354,9 @@ long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask, · 353 unmodified lines
354354 bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
355355 nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size);
356356
357− if (!access_ok(umask, bitmap_size / 8))
357+ if (!user_access_begin(umask, bitmap_size / 8))
358358 return -EFAULT;
359359
360− user_access_begin();
361360 while (nr_compat_longs > 1) {
362361 compat_ulong_t l1, l2;
363362 unsafe_get_user(l1, umask++, Efault);
@@ -384,10 +383,9 @@ long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask, · 20 unmodified lines
384383 bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
385384 nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size);
386385
387− if (!access_ok(umask, bitmap_size / 8))
386+ if (!user_access_begin(umask, bitmap_size / 8))
388387 return -EFAULT;
389388
390− user_access_begin();
391389 while (nr_compat_longs > 1) {
392390 unsigned long m = *mask++;
393391 unsafe_put_user((compat_ulong_t)m, umask++, Efault);
kernel/exit.c+2−4
@@ -1604,10 +1604,9 @@ SYSCALL_DEFINE5(waitid, int, which, pid_t, upid, struct siginfo __user *, · 1603 unmodified lines
16041604 if (!infop)
16051605 return err;
16061606
1607− if (!access_ok(infop, sizeof(*infop)))
1607+ if (!user_access_begin(infop, sizeof(*infop)))
16081608 return -EFAULT;
16091609
1610− user_access_begin();
16111610 unsafe_put_user(signo, &infop->si_signo, Efault);
16121611 unsafe_put_user(0, &infop->si_errno, Efault);
16131612 unsafe_put_user(info.cause, &infop->si_code, Efault);
@@ -1732,10 +1731,9 @@ COMPAT_SYSCALL_DEFINE5(waitid, · 118 unmodified lines
17321731 if (!infop)
17331732 return err;
17341733
1735− if (!access_ok(infop, sizeof(*infop)))
1734+ if (!user_access_begin(infop, sizeof(*infop)))
17361735 return -EFAULT;
17371736
1738− user_access_begin();
17391737 unsafe_put_user(signo, &infop->si_signo, Efault);
17401738 unsafe_put_user(0, &infop->si_errno, Efault);
17411739 unsafe_put_user(info.cause, &infop->si_code, Efault);