| .. | .. |
|---|
| 9 | 9 | */ |
|---|
| 10 | 10 | #include <linux/string.h> |
|---|
| 11 | 11 | |
|---|
| 12 | | -#include <asm/segment.h> |
|---|
| 12 | +#ifdef CONFIG_UACCESS_MEMCPY |
|---|
| 13 | +#include <asm/unaligned.h> |
|---|
| 13 | 14 | |
|---|
| 15 | +static __always_inline int |
|---|
| 16 | +__get_user_fn(size_t size, const void __user *from, void *to) |
|---|
| 17 | +{ |
|---|
| 18 | + BUILD_BUG_ON(!__builtin_constant_p(size)); |
|---|
| 19 | + |
|---|
| 20 | + switch (size) { |
|---|
| 21 | + case 1: |
|---|
| 22 | + *(u8 *)to = get_unaligned((u8 __force *)from); |
|---|
| 23 | + return 0; |
|---|
| 24 | + case 2: |
|---|
| 25 | + *(u16 *)to = get_unaligned((u16 __force *)from); |
|---|
| 26 | + return 0; |
|---|
| 27 | + case 4: |
|---|
| 28 | + *(u32 *)to = get_unaligned((u32 __force *)from); |
|---|
| 29 | + return 0; |
|---|
| 30 | + case 8: |
|---|
| 31 | + *(u64 *)to = get_unaligned((u64 __force *)from); |
|---|
| 32 | + return 0; |
|---|
| 33 | + default: |
|---|
| 34 | + BUILD_BUG(); |
|---|
| 35 | + return 0; |
|---|
| 36 | + } |
|---|
| 37 | + |
|---|
| 38 | +} |
|---|
| 39 | +#define __get_user_fn(sz, u, k) __get_user_fn(sz, u, k) |
|---|
| 40 | + |
|---|
| 41 | +static __always_inline int |
|---|
| 42 | +__put_user_fn(size_t size, void __user *to, void *from) |
|---|
| 43 | +{ |
|---|
| 44 | + BUILD_BUG_ON(!__builtin_constant_p(size)); |
|---|
| 45 | + |
|---|
| 46 | + switch (size) { |
|---|
| 47 | + case 1: |
|---|
| 48 | + put_unaligned(*(u8 *)from, (u8 __force *)to); |
|---|
| 49 | + return 0; |
|---|
| 50 | + case 2: |
|---|
| 51 | + put_unaligned(*(u16 *)from, (u16 __force *)to); |
|---|
| 52 | + return 0; |
|---|
| 53 | + case 4: |
|---|
| 54 | + put_unaligned(*(u32 *)from, (u32 __force *)to); |
|---|
| 55 | + return 0; |
|---|
| 56 | + case 8: |
|---|
| 57 | + put_unaligned(*(u64 *)from, (u64 __force *)to); |
|---|
| 58 | + return 0; |
|---|
| 59 | + default: |
|---|
| 60 | + BUILD_BUG(); |
|---|
| 61 | + return 0; |
|---|
| 62 | + } |
|---|
| 63 | +} |
|---|
| 64 | +#define __put_user_fn(sz, u, k) __put_user_fn(sz, u, k) |
|---|
| 65 | + |
|---|
| 66 | +#define __get_kernel_nofault(dst, src, type, err_label) \ |
|---|
| 67 | +do { \ |
|---|
| 68 | + *((type *)dst) = get_unaligned((type *)(src)); \ |
|---|
| 69 | + if (0) /* make sure the label looks used to the compiler */ \ |
|---|
| 70 | + goto err_label; \ |
|---|
| 71 | +} while (0) |
|---|
| 72 | + |
|---|
| 73 | +#define __put_kernel_nofault(dst, src, type, err_label) \ |
|---|
| 74 | +do { \ |
|---|
| 75 | + put_unaligned(*((type *)src), (type *)(dst)); \ |
|---|
| 76 | + if (0) /* make sure the label looks used to the compiler */ \ |
|---|
| 77 | + goto err_label; \ |
|---|
| 78 | +} while (0) |
|---|
| 79 | + |
|---|
| 80 | +#define HAVE_GET_KERNEL_NOFAULT 1 |
|---|
| 81 | + |
|---|
| 82 | +static inline __must_check unsigned long |
|---|
| 83 | +raw_copy_from_user(void *to, const void __user * from, unsigned long n) |
|---|
| 84 | +{ |
|---|
| 85 | + memcpy(to, (const void __force *)from, n); |
|---|
| 86 | + return 0; |
|---|
| 87 | +} |
|---|
| 88 | + |
|---|
| 89 | +static inline __must_check unsigned long |
|---|
| 90 | +raw_copy_to_user(void __user *to, const void *from, unsigned long n) |
|---|
| 91 | +{ |
|---|
| 92 | + memcpy((void __force *)to, from, n); |
|---|
| 93 | + return 0; |
|---|
| 94 | +} |
|---|
| 95 | +#define INLINE_COPY_FROM_USER |
|---|
| 96 | +#define INLINE_COPY_TO_USER |
|---|
| 97 | +#endif /* CONFIG_UACCESS_MEMCPY */ |
|---|
| 98 | + |
|---|
| 99 | +#ifdef CONFIG_SET_FS |
|---|
| 14 | 100 | #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) }) |
|---|
| 15 | 101 | |
|---|
| 16 | 102 | #ifndef KERNEL_DS |
|---|
| .. | .. |
|---|
| 22 | 108 | #endif |
|---|
| 23 | 109 | |
|---|
| 24 | 110 | #ifndef get_fs |
|---|
| 25 | | -#define get_ds() (KERNEL_DS) |
|---|
| 26 | 111 | #define get_fs() (current_thread_info()->addr_limit) |
|---|
| 27 | 112 | |
|---|
| 28 | 113 | static inline void set_fs(mm_segment_t fs) |
|---|
| .. | .. |
|---|
| 31 | 116 | } |
|---|
| 32 | 117 | #endif |
|---|
| 33 | 118 | |
|---|
| 34 | | -#ifndef segment_eq |
|---|
| 35 | | -#define segment_eq(a, b) ((a).seg == (b).seg) |
|---|
| 119 | +#ifndef uaccess_kernel |
|---|
| 120 | +#define uaccess_kernel() (get_fs().seg == KERNEL_DS.seg) |
|---|
| 36 | 121 | #endif |
|---|
| 122 | +#endif /* CONFIG_SET_FS */ |
|---|
| 37 | 123 | |
|---|
| 38 | | -#define access_ok(type, addr, size) __access_ok((unsigned long)(addr),(size)) |
|---|
| 124 | +#define access_ok(addr, size) __access_ok((unsigned long)(addr),(size)) |
|---|
| 39 | 125 | |
|---|
| 40 | 126 | /* |
|---|
| 41 | 127 | * The architecture should really override this if possible, at least |
|---|
| .. | .. |
|---|
| 78 | 164 | ({ \ |
|---|
| 79 | 165 | void __user *__p = (ptr); \ |
|---|
| 80 | 166 | might_fault(); \ |
|---|
| 81 | | - access_ok(VERIFY_WRITE, __p, sizeof(*ptr)) ? \ |
|---|
| 167 | + access_ok(__p, sizeof(*ptr)) ? \ |
|---|
| 82 | 168 | __put_user((x), ((__typeof__(*(ptr)) __user *)__p)) : \ |
|---|
| 83 | 169 | -EFAULT; \ |
|---|
| 84 | 170 | }) |
|---|
| .. | .. |
|---|
| 140 | 226 | ({ \ |
|---|
| 141 | 227 | const void __user *__p = (ptr); \ |
|---|
| 142 | 228 | might_fault(); \ |
|---|
| 143 | | - access_ok(VERIFY_READ, __p, sizeof(*ptr)) ? \ |
|---|
| 229 | + access_ok(__p, sizeof(*ptr)) ? \ |
|---|
| 144 | 230 | __get_user((x), (__typeof__(*(ptr)) __user *)__p) :\ |
|---|
| 145 | 231 | ((x) = (__typeof__(*(ptr)))0,-EFAULT); \ |
|---|
| 146 | 232 | }) |
|---|
| .. | .. |
|---|
| 175 | 261 | static inline long |
|---|
| 176 | 262 | strncpy_from_user(char *dst, const char __user *src, long count) |
|---|
| 177 | 263 | { |
|---|
| 178 | | - if (!access_ok(VERIFY_READ, src, 1)) |
|---|
| 264 | + if (!access_ok(src, 1)) |
|---|
| 179 | 265 | return -EFAULT; |
|---|
| 180 | 266 | return __strncpy_from_user(dst, src, count); |
|---|
| 181 | 267 | } |
|---|
| .. | .. |
|---|
| 196 | 282 | */ |
|---|
| 197 | 283 | static inline long strnlen_user(const char __user *src, long n) |
|---|
| 198 | 284 | { |
|---|
| 199 | | - if (!access_ok(VERIFY_READ, src, 1)) |
|---|
| 285 | + if (!access_ok(src, 1)) |
|---|
| 200 | 286 | return 0; |
|---|
| 201 | 287 | return __strnlen_user(src, n); |
|---|
| 202 | 288 | } |
|---|
| .. | .. |
|---|
| 217 | 303 | clear_user(void __user *to, unsigned long n) |
|---|
| 218 | 304 | { |
|---|
| 219 | 305 | might_fault(); |
|---|
| 220 | | - if (!access_ok(VERIFY_WRITE, to, n)) |
|---|
| 306 | + if (!access_ok(to, n)) |
|---|
| 221 | 307 | return n; |
|---|
| 222 | 308 | |
|---|
| 223 | 309 | return __clear_user(to, n); |
|---|