Skip to content

Commit 96d4f26

Browse files
committed
Remove 'type' argument from access_ok() function
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]>
1 parent 135143b commit 96d4f26

File tree

221 files changed

+610
-679
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

221 files changed

+610
-679
lines changed

arch/alpha/include/asm/futex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
6868
int ret = 0, cmp;
6969
u32 prev;
7070

71-
if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
71+
if (!access_ok(uaddr, sizeof(u32)))
7272
return -EFAULT;
7373

7474
__asm__ __volatile__ (

arch/alpha/include/asm/uaccess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define __access_ok(addr, size) \
3737
((get_fs().seg & (addr | size | (addr+size))) == 0)
3838

39-
#define access_ok(type, addr, size) \
39+
#define access_ok(addr, size) \
4040
({ \
4141
__chk_user_ptr(addr); \
4242
__access_ok(((unsigned long)(addr)), (size)); \

arch/alpha/kernel/signal.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ SYSCALL_DEFINE3(osf_sigaction, int, sig,
6565

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

7979
if (!ret && oact) {
80-
if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
80+
if (!access_ok(oact, sizeof(*oact)) ||
8181
__put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
8282
__put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
8383
__put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
@@ -207,7 +207,7 @@ do_sigreturn(struct sigcontext __user *sc)
207207
sigset_t set;
208208

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

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

333333
oldsp = rdusp();
334334
frame = get_sigframe(ksig, oldsp, sizeof(*frame));
335-
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
335+
if (!access_ok(frame, sizeof(*frame)))
336336
return -EFAULT;
337337

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

378378
oldsp = rdusp();
379379
frame = get_sigframe(ksig, oldsp, sizeof(*frame));
380-
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
380+
if (!access_ok(frame, sizeof(*frame)))
381381
return -EFAULT;
382382

383383
err |= copy_siginfo_to_user(&frame->info, &ksig->info);

arch/alpha/lib/csum_partial_copy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst, int len,
333333
unsigned long doff = 7 & (unsigned long) dst;
334334

335335
if (len) {
336-
if (!access_ok(VERIFY_READ, src, len)) {
336+
if (!access_ok(src, len)) {
337337
if (errp) *errp = -EFAULT;
338338
memset(dst, 0, len);
339339
return sum;

arch/arc/include/asm/futex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, u32 expval,
126126
int ret = 0;
127127
u32 existval;
128128

129-
if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
129+
if (!access_ok(uaddr, sizeof(u32)))
130130
return -EFAULT;
131131

132132
#ifndef CONFIG_ARC_HAS_LLSC

arch/arc/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ SYSCALL_DEFINE3(arc_usr_cmpxchg, int *, uaddr, int, expected, int, new)
6161
/* Z indicates to userspace if operation succeded */
6262
regs->status32 &= ~STATUS_Z_MASK;
6363

64-
ret = access_ok(VERIFY_WRITE, uaddr, sizeof(*uaddr));
64+
ret = access_ok(uaddr, sizeof(*uaddr));
6565
if (!ret)
6666
goto fail;
6767

arch/arc/kernel/signal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ SYSCALL_DEFINE0(rt_sigreturn)
169169

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

172-
if (!access_ok(VERIFY_READ, sf, sizeof(*sf)))
172+
if (!access_ok(sf, sizeof(*sf)))
173173
goto badframe;
174174

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

221221
/* Check that we can actually write to the signal frame */
222-
if (!access_ok(VERIFY_WRITE, frame, framesize))
222+
if (!access_ok(frame, framesize))
223223
frame = NULL;
224224

225225
return frame;

arch/arm/include/asm/futex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
5050
int ret;
5151
u32 val;
5252

53-
if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
53+
if (!access_ok(uaddr, sizeof(u32)))
5454
return -EFAULT;
5555

5656
smp_mb();
@@ -104,7 +104,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
104104
int ret = 0;
105105
u32 val;
106106

107-
if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
107+
if (!access_ok(uaddr, sizeof(u32)))
108108
return -EFAULT;
109109

110110
preempt_disable();

arch/arm/include/asm/uaccess.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static inline void set_fs(mm_segment_t fs)
279279

280280
#endif /* CONFIG_MMU */
281281

282-
#define access_ok(type, addr, size) (__range_ok(addr, size) == 0)
282+
#define access_ok(addr, size) (__range_ok(addr, size) == 0)
283283

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

561561
static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
562562
{
563-
if (access_ok(VERIFY_WRITE, to, n))
563+
if (access_ok(to, n))
564564
n = __clear_user(to, n);
565565
return n;
566566
}

arch/arm/kernel/perf_callchain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ user_backtrace(struct frame_tail __user *tail,
3737
struct frame_tail buftail;
3838
unsigned long err;
3939

40-
if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
40+
if (!access_ok(tail, sizeof(buftail)))
4141
return NULL;
4242

4343
pagefault_disable();

arch/arm/kernel/signal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ asmlinkage int sys_sigreturn(struct pt_regs *regs)
241241

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

244-
if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
244+
if (!access_ok(frame, sizeof (*frame)))
245245
goto badframe;
246246

247247
if (restore_sigframe(regs, frame))
@@ -271,7 +271,7 @@ asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
271271

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

274-
if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
274+
if (!access_ok(frame, sizeof (*frame)))
275275
goto badframe;
276276

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

361361
return frame;

arch/arm/kernel/swp_emulate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static int swp_handler(struct pt_regs *regs, unsigned int instr)
198198
destreg, EXTRACT_REG_NUM(instr, RT2_OFFSET), data);
199199

200200
/* Check access in reasonable access range for both SWP and SWPB */
201-
if (!access_ok(VERIFY_WRITE, (address & ~3), 4)) {
201+
if (!access_ok((address & ~3), 4)) {
202202
pr_debug("SWP{B} emulation: access to %p not allowed!\n",
203203
(void *)address);
204204
res = -EFAULT;

arch/arm/kernel/sys_oabi-compat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ asmlinkage long sys_oabi_epoll_wait(int epfd,
285285
maxevents > (INT_MAX/sizeof(*kbuf)) ||
286286
maxevents > (INT_MAX/sizeof(*events)))
287287
return -EINVAL;
288-
if (!access_ok(VERIFY_WRITE, events, sizeof(*events) * maxevents))
288+
if (!access_ok(events, sizeof(*events) * maxevents))
289289
return -EFAULT;
290290
kbuf = kmalloc_array(maxevents, sizeof(*kbuf), GFP_KERNEL);
291291
if (!kbuf)
@@ -326,7 +326,7 @@ asmlinkage long sys_oabi_semtimedop(int semid,
326326

327327
if (nsops < 1 || nsops > SEMOPM)
328328
return -EINVAL;
329-
if (!access_ok(VERIFY_READ, tsops, sizeof(*tsops) * nsops))
329+
if (!access_ok(tsops, sizeof(*tsops) * nsops))
330330
return -EFAULT;
331331
sops = kmalloc_array(nsops, sizeof(*sops), GFP_KERNEL);
332332
if (!sops)

arch/arm/kernel/traps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ do_cache_op(unsigned long start, unsigned long end, int flags)
582582
if (end < start || flags)
583583
return -EINVAL;
584584

585-
if (!access_ok(VERIFY_READ, start, end - start))
585+
if (!access_ok(start, end - start))
586586
return -EFAULT;
587587

588588
return __do_cache_op(start, end);

arch/arm/oprofile/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static struct frame_tail* user_backtrace(struct frame_tail *tail)
8888
struct frame_tail buftail[2];
8989

9090
/* Also check accessibility of one struct frame_tail beyond */
91-
if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
91+
if (!access_ok(tail, sizeof(buftail)))
9292
return NULL;
9393
if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail)))
9494
return NULL;

arch/arm64/include/asm/futex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *_uaddr,
9696
u32 val, tmp;
9797
u32 __user *uaddr;
9898

99-
if (!access_ok(VERIFY_WRITE, _uaddr, sizeof(u32)))
99+
if (!access_ok(_uaddr, sizeof(u32)))
100100
return -EFAULT;
101101

102102
uaddr = __uaccess_mask_ptr(_uaddr);

arch/arm64/include/asm/uaccess.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long si
9595
return ret;
9696
}
9797

98-
#define access_ok(type, addr, size) __range_ok(addr, size)
98+
#define access_ok(addr, size) __range_ok(addr, size)
9999
#define user_addr_max get_fs
100100

101101
#define _ASM_EXTABLE(from, to) \
@@ -301,7 +301,7 @@ do { \
301301
({ \
302302
__typeof__(*(ptr)) __user *__p = (ptr); \
303303
might_fault(); \
304-
if (access_ok(VERIFY_READ, __p, sizeof(*__p))) { \
304+
if (access_ok(__p, sizeof(*__p))) { \
305305
__p = uaccess_mask_ptr(__p); \
306306
__get_user_err((x), __p, (err)); \
307307
} else { \
@@ -370,7 +370,7 @@ do { \
370370
({ \
371371
__typeof__(*(ptr)) __user *__p = (ptr); \
372372
might_fault(); \
373-
if (access_ok(VERIFY_WRITE, __p, sizeof(*__p))) { \
373+
if (access_ok(__p, sizeof(*__p))) { \
374374
__p = uaccess_mask_ptr(__p); \
375375
__put_user_err((x), __p, (err)); \
376376
} else { \
@@ -418,7 +418,7 @@ extern unsigned long __must_check __arch_copy_in_user(void __user *to, const voi
418418
extern unsigned long __must_check __arch_clear_user(void __user *to, unsigned long n);
419419
static inline unsigned long __must_check __clear_user(void __user *to, unsigned long n)
420420
{
421-
if (access_ok(VERIFY_WRITE, to, n))
421+
if (access_ok(to, n))
422422
n = __arch_clear_user(__uaccess_mask_ptr(to), n);
423423
return n;
424424
}

arch/arm64/kernel/armv8_deprecated.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static int swp_handler(struct pt_regs *regs, u32 instr)
402402

403403
/* Check access in reasonable access range for both SWP and SWPB */
404404
user_ptr = (const void __user *)(unsigned long)(address & ~3);
405-
if (!access_ok(VERIFY_WRITE, user_ptr, 4)) {
405+
if (!access_ok(user_ptr, 4)) {
406406
pr_debug("SWP{B} emulation: access to 0x%08x not allowed!\n",
407407
address);
408408
goto fault;

arch/arm64/kernel/perf_callchain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ user_backtrace(struct frame_tail __user *tail,
3939
unsigned long lr;
4040

4141
/* Also check accessibility of one struct frame_tail beyond */
42-
if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
42+
if (!access_ok(tail, sizeof(buftail)))
4343
return NULL;
4444

4545
pagefault_disable();
@@ -86,7 +86,7 @@ compat_user_backtrace(struct compat_frame_tail __user *tail,
8686
unsigned long err;
8787

8888
/* Also check accessibility of one struct frame_tail beyond */
89-
if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
89+
if (!access_ok(tail, sizeof(buftail)))
9090
return NULL;
9191

9292
pagefault_disable();

arch/arm64/kernel/signal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ static int parse_user_sigframe(struct user_ctxs *user,
470470
offset = 0;
471471
limit = extra_size;
472472

473-
if (!access_ok(VERIFY_READ, base, limit))
473+
if (!access_ok(base, limit))
474474
goto invalid;
475475

476476
continue;
@@ -556,7 +556,7 @@ SYSCALL_DEFINE0(rt_sigreturn)
556556

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

559-
if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
559+
if (!access_ok(frame, sizeof (*frame)))
560560
goto badframe;
561561

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

736736
return 0;

arch/arm64/kernel/signal32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ COMPAT_SYSCALL_DEFINE0(sigreturn)
303303

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

306-
if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
306+
if (!access_ok(frame, sizeof (*frame)))
307307
goto badframe;
308308

309309
if (compat_restore_sigframe(regs, frame))
@@ -334,7 +334,7 @@ COMPAT_SYSCALL_DEFINE0(rt_sigreturn)
334334

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

337-
if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
337+
if (!access_ok(frame, sizeof (*frame)))
338338
goto badframe;
339339

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

371371
return frame;

arch/arm64/kernel/sys_compat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ do_compat_cache_op(unsigned long start, unsigned long end, int flags)
5858
if (end < start || flags)
5959
return -EINVAL;
6060

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

6464
return __do_compat_cache_op(start, end);

arch/c6x/kernel/signal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ asmlinkage int do_rt_sigreturn(struct pt_regs *regs)
8080

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

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

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

152-
if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
152+
if (!access_ok(frame, sizeof(*frame)))
153153
return -EFAULT;
154154

155155
err |= __put_user(&frame->info, &frame->pinfo);

0 commit comments

Comments
 (0)