aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/include/asm/uaccess.h
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/include/asm/uaccess.h')
-rw-r--r--arch/mips/include/asm/uaccess.h66
1 files changed, 48 insertions, 18 deletions
diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
index 09ff5bb17445..8de858f5449f 100644
--- a/arch/mips/include/asm/uaccess.h
+++ b/arch/mips/include/asm/uaccess.h
@@ -105,10 +105,20 @@
105#define __access_mask get_fs().seg 105#define __access_mask get_fs().seg
106 106
107#define __access_ok(addr, size, mask) \ 107#define __access_ok(addr, size, mask) \
108 (((signed long)((mask) & ((addr) | ((addr) + (size)) | __ua_size(size)))) == 0) 108({ \
109 unsigned long __addr = (unsigned long) (addr); \
110 unsigned long __size = size; \
111 unsigned long __mask = mask; \
112 unsigned long __ok; \
113 \
114 __chk_user_ptr(addr); \
115 __ok = (signed long)(__mask & (__addr | (__addr + __size) | \
116 __ua_size(__size))); \
117 __ok == 0; \
118})
109 119
110#define access_ok(type, addr, size) \ 120#define access_ok(type, addr, size) \
111 likely(__access_ok((unsigned long)(addr), (size), __access_mask)) 121 likely(__access_ok((addr), (size), __access_mask))
112 122
113/* 123/*
114 * put_user: - Write a simple value into user space. 124 * put_user: - Write a simple value into user space.
@@ -225,6 +235,7 @@ do { \
225({ \ 235({ \
226 int __gu_err; \ 236 int __gu_err; \
227 \ 237 \
238 __chk_user_ptr(ptr); \
228 __get_user_common((x), size, ptr); \ 239 __get_user_common((x), size, ptr); \
229 __gu_err; \ 240 __gu_err; \
230}) 241})
@@ -234,6 +245,7 @@ do { \
234 int __gu_err = -EFAULT; \ 245 int __gu_err = -EFAULT; \
235 const __typeof__(*(ptr)) __user * __gu_ptr = (ptr); \ 246 const __typeof__(*(ptr)) __user * __gu_ptr = (ptr); \
236 \ 247 \
248 might_fault(); \
237 if (likely(access_ok(VERIFY_READ, __gu_ptr, size))) \ 249 if (likely(access_ok(VERIFY_READ, __gu_ptr, size))) \
238 __get_user_common((x), size, __gu_ptr); \ 250 __get_user_common((x), size, __gu_ptr); \
239 \ 251 \
@@ -305,6 +317,7 @@ do { \
305 __typeof__(*(ptr)) __pu_val; \ 317 __typeof__(*(ptr)) __pu_val; \
306 int __pu_err = 0; \ 318 int __pu_err = 0; \
307 \ 319 \
320 __chk_user_ptr(ptr); \
308 __pu_val = (x); \ 321 __pu_val = (x); \
309 switch (size) { \ 322 switch (size) { \
310 case 1: __put_user_asm("sb", ptr); break; \ 323 case 1: __put_user_asm("sb", ptr); break; \
@@ -322,6 +335,7 @@ do { \
322 __typeof__(*(ptr)) __pu_val = (x); \ 335 __typeof__(*(ptr)) __pu_val = (x); \
323 int __pu_err = -EFAULT; \ 336 int __pu_err = -EFAULT; \
324 \ 337 \
338 might_fault(); \
325 if (likely(access_ok(VERIFY_WRITE, __pu_addr, size))) { \ 339 if (likely(access_ok(VERIFY_WRITE, __pu_addr, size))) { \
326 switch (size) { \ 340 switch (size) { \
327 case 1: __put_user_asm("sb", __pu_addr); break; \ 341 case 1: __put_user_asm("sb", __pu_addr); break; \
@@ -696,10 +710,10 @@ extern size_t __copy_user(void *__to, const void *__from, size_t __n);
696 const void *__cu_from; \ 710 const void *__cu_from; \
697 long __cu_len; \ 711 long __cu_len; \
698 \ 712 \
699 might_sleep(); \
700 __cu_to = (to); \ 713 __cu_to = (to); \
701 __cu_from = (from); \ 714 __cu_from = (from); \
702 __cu_len = (n); \ 715 __cu_len = (n); \
716 might_fault(); \
703 __cu_len = __invoke_copy_to_user(__cu_to, __cu_from, __cu_len); \ 717 __cu_len = __invoke_copy_to_user(__cu_to, __cu_from, __cu_len); \
704 __cu_len; \ 718 __cu_len; \
705}) 719})
@@ -752,13 +766,14 @@ extern size_t __copy_user_inatomic(void *__to, const void *__from, size_t __n);
752 const void *__cu_from; \ 766 const void *__cu_from; \
753 long __cu_len; \ 767 long __cu_len; \
754 \ 768 \
755 might_sleep(); \
756 __cu_to = (to); \ 769 __cu_to = (to); \
757 __cu_from = (from); \ 770 __cu_from = (from); \
758 __cu_len = (n); \ 771 __cu_len = (n); \
759 if (access_ok(VERIFY_WRITE, __cu_to, __cu_len)) \ 772 if (access_ok(VERIFY_WRITE, __cu_to, __cu_len)) { \
773 might_fault(); \
760 __cu_len = __invoke_copy_to_user(__cu_to, __cu_from, \ 774 __cu_len = __invoke_copy_to_user(__cu_to, __cu_from, \
761 __cu_len); \ 775 __cu_len); \
776 } \
762 __cu_len; \ 777 __cu_len; \
763}) 778})
764 779
@@ -831,10 +846,10 @@ extern size_t __copy_user_inatomic(void *__to, const void *__from, size_t __n);
831 const void __user *__cu_from; \ 846 const void __user *__cu_from; \
832 long __cu_len; \ 847 long __cu_len; \
833 \ 848 \
834 might_sleep(); \
835 __cu_to = (to); \ 849 __cu_to = (to); \
836 __cu_from = (from); \ 850 __cu_from = (from); \
837 __cu_len = (n); \ 851 __cu_len = (n); \
852 might_fault(); \
838 __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \ 853 __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
839 __cu_len); \ 854 __cu_len); \
840 __cu_len; \ 855 __cu_len; \
@@ -862,17 +877,31 @@ extern size_t __copy_user_inatomic(void *__to, const void *__from, size_t __n);
862 const void __user *__cu_from; \ 877 const void __user *__cu_from; \
863 long __cu_len; \ 878 long __cu_len; \
864 \ 879 \
865 might_sleep(); \
866 __cu_to = (to); \ 880 __cu_to = (to); \
867 __cu_from = (from); \ 881 __cu_from = (from); \
868 __cu_len = (n); \ 882 __cu_len = (n); \
869 if (access_ok(VERIFY_READ, __cu_from, __cu_len)) \ 883 if (access_ok(VERIFY_READ, __cu_from, __cu_len)) { \
884 might_fault(); \
870 __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \ 885 __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
871 __cu_len); \ 886 __cu_len); \
887 } \
872 __cu_len; \ 888 __cu_len; \
873}) 889})
874 890
875#define __copy_in_user(to, from, n) __copy_from_user(to, from, n) 891#define __copy_in_user(to, from, n) \
892({ \
893 void __user *__cu_to; \
894 const void __user *__cu_from; \
895 long __cu_len; \
896 \
897 __cu_to = (to); \
898 __cu_from = (from); \
899 __cu_len = (n); \
900 might_fault(); \
901 __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
902 __cu_len); \
903 __cu_len; \
904})
876 905
877#define copy_in_user(to, from, n) \ 906#define copy_in_user(to, from, n) \
878({ \ 907({ \
@@ -880,14 +909,15 @@ extern size_t __copy_user_inatomic(void *__to, const void *__from, size_t __n);
880 const void __user *__cu_from; \ 909 const void __user *__cu_from; \
881 long __cu_len; \ 910 long __cu_len; \
882 \ 911 \
883 might_sleep(); \
884 __cu_to = (to); \ 912 __cu_to = (to); \
885 __cu_from = (from); \ 913 __cu_from = (from); \
886 __cu_len = (n); \ 914 __cu_len = (n); \
887 if (likely(access_ok(VERIFY_READ, __cu_from, __cu_len) && \ 915 if (likely(access_ok(VERIFY_READ, __cu_from, __cu_len) && \
888 access_ok(VERIFY_WRITE, __cu_to, __cu_len))) \ 916 access_ok(VERIFY_WRITE, __cu_to, __cu_len))) { \
917 might_fault(); \
889 __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \ 918 __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
890 __cu_len); \ 919 __cu_len); \
920 } \
891 __cu_len; \ 921 __cu_len; \
892}) 922})
893 923
@@ -907,7 +937,7 @@ __clear_user(void __user *addr, __kernel_size_t size)
907{ 937{
908 __kernel_size_t res; 938 __kernel_size_t res;
909 939
910 might_sleep(); 940 might_fault();
911 __asm__ __volatile__( 941 __asm__ __volatile__(
912 "move\t$4, %1\n\t" 942 "move\t$4, %1\n\t"
913 "move\t$5, $0\n\t" 943 "move\t$5, $0\n\t"
@@ -956,7 +986,7 @@ __strncpy_from_user(char *__to, const char __user *__from, long __len)
956{ 986{
957 long res; 987 long res;
958 988
959 might_sleep(); 989 might_fault();
960 __asm__ __volatile__( 990 __asm__ __volatile__(
961 "move\t$4, %1\n\t" 991 "move\t$4, %1\n\t"
962 "move\t$5, %2\n\t" 992 "move\t$5, %2\n\t"
@@ -993,7 +1023,7 @@ strncpy_from_user(char *__to, const char __user *__from, long __len)
993{ 1023{
994 long res; 1024 long res;
995 1025
996 might_sleep(); 1026 might_fault();
997 __asm__ __volatile__( 1027 __asm__ __volatile__(
998 "move\t$4, %1\n\t" 1028 "move\t$4, %1\n\t"
999 "move\t$5, %2\n\t" 1029 "move\t$5, %2\n\t"
@@ -1012,7 +1042,7 @@ static inline long __strlen_user(const char __user *s)
1012{ 1042{
1013 long res; 1043 long res;
1014 1044
1015 might_sleep(); 1045 might_fault();
1016 __asm__ __volatile__( 1046 __asm__ __volatile__(
1017 "move\t$4, %1\n\t" 1047 "move\t$4, %1\n\t"
1018 __MODULE_JAL(__strlen_user_nocheck_asm) 1048 __MODULE_JAL(__strlen_user_nocheck_asm)
@@ -1042,7 +1072,7 @@ static inline long strlen_user(const char __user *s)
1042{ 1072{
1043 long res; 1073 long res;
1044 1074
1045 might_sleep(); 1075 might_fault();
1046 __asm__ __volatile__( 1076 __asm__ __volatile__(
1047 "move\t$4, %1\n\t" 1077 "move\t$4, %1\n\t"
1048 __MODULE_JAL(__strlen_user_asm) 1078 __MODULE_JAL(__strlen_user_asm)
@@ -1059,7 +1089,7 @@ static inline long __strnlen_user(const char __user *s, long n)
1059{ 1089{
1060 long res; 1090 long res;
1061 1091
1062 might_sleep(); 1092 might_fault();
1063 __asm__ __volatile__( 1093 __asm__ __volatile__(
1064 "move\t$4, %1\n\t" 1094 "move\t$4, %1\n\t"
1065 "move\t$5, %2\n\t" 1095 "move\t$5, %2\n\t"
@@ -1090,7 +1120,7 @@ static inline long strnlen_user(const char __user *s, long n)
1090{ 1120{
1091 long res; 1121 long res;
1092 1122
1093 might_sleep(); 1123 might_fault();
1094 __asm__ __volatile__( 1124 __asm__ __volatile__(
1095 "move\t$4, %1\n\t" 1125 "move\t$4, %1\n\t"
1096 "move\t$5, %2\n\t" 1126 "move\t$5, %2\n\t"