aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-sh/uaccess.h
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2006-09-27 04:07:07 -0400
committerPaul Mundt <lethal@linux-sh.org>2006-09-27 04:07:07 -0400
commit2991be725260d6fec11691a6138b9d71de949956 (patch)
tree407241b126eed902bacba4e02043930c6ce087b4 /include/asm-sh/uaccess.h
parent0f08f338083cc1d68788ccbccc44bd0502fc57ae (diff)
sh: Fixup __strnlen_user() behaviour.
Drop TIF_USERSPACE and add addr_limit to the thread_info struct. Subsequently, use that for address checking in strnlen_user() to ward off bogus -EFAULTs. Make __strnlen_user() return 0 on exception, rather than -EFAULT. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'include/asm-sh/uaccess.h')
-rw-r--r--include/asm-sh/uaccess.h65
1 files changed, 13 insertions, 52 deletions
diff --git a/include/asm-sh/uaccess.h b/include/asm-sh/uaccess.h
index 2cb01861e7c5..6c0014dd2ef7 100644
--- a/include/asm-sh/uaccess.h
+++ b/include/asm-sh/uaccess.h
@@ -16,21 +16,9 @@
16#include <linux/errno.h> 16#include <linux/errno.h>
17#include <linux/sched.h> 17#include <linux/sched.h>
18 18
19/*
20 * NOTE: Macro/functions in this file depends on threads_info.h implementation.
21 * Assumes:
22 * TI_FLAGS == 8
23 * TIF_USERSPACE == 31
24 * USER_ADDR_LIMIT == 0x80000000
25 */
26
27#define VERIFY_READ 0 19#define VERIFY_READ 0
28#define VERIFY_WRITE 1 20#define VERIFY_WRITE 1
29 21
30typedef struct {
31 unsigned int is_user_space;
32} mm_segment_t;
33
34/* 22/*
35 * The fs value determines whether argument validity checking should be 23 * The fs value determines whether argument validity checking should be
36 * performed or not. If get_fs() == USER_DS, checking is performed, with 24 * performed or not. If get_fs() == USER_DS, checking is performed, with
@@ -40,12 +28,14 @@ typedef struct {
40 */ 28 */
41 29
42#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) }) 30#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
43#define segment_eq(a,b) ((a).is_user_space == (b).is_user_space)
44 31
45#define USER_ADDR_LIMIT 0x80000000 32#define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFFUL)
33#define USER_DS MAKE_MM_SEG(PAGE_OFFSET)
34
35#define segment_eq(a,b) ((a).seg == (b).seg)
46 36
47#define KERNEL_DS MAKE_MM_SEG(0) 37#define __addr_ok(addr) \
48#define USER_DS MAKE_MM_SEG(1) 38 ((unsigned long)(addr) < (current_thread_info()->addr_limit.seg))
49 39
50#define get_ds() (KERNEL_DS) 40#define get_ds() (KERNEL_DS)
51 41
@@ -76,31 +66,8 @@ static inline int __access_ok(unsigned long addr, unsigned long size)
76 return ((addr >= memory_start) && ((addr + size) < memory_end)); 66 return ((addr >= memory_start) && ((addr + size) < memory_end));
77} 67}
78#else /* CONFIG_MMU */ 68#else /* CONFIG_MMU */
79static inline mm_segment_t get_fs(void) 69#define get_fs() (current_thread_info()->addr_limit)
80{ 70#define set_fs(x) (current_thread_info()->addr_limit = (x))
81 return MAKE_MM_SEG(test_thread_flag(TIF_USERSPACE));
82}
83
84static inline void set_fs(mm_segment_t s)
85{
86 unsigned long ti, flag;
87 __asm__ __volatile__(
88 "stc r7_bank, %0\n\t"
89 "mov.l @(8,%0), %1\n\t"
90 "shal %1\n\t"
91 "cmp/pl %2\n\t"
92 "rotcr %1\n\t"
93 "mov.l %1, @(8,%0)"
94 : "=&r" (ti), "=&r" (flag)
95 : "r" (s.is_user_space)
96 : "t");
97/****
98 if (s.is_user_space)
99 set_thread_flag(TIF_USERSPACE);
100 else
101 clear_thread_flag(TIF_USERSPACE);
102****/
103}
104 71
105/* 72/*
106 * __access_ok: Check if address with size is OK or not. 73 * __access_ok: Check if address with size is OK or not.
@@ -108,7 +75,7 @@ static inline void set_fs(mm_segment_t s)
108 * We do three checks: 75 * We do three checks:
109 * (1) is it user space? 76 * (1) is it user space?
110 * (2) addr + size --> carry? 77 * (2) addr + size --> carry?
111 * (3) addr + size >= 0x80000000 (USER_ADDR_LIMIT) 78 * (3) addr + size >= 0x80000000 (PAGE_OFFSET)
112 * 79 *
113 * (1) (2) (3) | RESULT 80 * (1) (2) (3) | RESULT
114 * 0 0 0 | ok 81 * 0 0 0 | ok
@@ -541,7 +508,7 @@ static __inline__ long __strnlen_user(const char __user *__s, long __n)
541 "3:\n\t" 508 "3:\n\t"
542 "mov.l 4f, %1\n\t" 509 "mov.l 4f, %1\n\t"
543 "jmp @%1\n\t" 510 "jmp @%1\n\t"
544 " mov %5, %0\n" 511 " mov #0, %0\n"
545 ".balign 4\n" 512 ".balign 4\n"
546 "4: .long 2b\n" 513 "4: .long 2b\n"
547 ".previous\n" 514 ".previous\n"
@@ -550,26 +517,20 @@ static __inline__ long __strnlen_user(const char __user *__s, long __n)
550 " .long 1b,3b\n" 517 " .long 1b,3b\n"
551 ".previous" 518 ".previous"
552 : "=z" (res), "=&r" (__dummy) 519 : "=z" (res), "=&r" (__dummy)
553 : "0" (0), "r" (__s), "r" (__n), "i" (-EFAULT) 520 : "0" (0), "r" (__s), "r" (__n)
554 : "t"); 521 : "t");
555 return res; 522 return res;
556} 523}
557 524
558static __inline__ long strnlen_user(const char __user *s, long n) 525static __inline__ long strnlen_user(const char __user *s, long n)
559{ 526{
560 if (!access_ok(VERIFY_READ, s, n)) 527 if (!__addr_ok(s))
561 return 0; 528 return 0;
562 else 529 else
563 return __strnlen_user(s, n); 530 return __strnlen_user(s, n);
564} 531}
565 532
566static __inline__ long strlen_user(const char __user *s) 533#define strlen_user(str) strnlen_user(str, ~0UL >> 1)
567{
568 if (!access_ok(VERIFY_READ, s, 0))
569 return 0;
570 else
571 return __strnlen_user(s, ~0UL >> 1);
572}
573 534
574/* 535/*
575 * The exception table consists of pairs of addresses: the first is the 536 * The exception table consists of pairs of addresses: the first is the