Skip to content

Commit

Permalink
Remove 'type' argument from access_ok() function
Browse files Browse the repository at this point in the history
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.

It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access.  But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.

A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model.  And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.

This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.

There were a couple of notable cases:

 - csky still had the old "verify_area()" name as an alias.

 - the iter_iov code had magical hardcoded knowledge of the actual
   values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
   really used it)

 - microblaze used the type argument for a debug printout

but other than those oddities this should be a total no-op patch.

I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something.  Any missed conversion should be trivially fixable, though.

Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
torvalds committed Jan 4, 2019
1 parent 135143b commit 96d4f26
Show file tree
Hide file tree
Showing 221 changed files with 610 additions and 679 deletions.
2 changes: 1 addition & 1 deletion arch/alpha/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
int ret = 0, cmp;
u32 prev;

if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

__asm__ __volatile__ (
Expand Down
2 changes: 1 addition & 1 deletion arch/alpha/include/asm/uaccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define __access_ok(addr, size) \
((get_fs().seg & (addr | size | (addr+size))) == 0)

#define access_ok(type, addr, size) \
#define access_ok(addr, size) \
({ \
__chk_user_ptr(addr); \
__access_ok(((unsigned long)(addr)), (size)); \
Expand Down
12 changes: 6 additions & 6 deletions arch/alpha/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ SYSCALL_DEFINE3(osf_sigaction, int, sig,

if (act) {
old_sigset_t mask;
if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
if (!access_ok(act, sizeof(*act)) ||
__get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
__get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
__get_user(mask, &act->sa_mask))
Expand All @@ -77,7 +77,7 @@ SYSCALL_DEFINE3(osf_sigaction, int, sig,
ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);

if (!ret && oact) {
if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
if (!access_ok(oact, sizeof(*oact)) ||
__put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
__put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
__put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
Expand Down Expand Up @@ -207,7 +207,7 @@ do_sigreturn(struct sigcontext __user *sc)
sigset_t set;

/* Verify that it's a good sigcontext before using it */
if (!access_ok(VERIFY_READ, sc, sizeof(*sc)))
if (!access_ok(sc, sizeof(*sc)))
goto give_sigsegv;
if (__get_user(set.sig[0], &sc->sc_mask))
goto give_sigsegv;
Expand Down Expand Up @@ -235,7 +235,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame)
sigset_t set;

/* Verify that it's a good ucontext_t before using it */
if (!access_ok(VERIFY_READ, &frame->uc, sizeof(frame->uc)))
if (!access_ok(&frame->uc, sizeof(frame->uc)))
goto give_sigsegv;
if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
goto give_sigsegv;
Expand Down Expand Up @@ -332,7 +332,7 @@ setup_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)

oldsp = rdusp();
frame = get_sigframe(ksig, oldsp, sizeof(*frame));
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
if (!access_ok(frame, sizeof(*frame)))
return -EFAULT;

err |= setup_sigcontext(&frame->sc, regs, set->sig[0], oldsp);
Expand Down Expand Up @@ -377,7 +377,7 @@ setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)

oldsp = rdusp();
frame = get_sigframe(ksig, oldsp, sizeof(*frame));
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
if (!access_ok(frame, sizeof(*frame)))
return -EFAULT;

err |= copy_siginfo_to_user(&frame->info, &ksig->info);
Expand Down
2 changes: 1 addition & 1 deletion arch/alpha/lib/csum_partial_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst, int len,
unsigned long doff = 7 & (unsigned long) dst;

if (len) {
if (!access_ok(VERIFY_READ, src, len)) {
if (!access_ok(src, len)) {
if (errp) *errp = -EFAULT;
memset(dst, 0, len);
return sum;
Expand Down
2 changes: 1 addition & 1 deletion arch/arc/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, u32 expval,
int ret = 0;
u32 existval;

if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

#ifndef CONFIG_ARC_HAS_LLSC
Expand Down
2 changes: 1 addition & 1 deletion arch/arc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
/* Z indicates to userspace if operation succeded */
regs->status32 &= ~STATUS_Z_MASK;

ret = access_ok(VERIFY_WRITE, uaddr, sizeof(*uaddr));
ret = access_ok(uaddr, sizeof(*uaddr));
if (!ret)
goto fail;

Expand Down
4 changes: 2 additions & 2 deletions arch/arc/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ SYSCALL_DEFINE0(rt_sigreturn)

sf = (struct rt_sigframe __force __user *)(regs->sp);

if (!access_ok(VERIFY_READ, sf, sizeof(*sf)))
if (!access_ok(sf, sizeof(*sf)))
goto badframe;

if (__get_user(magic, &sf->sigret_magic))
Expand Down Expand Up @@ -219,7 +219,7 @@ static inline void __user *get_sigframe(struct ksignal *ksig,
frame = (void __user *)((sp - framesize) & ~7);

/* Check that we can actually write to the signal frame */
if (!access_ok(VERIFY_WRITE, frame, framesize))
if (!access_ok(frame, framesize))
frame = NULL;

return frame;
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
int ret;
u32 val;

if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

smp_mb();
Expand Down Expand Up @@ -104,7 +104,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
int ret = 0;
u32 val;

if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
if (!access_ok(uaddr, sizeof(u32)))
return -EFAULT;

preempt_disable();
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/include/asm/uaccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static inline void set_fs(mm_segment_t fs)

#endif /* CONFIG_MMU */

#define access_ok(type, addr, size) (__range_ok(addr, size) == 0)
#define access_ok(addr, size) (__range_ok(addr, size) == 0)

#define user_addr_max() \
(uaccess_kernel() ? ~0UL : get_fs())
Expand Down Expand Up @@ -560,7 +560,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)

static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
{
if (access_ok(VERIFY_WRITE, to, n))
if (access_ok(to, n))
n = __clear_user(to, n);
return n;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/kernel/perf_callchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ user_backtrace(struct frame_tail __user *tail,
struct frame_tail buftail;
unsigned long err;

if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
if (!access_ok(tail, sizeof(buftail)))
return NULL;

pagefault_disable();
Expand Down
6 changes: 3 additions & 3 deletions arch/arm/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ asmlinkage int sys_sigreturn(struct pt_regs *regs)

frame = (struct sigframe __user *)regs->ARM_sp;

if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
if (!access_ok(frame, sizeof (*frame)))
goto badframe;

if (restore_sigframe(regs, frame))
Expand Down Expand Up @@ -271,7 +271,7 @@ asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)

frame = (struct rt_sigframe __user *)regs->ARM_sp;

if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
if (!access_ok(frame, sizeof (*frame)))
goto badframe;

if (restore_sigframe(regs, &frame->sig))
Expand Down Expand Up @@ -355,7 +355,7 @@ get_sigframe(struct ksignal *ksig, struct pt_regs *regs, int framesize)
/*
* Check that we can actually write to the signal frame.
*/
if (!access_ok(VERIFY_WRITE, frame, framesize))
if (!access_ok(frame, framesize))
frame = NULL;

return frame;
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/kernel/swp_emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static int swp_handler(struct pt_regs *regs, unsigned int instr)
destreg, EXTRACT_REG_NUM(instr, RT2_OFFSET), data);

/* Check access in reasonable access range for both SWP and SWPB */
if (!access_ok(VERIFY_WRITE, (address & ~3), 4)) {
if (!access_ok((address & ~3), 4)) {
pr_debug("SWP{B} emulation: access to %p not allowed!\n",
(void *)address);
res = -EFAULT;
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/kernel/sys_oabi-compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ asmlinkage long sys_oabi_epoll_wait(int epfd,
maxevents > (INT_MAX/sizeof(*kbuf)) ||
maxevents > (INT_MAX/sizeof(*events)))
return -EINVAL;
if (!access_ok(VERIFY_WRITE, events, sizeof(*events) * maxevents))
if (!access_ok(events, sizeof(*events) * maxevents))
return -EFAULT;
kbuf = kmalloc_array(maxevents, sizeof(*kbuf), GFP_KERNEL);
if (!kbuf)
Expand Down Expand Up @@ -326,7 +326,7 @@ asmlinkage long sys_oabi_semtimedop(int semid,

if (nsops < 1 || nsops > SEMOPM)
return -EINVAL;
if (!access_ok(VERIFY_READ, tsops, sizeof(*tsops) * nsops))
if (!access_ok(tsops, sizeof(*tsops) * nsops))
return -EFAULT;
sops = kmalloc_array(nsops, sizeof(*sops), GFP_KERNEL);
if (!sops)
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ do_cache_op(unsigned long start, unsigned long end, int flags)
if (end < start || flags)
return -EINVAL;

if (!access_ok(VERIFY_READ, start, end - start))
if (!access_ok(start, end - start))
return -EFAULT;

return __do_cache_op(start, end);
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/oprofile/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static struct frame_tail* user_backtrace(struct frame_tail *tail)
struct frame_tail buftail[2];

/* Also check accessibility of one struct frame_tail beyond */
if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
if (!access_ok(tail, sizeof(buftail)))
return NULL;
if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail)))
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/include/asm/futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *_uaddr,
u32 val, tmp;
u32 __user *uaddr;

if (!access_ok(VERIFY_WRITE, _uaddr, sizeof(u32)))
if (!access_ok(_uaddr, sizeof(u32)))
return -EFAULT;

uaddr = __uaccess_mask_ptr(_uaddr);
Expand Down
8 changes: 4 additions & 4 deletions arch/arm64/include/asm/uaccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si
return ret;
}

#define access_ok(type, addr, size) __range_ok(addr, size)
#define access_ok(addr, size) __range_ok(addr, size)
#define user_addr_max get_fs

#define _ASM_EXTABLE(from, to) \
Expand Down Expand Up @@ -301,7 +301,7 @@ do { \
({ \
__typeof__(*(ptr)) __user *__p = (ptr); \
might_fault(); \
if (access_ok(VERIFY_READ, __p, sizeof(*__p))) { \
if (access_ok(__p, sizeof(*__p))) { \
__p = uaccess_mask_ptr(__p); \
__get_user_err((x), __p, (err)); \
} else { \
Expand Down Expand Up @@ -370,7 +370,7 @@ do { \
({ \
__typeof__(*(ptr)) __user *__p = (ptr); \
might_fault(); \
if (access_ok(VERIFY_WRITE, __p, sizeof(*__p))) { \
if (access_ok(__p, sizeof(*__p))) { \
__p = uaccess_mask_ptr(__p); \
__put_user_err((x), __p, (err)); \
} else { \
Expand Down Expand Up @@ -418,7 +418,7 @@ extern unsigned long __must_check __arch_copy_in_user(void __user *to, const voi
extern unsigned long __must_check __arch_clear_user(void __user *to, unsigned long n);
static inline unsigned long __must_check __clear_user(void __user *to, unsigned long n)
{
if (access_ok(VERIFY_WRITE, to, n))
if (access_ok(to, n))
n = __arch_clear_user(__uaccess_mask_ptr(to), n);
return n;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/kernel/armv8_deprecated.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ static int swp_handler(struct pt_regs *regs, u32 instr)

/* Check access in reasonable access range for both SWP and SWPB */
user_ptr = (const void __user *)(unsigned long)(address & ~3);
if (!access_ok(VERIFY_WRITE, user_ptr, 4)) {
if (!access_ok(user_ptr, 4)) {
pr_debug("SWP{B} emulation: access to 0x%08x not allowed!\n",
address);
goto fault;
Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/kernel/perf_callchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ user_backtrace(struct frame_tail __user *tail,
unsigned long lr;

/* Also check accessibility of one struct frame_tail beyond */
if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
if (!access_ok(tail, sizeof(buftail)))
return NULL;

pagefault_disable();
Expand Down Expand Up @@ -86,7 +86,7 @@ compat_user_backtrace(struct compat_frame_tail __user *tail,
unsigned long err;

/* Also check accessibility of one struct frame_tail beyond */
if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
if (!access_ok(tail, sizeof(buftail)))
return NULL;

pagefault_disable();
Expand Down
6 changes: 3 additions & 3 deletions arch/arm64/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ static int parse_user_sigframe(struct user_ctxs *user,
offset = 0;
limit = extra_size;

if (!access_ok(VERIFY_READ, base, limit))
if (!access_ok(base, limit))
goto invalid;

continue;
Expand Down Expand Up @@ -556,7 +556,7 @@ SYSCALL_DEFINE0(rt_sigreturn)

frame = (struct rt_sigframe __user *)regs->sp;

if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
if (!access_ok(frame, sizeof (*frame)))
goto badframe;

if (restore_sigframe(regs, frame))
Expand Down Expand Up @@ -730,7 +730,7 @@ static int get_sigframe(struct rt_sigframe_user_layout *user,
/*
* Check that we can actually write to the signal frame.
*/
if (!access_ok(VERIFY_WRITE, user->sigframe, sp_top - sp))
if (!access_ok(user->sigframe, sp_top - sp))
return -EFAULT;

return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/arm64/kernel/signal32.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ COMPAT_SYSCALL_DEFINE0(sigreturn)

frame = (struct compat_sigframe __user *)regs->compat_sp;

if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
if (!access_ok(frame, sizeof (*frame)))
goto badframe;

if (compat_restore_sigframe(regs, frame))
Expand Down Expand Up @@ -334,7 +334,7 @@ COMPAT_SYSCALL_DEFINE0(rt_sigreturn)

frame = (struct compat_rt_sigframe __user *)regs->compat_sp;

if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
if (!access_ok(frame, sizeof (*frame)))
goto badframe;

if (compat_restore_sigframe(regs, &frame->sig))
Expand Down Expand Up @@ -365,7 +365,7 @@ static void __user *compat_get_sigframe(struct ksignal *ksig,
/*
* Check that we can actually write to the signal frame.
*/
if (!access_ok(VERIFY_WRITE, frame, framesize))
if (!access_ok(frame, framesize))
frame = NULL;

return frame;
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/kernel/sys_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ do_compat_cache_op(unsigned long start, unsigned long end, int flags)
if (end < start || flags)
return -EINVAL;

if (!access_ok(VERIFY_READ, (const void __user *)start, end - start))
if (!access_ok((const void __user *)start, end - start))
return -EFAULT;

return __do_compat_cache_op(start, end);
Expand Down
4 changes: 2 additions & 2 deletions arch/c6x/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ asmlinkage int do_rt_sigreturn(struct pt_regs *regs)

frame = (struct rt_sigframe __user *) ((unsigned long) regs->sp + 8);

if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
if (!access_ok(frame, sizeof(*frame)))
goto badframe;
if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
goto badframe;
Expand Down Expand Up @@ -149,7 +149,7 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,

frame = get_sigframe(ksig, regs, sizeof(*frame));

if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
if (!access_ok(frame, sizeof(*frame)))
return -EFAULT;

err |= __put_user(&frame->info, &frame->pinfo);
Expand Down
Loading

0 comments on commit 96d4f26

Please sign in to comment.