Skip to content

Commit e08f457

Browse files
pmundtPaul Mundt
authored andcommitted
sh: __user annotations for __get/__put_user().
This adds in some more __user annotations. These weren't being handled properly in some of the __get_user and __put_user paths, so tidy those up. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 7a302a9 commit e08f457

8 files changed

Lines changed: 49 additions & 34 deletions

File tree

‎arch/sh/kernel/process.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/kexec.h>
1818
#include <linux/kdebug.h>
1919
#include <linux/tick.h>
20+
#include <linux/reboot.h>
2021
#include <asm/uaccess.h>
2122
#include <asm/mmu_context.h>
2223
#include <asm/pgalloc.h>
@@ -449,23 +450,20 @@ asmlinkage int sys_vfork(unsigned long r4, unsigned long r5,
449450
/*
450451
* sys_execve() executes a new program.
451452
*/
452-
asmlinkage int sys_execve(char *ufilename, char **uargv,
453-
char **uenvp, unsigned long r7,
453+
asmlinkage int sys_execve(char __user *ufilename, char __user * __user *uargv,
454+
char __user * __user *uenvp, unsigned long r7,
454455
struct pt_regs __regs)
455456
{
456457
struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
457458
int error;
458459
char *filename;
459460

460-
filename = getname((char __user *)ufilename);
461+
filename = getname(ufilename);
461462
error = PTR_ERR(filename);
462463
if (IS_ERR(filename))
463464
goto out;
464465

465-
error = do_execve(filename,
466-
(char __user * __user *)uargv,
467-
(char __user * __user *)uenvp,
468-
regs);
466+
error = do_execve(filename, uargv, uenvp, regs);
469467
if (error == 0) {
470468
task_lock(current);
471469
current->ptrace &= ~PT_DTRACE;

‎arch/sh/kernel/ptrace.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
9999
ret = -EIO;
100100
if (copied != sizeof(tmp))
101101
break;
102-
ret = put_user(tmp,(unsigned long *) data);
102+
ret = put_user(tmp,(unsigned long __user *) data);
103103
break;
104104
}
105105

@@ -128,7 +128,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
128128
tmp = !!tsk_used_math(child);
129129
else
130130
tmp = 0;
131-
ret = put_user(tmp, (unsigned long *)data);
131+
ret = put_user(tmp, (unsigned long __user *)data);
132132
break;
133133
}
134134

@@ -196,7 +196,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
196196

197197
case PTRACE_SINGLESTEP: { /* set the trap flag. */
198198
long pc;
199-
struct pt_regs *dummy = NULL;
199+
struct pt_regs *regs = NULL;
200200

201201
ret = -EIO;
202202
if (!valid_signal(data))
@@ -207,7 +207,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
207207
child->ptrace |= PT_DTRACE;
208208
}
209209

210-
pc = get_stack_long(child, (long)&dummy->pc);
210+
pc = get_stack_long(child, (long)&regs->pc);
211211

212212
/* Next scheduling will set up UBC */
213213
if (child->thread.ubc_pc == 0)

‎arch/sh/kernel/signal.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ asmlinkage int sys_rt_sigreturn(unsigned long r4, unsigned long r5,
261261
goto badframe;
262262
/* It is more difficult to avoid calling this function than to
263263
call it and ignore errors. */
264-
do_sigaltstack(&st, NULL, regs->regs[15]);
264+
do_sigaltstack((const stack_t __user *)&st, NULL, (unsigned long)frame);
265265

266266
return r0;
267267

268268
badframe:
269269
force_sig(SIGSEGV, current);
270270
return 0;
271-
}
271+
}
272272

273273
/*
274274
* Set up a signal frame.

‎arch/sh/kernel/traps.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ asmlinkage void do_address_error(struct pt_regs *regs,
581581
info.si_signo = SIGBUS;
582582
info.si_errno = 0;
583583
info.si_code = si_code;
584-
info.si_addr = (void *) address;
584+
info.si_addr = (void __user *)address;
585585
force_sig_info(SIGBUS, &info, current);
586586
} else {
587587
if (regs->pc & 1)

‎include/asm-sh/page.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern void (*copy_page)(void *to, void *from);
6060

6161
extern unsigned long shm_align_mask;
6262
extern unsigned long max_low_pfn, min_low_pfn;
63+
extern unsigned long memory_start, memory_end;
6364

6465
#ifdef CONFIG_MMU
6566
extern void clear_page_slow(void *to);

‎include/asm-sh/sections.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33

44
#include <asm-generic/sections.h>
55

6-
extern char _end[];
7-
86
#endif /* __ASM_SH_SECTIONS_H */
97

‎include/asm-sh/system.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
#include <linux/irqflags.h>
1010
#include <linux/compiler.h>
11+
#include <linux/linkage.h>
1112
#include <asm/types.h>
1213
#include <asm/ptrace.h>
1314

15+
struct task_struct *__switch_to(struct task_struct *prev,
16+
struct task_struct *next);
17+
1418
/*
1519
* switch_to() should switch tasks to task nr n, first
1620
*/
@@ -271,6 +275,16 @@ extern unsigned int instruction_size(unsigned int insn);
271275
void disable_hlt(void);
272276
void enable_hlt(void);
273277

278+
void default_idle(void);
279+
280+
asmlinkage void break_point_trap(void);
281+
asmlinkage void debug_trap_handler(unsigned long r4, unsigned long r5,
282+
unsigned long r6, unsigned long r7,
283+
struct pt_regs __regs);
284+
asmlinkage void bug_trap_handler(unsigned long r4, unsigned long r5,
285+
unsigned long r6, unsigned long r7,
286+
struct pt_regs __regs);
287+
274288
#define arch_align_stack(x) (x)
275289

276290
#endif

‎include/asm-sh/uaccess.h‎

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ static inline void set_fs(mm_segment_t s)
6161
*/
6262
static inline int __access_ok(unsigned long addr, unsigned long size)
6363
{
64-
extern unsigned long memory_start, memory_end;
65-
6664
return ((addr >= memory_start) && ((addr + size) < memory_end));
6765
}
6866
#else /* CONFIG_MMU */
@@ -76,7 +74,7 @@ static inline int __access_ok(unsigned long addr, unsigned long size)
7674
* __access_ok: Check if address with size is OK or not.
7775
*
7876
* We do three checks:
79-
* (1) is it user space?
77+
* (1) is it user space?
8078
* (2) addr + size --> carry?
8179
* (3) addr + size >= 0x80000000 (PAGE_OFFSET)
8280
*
@@ -142,11 +140,12 @@ static inline int access_ok(int type, const void __user *p, unsigned long size)
142140
__get_user_nocheck((x),(ptr),sizeof(*(ptr)))
143141

144142
struct __large_struct { unsigned long buf[100]; };
145-
#define __m(x) (*(struct __large_struct *)(x))
143+
#define __m(x) (*(struct __large_struct __user *)(x))
146144

147145
#define __get_user_size(x,ptr,size,retval) \
148146
do { \
149147
retval = 0; \
148+
__chk_user_ptr(ptr); \
150149
switch (size) { \
151150
case 1: \
152151
__get_user_asm(x, ptr, retval, "b"); \
@@ -175,6 +174,7 @@ do { \
175174
#define __get_user_check(x,ptr,size) \
176175
({ \
177176
long __gu_err, __gu_val; \
177+
__chk_user_ptr(ptr); \
178178
switch (size) { \
179179
case 1: \
180180
__get_user_1(__gu_val, (ptr), __gu_err); \
@@ -300,6 +300,7 @@ extern void __get_user_unknown(void);
300300
#define __put_user_size(x,ptr,size,retval) \
301301
do { \
302302
retval = 0; \
303+
__chk_user_ptr(ptr); \
303304
switch (size) { \
304305
case 1: \
305306
__put_user_asm(x, ptr, retval, "b"); \
@@ -328,7 +329,7 @@ do { \
328329
#define __put_user_check(x,ptr,size) \
329330
({ \
330331
long __pu_err = -EFAULT; \
331-
__typeof__(*(ptr)) *__pu_addr = (ptr); \
332+
__typeof__(*(ptr)) __user *__pu_addr = (ptr); \
332333
\
333334
if (__access_ok((unsigned long)__pu_addr,size)) \
334335
__put_user_size((x),__pu_addr,(size),__pu_err); \
@@ -406,10 +407,10 @@ __asm__ __volatile__( \
406407
#endif
407408

408409
extern void __put_user_unknown(void);
409-
410+
410411
/* Generic arbitrary sized copy. */
411412
/* Return the number of bytes NOT copied */
412-
extern __kernel_size_t __copy_user(void *to, const void *from, __kernel_size_t n);
413+
__kernel_size_t __copy_user(void *to, const void *from, __kernel_size_t n);
413414

414415
#define copy_to_user(to,from,n) ({ \
415416
void *__copy_to = (void *) (to); \
@@ -420,14 +421,6 @@ __copy_res = __copy_user(__copy_to, (void *) (from), __copy_size); \
420421
} else __copy_res = __copy_size; \
421422
__copy_res; })
422423

423-
#define __copy_to_user(to,from,n) \
424-
__copy_user((void *)(to), \
425-
(void *)(from), n)
426-
427-
#define __copy_to_user_inatomic __copy_to_user
428-
#define __copy_from_user_inatomic __copy_from_user
429-
430-
431424
#define copy_from_user(to,from,n) ({ \
432425
void *__copy_to = (void *) (to); \
433426
void *__copy_from = (void *) (from); \
@@ -438,9 +431,20 @@ __copy_res = __copy_user(__copy_to, __copy_from, __copy_size); \
438431
} else __copy_res = __copy_size; \
439432
__copy_res; })
440433

441-
#define __copy_from_user(to,from,n) \
442-
__copy_user((void *)(to), \
443-
(void *)(from), n)
434+
static __always_inline unsigned long
435+
__copy_from_user(void *to, const void __user *from, unsigned long n)
436+
{
437+
return __copy_user(to, (__force void *)from, n);
438+
}
439+
440+
static __always_inline unsigned long __must_check
441+
__copy_to_user(void __user *to, const void *from, unsigned long n)
442+
{
443+
return __copy_user((__force void *)to, from, n);
444+
}
445+
446+
#define __copy_to_user_inatomic __copy_to_user
447+
#define __copy_from_user_inatomic __copy_from_user
444448

445449
/*
446450
* Clear the area and return remaining number of bytes

0 commit comments

Comments
 (0)