Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Based on arch/arm/include/asm/uaccess.h |
| 3 | * |
| 4 | * Copyright (C) 2012 ARM Ltd. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | #ifndef __ASM_UACCESS_H |
| 19 | #define __ASM_UACCESS_H |
| 20 | |
Catalin Marinas | bd38967 | 2016-07-01 14:58:21 +0100 | [diff] [blame] | 21 | #include <asm/alternative.h> |
Catalin Marinas | 4b65a5d | 2016-07-01 16:53:00 +0100 | [diff] [blame] | 22 | #include <asm/kernel-pgtable.h> |
Catalin Marinas | bd38967 | 2016-07-01 14:58:21 +0100 | [diff] [blame] | 23 | #include <asm/sysreg.h> |
| 24 | |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 25 | /* |
| 26 | * User space memory access functions |
| 27 | */ |
Andre Przywara | 87261d1 | 2016-10-19 14:40:54 +0100 | [diff] [blame] | 28 | #include <linux/bitops.h> |
Yang Shi | bffe1ba | 2016-06-08 14:40:56 -0700 | [diff] [blame] | 29 | #include <linux/kasan-checks.h> |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 30 | #include <linux/string.h> |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 31 | |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 32 | #include <asm/cpufeature.h> |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 33 | #include <asm/ptrace.h> |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 34 | #include <asm/memory.h> |
| 35 | #include <asm/compiler.h> |
Al Viro | 4658393 | 2016-12-25 14:00:03 -0500 | [diff] [blame] | 36 | #include <asm/extable.h> |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 37 | |
| 38 | #define KERNEL_DS (-1UL) |
| 39 | #define get_ds() (KERNEL_DS) |
| 40 | |
| 41 | #define USER_DS TASK_SIZE_64 |
| 42 | #define get_fs() (current_thread_info()->addr_limit) |
| 43 | |
| 44 | static inline void set_fs(mm_segment_t fs) |
| 45 | { |
| 46 | current_thread_info()->addr_limit = fs; |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 47 | |
| 48 | /* |
| 49 | * Enable/disable UAO so that copy_to_user() etc can access |
| 50 | * kernel memory with the unprivileged instructions. |
| 51 | */ |
| 52 | if (IS_ENABLED(CONFIG_ARM64_UAO) && fs == KERNEL_DS) |
| 53 | asm(ALTERNATIVE("nop", SET_PSTATE_UAO(1), ARM64_HAS_UAO)); |
| 54 | else |
| 55 | asm(ALTERNATIVE("nop", SET_PSTATE_UAO(0), ARM64_HAS_UAO, |
| 56 | CONFIG_ARM64_UAO)); |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Michael S. Tsirkin | 967f0e5 | 2015-01-06 15:11:13 +0200 | [diff] [blame] | 59 | #define segment_eq(a, b) ((a) == (b)) |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 60 | |
| 61 | /* |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 62 | * Test whether a block of memory is a valid user space address. |
| 63 | * Returns 1 if the range is valid, 0 otherwise. |
| 64 | * |
| 65 | * This is equivalent to the following test: |
Christopher Covington | 31b1e94 | 2014-03-19 16:29:37 +0000 | [diff] [blame] | 66 | * (u65)addr + (u65)size <= current->addr_limit |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 67 | * |
| 68 | * This needs 65-bit arithmetic. |
| 69 | */ |
| 70 | #define __range_ok(addr, size) \ |
| 71 | ({ \ |
Will Deacon | c396fe7 | 2017-07-03 14:37:46 +0100 | [diff] [blame] | 72 | unsigned long __addr = (unsigned long)(addr); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 73 | unsigned long flag, roksum; \ |
| 74 | __chk_user_ptr(addr); \ |
Christopher Covington | 31b1e94 | 2014-03-19 16:29:37 +0000 | [diff] [blame] | 75 | asm("adds %1, %1, %3; ccmp %1, %4, #2, cc; cset %0, ls" \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 76 | : "=&r" (flag), "=&r" (roksum) \ |
Mark Rutland | a06040d | 2017-05-03 16:09:35 +0100 | [diff] [blame] | 77 | : "1" (__addr), "Ir" (size), \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 78 | "r" (current_thread_info()->addr_limit) \ |
| 79 | : "cc"); \ |
| 80 | flag; \ |
| 81 | }) |
| 82 | |
Andre Przywara | 87261d1 | 2016-10-19 14:40:54 +0100 | [diff] [blame] | 83 | /* |
Kristina Martsenko | 7dcd9dd8 | 2017-05-03 16:37:46 +0100 | [diff] [blame] | 84 | * When dealing with data aborts, watchpoints, or instruction traps we may end |
| 85 | * up with a tagged userland pointer. Clear the tag to get a sane pointer to |
| 86 | * pass on to access_ok(), for instance. |
Andre Przywara | 87261d1 | 2016-10-19 14:40:54 +0100 | [diff] [blame] | 87 | */ |
| 88 | #define untagged_addr(addr) sign_extend64(addr, 55) |
| 89 | |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 90 | #define access_ok(type, addr, size) __range_ok(addr, size) |
Will Deacon | 12a0ef7 | 2013-11-06 17:20:22 +0000 | [diff] [blame] | 91 | #define user_addr_max get_fs |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 92 | |
Ard Biesheuvel | 6c94f27 | 2016-01-01 15:02:12 +0100 | [diff] [blame] | 93 | #define _ASM_EXTABLE(from, to) \ |
| 94 | " .pushsection __ex_table, \"a\"\n" \ |
| 95 | " .align 3\n" \ |
| 96 | " .long (" #from " - .), (" #to " - .)\n" \ |
| 97 | " .popsection\n" |
| 98 | |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 99 | /* |
Catalin Marinas | bd38967 | 2016-07-01 14:58:21 +0100 | [diff] [blame] | 100 | * User access enabling/disabling. |
| 101 | */ |
Catalin Marinas | 4b65a5d | 2016-07-01 16:53:00 +0100 | [diff] [blame] | 102 | #ifdef CONFIG_ARM64_SW_TTBR0_PAN |
| 103 | static inline void __uaccess_ttbr0_disable(void) |
| 104 | { |
| 105 | unsigned long ttbr; |
| 106 | |
| 107 | /* reserved_ttbr0 placed at the end of swapper_pg_dir */ |
| 108 | ttbr = read_sysreg(ttbr1_el1) + SWAPPER_DIR_SIZE; |
| 109 | write_sysreg(ttbr, ttbr0_el1); |
| 110 | isb(); |
| 111 | } |
| 112 | |
| 113 | static inline void __uaccess_ttbr0_enable(void) |
| 114 | { |
| 115 | unsigned long flags; |
| 116 | |
| 117 | /* |
| 118 | * Disable interrupts to avoid preemption between reading the 'ttbr0' |
| 119 | * variable and the MSR. A context switch could trigger an ASID |
| 120 | * roll-over and an update of 'ttbr0'. |
| 121 | */ |
| 122 | local_irq_save(flags); |
| 123 | write_sysreg(current_thread_info()->ttbr0, ttbr0_el1); |
| 124 | isb(); |
| 125 | local_irq_restore(flags); |
| 126 | } |
| 127 | |
| 128 | static inline bool uaccess_ttbr0_disable(void) |
| 129 | { |
| 130 | if (!system_uses_ttbr0_pan()) |
| 131 | return false; |
| 132 | __uaccess_ttbr0_disable(); |
| 133 | return true; |
| 134 | } |
| 135 | |
| 136 | static inline bool uaccess_ttbr0_enable(void) |
| 137 | { |
| 138 | if (!system_uses_ttbr0_pan()) |
| 139 | return false; |
| 140 | __uaccess_ttbr0_enable(); |
| 141 | return true; |
| 142 | } |
| 143 | #else |
| 144 | static inline bool uaccess_ttbr0_disable(void) |
| 145 | { |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | static inline bool uaccess_ttbr0_enable(void) |
| 150 | { |
| 151 | return false; |
| 152 | } |
| 153 | #endif |
| 154 | |
Catalin Marinas | bd38967 | 2016-07-01 14:58:21 +0100 | [diff] [blame] | 155 | #define __uaccess_disable(alt) \ |
| 156 | do { \ |
Catalin Marinas | 4b65a5d | 2016-07-01 16:53:00 +0100 | [diff] [blame] | 157 | if (!uaccess_ttbr0_disable()) \ |
| 158 | asm(ALTERNATIVE("nop", SET_PSTATE_PAN(1), alt, \ |
| 159 | CONFIG_ARM64_PAN)); \ |
Catalin Marinas | bd38967 | 2016-07-01 14:58:21 +0100 | [diff] [blame] | 160 | } while (0) |
| 161 | |
| 162 | #define __uaccess_enable(alt) \ |
| 163 | do { \ |
Marc Zyngier | 7503712 | 2016-12-12 13:50:26 +0000 | [diff] [blame] | 164 | if (!uaccess_ttbr0_enable()) \ |
Catalin Marinas | 4b65a5d | 2016-07-01 16:53:00 +0100 | [diff] [blame] | 165 | asm(ALTERNATIVE("nop", SET_PSTATE_PAN(0), alt, \ |
| 166 | CONFIG_ARM64_PAN)); \ |
Catalin Marinas | bd38967 | 2016-07-01 14:58:21 +0100 | [diff] [blame] | 167 | } while (0) |
| 168 | |
| 169 | static inline void uaccess_disable(void) |
| 170 | { |
| 171 | __uaccess_disable(ARM64_HAS_PAN); |
| 172 | } |
| 173 | |
| 174 | static inline void uaccess_enable(void) |
| 175 | { |
| 176 | __uaccess_enable(ARM64_HAS_PAN); |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * These functions are no-ops when UAO is present. |
| 181 | */ |
| 182 | static inline void uaccess_disable_not_uao(void) |
| 183 | { |
| 184 | __uaccess_disable(ARM64_ALT_PAN_NOT_UAO); |
| 185 | } |
| 186 | |
| 187 | static inline void uaccess_enable_not_uao(void) |
| 188 | { |
| 189 | __uaccess_enable(ARM64_ALT_PAN_NOT_UAO); |
| 190 | } |
| 191 | |
| 192 | /* |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 193 | * The "__xxx" versions of the user access functions do not verify the address |
| 194 | * space - it must have been done previously with a separate "access_ok()" |
| 195 | * call. |
| 196 | * |
| 197 | * The "__xxx_error" versions set the third argument to -EFAULT if an error |
| 198 | * occurs, and leave it unchanged on success. |
| 199 | */ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 200 | #define __get_user_asm(instr, alt_instr, reg, x, addr, err, feature) \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 201 | asm volatile( \ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 202 | "1:"ALTERNATIVE(instr " " reg "1, [%2]\n", \ |
| 203 | alt_instr " " reg "1, [%2]\n", feature) \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 204 | "2:\n" \ |
| 205 | " .section .fixup, \"ax\"\n" \ |
| 206 | " .align 2\n" \ |
| 207 | "3: mov %w0, %3\n" \ |
| 208 | " mov %1, #0\n" \ |
| 209 | " b 2b\n" \ |
| 210 | " .previous\n" \ |
Ard Biesheuvel | 6c94f27 | 2016-01-01 15:02:12 +0100 | [diff] [blame] | 211 | _ASM_EXTABLE(1b, 3b) \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 212 | : "+r" (err), "=&r" (x) \ |
| 213 | : "r" (addr), "i" (-EFAULT)) |
| 214 | |
| 215 | #define __get_user_err(x, ptr, err) \ |
| 216 | do { \ |
| 217 | unsigned long __gu_val; \ |
| 218 | __chk_user_ptr(ptr); \ |
Catalin Marinas | bd38967 | 2016-07-01 14:58:21 +0100 | [diff] [blame] | 219 | uaccess_enable_not_uao(); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 220 | switch (sizeof(*(ptr))) { \ |
| 221 | case 1: \ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 222 | __get_user_asm("ldrb", "ldtrb", "%w", __gu_val, (ptr), \ |
| 223 | (err), ARM64_HAS_UAO); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 224 | break; \ |
| 225 | case 2: \ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 226 | __get_user_asm("ldrh", "ldtrh", "%w", __gu_val, (ptr), \ |
| 227 | (err), ARM64_HAS_UAO); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 228 | break; \ |
| 229 | case 4: \ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 230 | __get_user_asm("ldr", "ldtr", "%w", __gu_val, (ptr), \ |
| 231 | (err), ARM64_HAS_UAO); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 232 | break; \ |
| 233 | case 8: \ |
Mark Rutland | d135b8b | 2017-05-03 16:09:38 +0100 | [diff] [blame] | 234 | __get_user_asm("ldr", "ldtr", "%x", __gu_val, (ptr), \ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 235 | (err), ARM64_HAS_UAO); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 236 | break; \ |
| 237 | default: \ |
| 238 | BUILD_BUG(); \ |
| 239 | } \ |
Catalin Marinas | bd38967 | 2016-07-01 14:58:21 +0100 | [diff] [blame] | 240 | uaccess_disable_not_uao(); \ |
Michael S. Tsirkin | 58fff51 | 2014-12-12 01:56:04 +0200 | [diff] [blame] | 241 | (x) = (__force __typeof__(*(ptr)))__gu_val; \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 242 | } while (0) |
| 243 | |
| 244 | #define __get_user(x, ptr) \ |
| 245 | ({ \ |
| 246 | int __gu_err = 0; \ |
| 247 | __get_user_err((x), (ptr), __gu_err); \ |
| 248 | __gu_err; \ |
| 249 | }) |
| 250 | |
| 251 | #define __get_user_error(x, ptr, err) \ |
| 252 | ({ \ |
| 253 | __get_user_err((x), (ptr), (err)); \ |
| 254 | (void)0; \ |
| 255 | }) |
| 256 | |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 257 | #define get_user(x, ptr) \ |
| 258 | ({ \ |
AKASHI Takahiro | 1f65c13 | 2013-09-24 10:00:50 +0100 | [diff] [blame] | 259 | __typeof__(*(ptr)) __user *__p = (ptr); \ |
Michael S. Tsirkin | 56d2ef7 | 2013-05-26 17:30:42 +0300 | [diff] [blame] | 260 | might_fault(); \ |
AKASHI Takahiro | 1f65c13 | 2013-09-24 10:00:50 +0100 | [diff] [blame] | 261 | access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \ |
| 262 | __get_user((x), __p) : \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 263 | ((x) = 0, -EFAULT); \ |
| 264 | }) |
| 265 | |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 266 | #define __put_user_asm(instr, alt_instr, reg, x, addr, err, feature) \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 267 | asm volatile( \ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 268 | "1:"ALTERNATIVE(instr " " reg "1, [%2]\n", \ |
| 269 | alt_instr " " reg "1, [%2]\n", feature) \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 270 | "2:\n" \ |
| 271 | " .section .fixup,\"ax\"\n" \ |
| 272 | " .align 2\n" \ |
| 273 | "3: mov %w0, %3\n" \ |
| 274 | " b 2b\n" \ |
| 275 | " .previous\n" \ |
Ard Biesheuvel | 6c94f27 | 2016-01-01 15:02:12 +0100 | [diff] [blame] | 276 | _ASM_EXTABLE(1b, 3b) \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 277 | : "+r" (err) \ |
| 278 | : "r" (x), "r" (addr), "i" (-EFAULT)) |
| 279 | |
| 280 | #define __put_user_err(x, ptr, err) \ |
| 281 | do { \ |
| 282 | __typeof__(*(ptr)) __pu_val = (x); \ |
| 283 | __chk_user_ptr(ptr); \ |
Catalin Marinas | bd38967 | 2016-07-01 14:58:21 +0100 | [diff] [blame] | 284 | uaccess_enable_not_uao(); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 285 | switch (sizeof(*(ptr))) { \ |
| 286 | case 1: \ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 287 | __put_user_asm("strb", "sttrb", "%w", __pu_val, (ptr), \ |
| 288 | (err), ARM64_HAS_UAO); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 289 | break; \ |
| 290 | case 2: \ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 291 | __put_user_asm("strh", "sttrh", "%w", __pu_val, (ptr), \ |
| 292 | (err), ARM64_HAS_UAO); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 293 | break; \ |
| 294 | case 4: \ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 295 | __put_user_asm("str", "sttr", "%w", __pu_val, (ptr), \ |
| 296 | (err), ARM64_HAS_UAO); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 297 | break; \ |
| 298 | case 8: \ |
Mark Rutland | d135b8b | 2017-05-03 16:09:38 +0100 | [diff] [blame] | 299 | __put_user_asm("str", "sttr", "%x", __pu_val, (ptr), \ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 300 | (err), ARM64_HAS_UAO); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 301 | break; \ |
| 302 | default: \ |
| 303 | BUILD_BUG(); \ |
| 304 | } \ |
Catalin Marinas | bd38967 | 2016-07-01 14:58:21 +0100 | [diff] [blame] | 305 | uaccess_disable_not_uao(); \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 306 | } while (0) |
| 307 | |
| 308 | #define __put_user(x, ptr) \ |
| 309 | ({ \ |
| 310 | int __pu_err = 0; \ |
| 311 | __put_user_err((x), (ptr), __pu_err); \ |
| 312 | __pu_err; \ |
| 313 | }) |
| 314 | |
| 315 | #define __put_user_error(x, ptr, err) \ |
| 316 | ({ \ |
| 317 | __put_user_err((x), (ptr), (err)); \ |
| 318 | (void)0; \ |
| 319 | }) |
| 320 | |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 321 | #define put_user(x, ptr) \ |
| 322 | ({ \ |
AKASHI Takahiro | 1f65c13 | 2013-09-24 10:00:50 +0100 | [diff] [blame] | 323 | __typeof__(*(ptr)) __user *__p = (ptr); \ |
Michael S. Tsirkin | 56d2ef7 | 2013-05-26 17:30:42 +0300 | [diff] [blame] | 324 | might_fault(); \ |
AKASHI Takahiro | 1f65c13 | 2013-09-24 10:00:50 +0100 | [diff] [blame] | 325 | access_ok(VERIFY_WRITE, __p, sizeof(*__p)) ? \ |
| 326 | __put_user((x), __p) : \ |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 327 | -EFAULT; \ |
| 328 | }) |
| 329 | |
Yang Shi | bffe1ba | 2016-06-08 14:40:56 -0700 | [diff] [blame] | 330 | extern unsigned long __must_check __arch_copy_from_user(void *to, const void __user *from, unsigned long n); |
Al Viro | 92430da | 2017-03-21 08:40:57 -0400 | [diff] [blame] | 331 | #define raw_copy_from_user __arch_copy_from_user |
Yang Shi | bffe1ba | 2016-06-08 14:40:56 -0700 | [diff] [blame] | 332 | extern unsigned long __must_check __arch_copy_to_user(void __user *to, const void *from, unsigned long n); |
Al Viro | 92430da | 2017-03-21 08:40:57 -0400 | [diff] [blame] | 333 | #define raw_copy_to_user __arch_copy_to_user |
| 334 | extern unsigned long __must_check raw_copy_in_user(void __user *to, const void __user *from, unsigned long n); |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 335 | extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n); |
Al Viro | 92430da | 2017-03-21 08:40:57 -0400 | [diff] [blame] | 336 | #define INLINE_COPY_TO_USER |
| 337 | #define INLINE_COPY_FROM_USER |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 338 | |
| 339 | static inline unsigned long __must_check clear_user(void __user *to, unsigned long n) |
| 340 | { |
| 341 | if (access_ok(VERIFY_WRITE, to, n)) |
| 342 | n = __clear_user(to, n); |
| 343 | return n; |
| 344 | } |
| 345 | |
Will Deacon | 12a0ef7 | 2013-11-06 17:20:22 +0000 | [diff] [blame] | 346 | extern long strncpy_from_user(char *dest, const char __user *src, long count); |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 347 | |
Will Deacon | 12a0ef7 | 2013-11-06 17:20:22 +0000 | [diff] [blame] | 348 | extern __must_check long strnlen_user(const char __user *str, long n); |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 349 | |
Catalin Marinas | 0aea86a | 2012-03-05 11:49:32 +0000 | [diff] [blame] | 350 | #endif /* __ASM_UACCESS_H */ |