Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arch: remove compat_alloc_user_space

All users of compat_alloc_user_space() and copy_in_user() have been
removed from the kernel, only a few functions in sparc remain that can be
changed to calling arch_copy_in_user() instead.

Link: https://lkml.kernel.org/r/20210727144859.4150043-7-arnd@kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Feng Tang <feng.tang@intel.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Helge Deller <deller@gmx.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Arnd Bergmann and committed by
Linus Torvalds
a7a08b27 59ab844e

+12 -333
-5
arch/arm64/include/asm/compat.h
··· 107 107 #define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current))) 108 108 #define COMPAT_MINSIGSTKSZ 2048 109 109 110 - static inline void __user *arch_compat_alloc_user_space(long len) 111 - { 112 - return (void __user *)compat_user_stack_pointer() - len; 113 - } 114 - 115 110 struct compat_ipc64_perm { 116 111 compat_key_t key; 117 112 __compat_uid32_t uid;
-11
arch/arm64/include/asm/uaccess.h
··· 430 430 __actu_ret; \ 431 431 }) 432 432 433 - extern unsigned long __must_check __arch_copy_in_user(void __user *to, const void __user *from, unsigned long n); 434 - #define raw_copy_in_user(to, from, n) \ 435 - ({ \ 436 - unsigned long __aciu_ret; \ 437 - uaccess_ttbr0_enable(); \ 438 - __aciu_ret = __arch_copy_in_user(__uaccess_mask_ptr(to), \ 439 - __uaccess_mask_ptr(from), (n)); \ 440 - uaccess_ttbr0_disable(); \ 441 - __aciu_ret; \ 442 - }) 443 - 444 433 #define INLINE_COPY_TO_USER 445 434 #define INLINE_COPY_FROM_USER 446 435
+1 -1
arch/arm64/lib/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 lib-y := clear_user.o delay.o copy_from_user.o \ 3 - copy_to_user.o copy_in_user.o copy_page.o \ 3 + copy_to_user.o copy_page.o \ 4 4 clear_page.o csum.o insn.o memchr.o memcpy.o \ 5 5 memset.o memcmp.o strcmp.o strncmp.o strlen.o \ 6 6 strnlen.o strchr.o strrchr.o tishift.o
-77
arch/arm64/lib/copy_in_user.S
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copy from user space to user space 4 - * 5 - * Copyright (C) 2012 ARM Ltd. 6 - */ 7 - 8 - #include <linux/linkage.h> 9 - 10 - #include <asm/asm-uaccess.h> 11 - #include <asm/assembler.h> 12 - #include <asm/cache.h> 13 - 14 - /* 15 - * Copy from user space to user space (alignment handled by the hardware) 16 - * 17 - * Parameters: 18 - * x0 - to 19 - * x1 - from 20 - * x2 - n 21 - * Returns: 22 - * x0 - bytes not copied 23 - */ 24 - .macro ldrb1 reg, ptr, val 25 - user_ldst 9998f, ldtrb, \reg, \ptr, \val 26 - .endm 27 - 28 - .macro strb1 reg, ptr, val 29 - user_ldst 9998f, sttrb, \reg, \ptr, \val 30 - .endm 31 - 32 - .macro ldrh1 reg, ptr, val 33 - user_ldst 9997f, ldtrh, \reg, \ptr, \val 34 - .endm 35 - 36 - .macro strh1 reg, ptr, val 37 - user_ldst 9997f, sttrh, \reg, \ptr, \val 38 - .endm 39 - 40 - .macro ldr1 reg, ptr, val 41 - user_ldst 9997f, ldtr, \reg, \ptr, \val 42 - .endm 43 - 44 - .macro str1 reg, ptr, val 45 - user_ldst 9997f, sttr, \reg, \ptr, \val 46 - .endm 47 - 48 - .macro ldp1 reg1, reg2, ptr, val 49 - user_ldp 9997f, \reg1, \reg2, \ptr, \val 50 - .endm 51 - 52 - .macro stp1 reg1, reg2, ptr, val 53 - user_stp 9997f, \reg1, \reg2, \ptr, \val 54 - .endm 55 - 56 - end .req x5 57 - srcin .req x15 58 - SYM_FUNC_START(__arch_copy_in_user) 59 - add end, x0, x2 60 - mov srcin, x1 61 - #include "copy_template.S" 62 - mov x0, #0 63 - ret 64 - SYM_FUNC_END(__arch_copy_in_user) 65 - EXPORT_SYMBOL(__arch_copy_in_user) 66 - 67 - .section .fixup,"ax" 68 - .align 2 69 - 9997: cmp dst, dstin 70 - b.ne 9998f 71 - // Before being absolutely sure we couldn't copy anything, try harder 72 - USER(9998f, ldtrb tmp1w, [srcin]) 73 - USER(9998f, sttrb tmp1w, [dst]) 74 - add dst, dst, #1 75 - 9998: sub x0, end, dst // bytes not copied 76 - ret 77 - .previous
-2
arch/mips/cavium-octeon/octeon-memcpy.S
··· 154 154 EXPORT_SYMBOL(__raw_copy_from_user) 155 155 FEXPORT(__raw_copy_to_user) 156 156 EXPORT_SYMBOL(__raw_copy_to_user) 157 - FEXPORT(__raw_copy_in_user) 158 - EXPORT_SYMBOL(__raw_copy_in_user) 159 157 /* 160 158 * Note: dst & src may be unaligned, len may be 0 161 159 * Temps
-8
arch/mips/include/asm/compat.h
··· 96 96 97 97 #define COMPAT_OFF_T_MAX 0x7fffffff 98 98 99 - static inline void __user *arch_compat_alloc_user_space(long len) 100 - { 101 - struct pt_regs *regs = (struct pt_regs *) 102 - ((unsigned long) current_thread_info() + THREAD_SIZE - 32) - 1; 103 - 104 - return (void __user *) (regs->regs[29] - len); 105 - } 106 - 107 99 struct compat_ipc64_perm { 108 100 compat_key_t key; 109 101 __compat_uid32_t uid;
-26
arch/mips/include/asm/uaccess.h
··· 428 428 429 429 extern size_t __raw_copy_from_user(void *__to, const void *__from, size_t __n); 430 430 extern size_t __raw_copy_to_user(void *__to, const void *__from, size_t __n); 431 - extern size_t __raw_copy_in_user(void *__to, const void *__from, size_t __n); 432 431 433 432 static inline unsigned long 434 433 raw_copy_from_user(void *to, const void __user *from, unsigned long n) ··· 478 479 479 480 #define INLINE_COPY_FROM_USER 480 481 #define INLINE_COPY_TO_USER 481 - 482 - static inline unsigned long 483 - raw_copy_in_user(void __user *to, const void __user *from, unsigned long n) 484 - { 485 - register void __user *__cu_to_r __asm__("$4"); 486 - register const void __user *__cu_from_r __asm__("$5"); 487 - register long __cu_len_r __asm__("$6"); 488 - 489 - __cu_to_r = to; 490 - __cu_from_r = from; 491 - __cu_len_r = n; 492 - 493 - __asm__ __volatile__( 494 - ".set\tnoreorder\n\t" 495 - __MODULE_JAL(__raw_copy_in_user) 496 - ".set\tnoat\n\t" 497 - __UA_ADDU "\t$1, %1, %2\n\t" 498 - ".set\tat\n\t" 499 - ".set\treorder" 500 - : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) 501 - : 502 - : "$8", "$9", "$10", "$11", "$12", "$14", "$15", "$24", "$31", 503 - DADDI_SCRATCH, "memory"); 504 - return __cu_len_r; 505 - } 506 482 507 483 extern __kernel_size_t __bzero(void __user *addr, __kernel_size_t size); 508 484
-11
arch/mips/lib/memcpy.S
··· 666 666 EXPORT_SYMBOL(__raw_copy_from_user) 667 667 FEXPORT(__raw_copy_to_user) 668 668 EXPORT_SYMBOL(__raw_copy_to_user) 669 - FEXPORT(__raw_copy_in_user) 670 - EXPORT_SYMBOL(__raw_copy_in_user) 671 669 #endif 672 670 /* Legacy Mode, user <-> user */ 673 671 __BUILD_COPY_USER LEGACY_MODE USEROP USEROP ··· 700 702 EXPORT_SYMBOL(__raw_copy_to_user) 701 703 __BUILD_COPY_USER EVA_MODE KERNELOP USEROP 702 704 END(__raw_copy_to_user) 703 - 704 - /* 705 - * __copy_in_user (EVA) 706 - */ 707 - 708 - LEAF(__raw_copy_in_user) 709 - EXPORT_SYMBOL(__raw_copy_in_user) 710 - __BUILD_COPY_USER EVA_MODE USEROP USEROP 711 - END(__raw_copy_in_user) 712 705 713 706 #endif
-6
arch/parisc/include/asm/compat.h
··· 163 163 #define COMPAT_ELF_NGREG 80 164 164 typedef compat_ulong_t compat_elf_gregset_t[COMPAT_ELF_NGREG]; 165 165 166 - static __inline__ void __user *arch_compat_alloc_user_space(long len) 167 - { 168 - struct pt_regs *regs = &current->thread.regs; 169 - return (void __user *)regs->gr[30]; 170 - } 171 - 172 166 static inline int __is_compat_task(struct task_struct *t) 173 167 { 174 168 return test_tsk_thread_flag(t, TIF_32BIT);
-2
arch/parisc/include/asm/uaccess.h
··· 215 215 unsigned long len); 216 216 unsigned long __must_check raw_copy_from_user(void *dst, const void __user *src, 217 217 unsigned long len); 218 - unsigned long __must_check raw_copy_in_user(void __user *dst, const void __user *src, 219 - unsigned long len); 220 218 #define INLINE_COPY_TO_USER 221 219 #define INLINE_COPY_FROM_USER 222 220
-9
arch/parisc/lib/memcpy.c
··· 38 38 } 39 39 EXPORT_SYMBOL(raw_copy_from_user); 40 40 41 - unsigned long raw_copy_in_user(void __user *dst, const void __user *src, unsigned long len) 42 - { 43 - mtsp(get_user_space(), 1); 44 - mtsp(get_user_space(), 2); 45 - return pa_memcpy((void __force *)dst, (void __force *)src, len); 46 - } 47 - 48 - 49 41 void * memcpy(void * dst,const void *src, size_t count) 50 42 { 51 43 mtsp(get_kernel_space(), 1); ··· 46 54 return dst; 47 55 } 48 56 49 - EXPORT_SYMBOL(raw_copy_in_user); 50 57 EXPORT_SYMBOL(memcpy); 51 58 52 59 bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
-16
arch/powerpc/include/asm/compat.h
··· 83 83 84 84 #define COMPAT_OFF_T_MAX 0x7fffffff 85 85 86 - static inline void __user *arch_compat_alloc_user_space(long len) 87 - { 88 - struct pt_regs *regs = current->thread.regs; 89 - unsigned long usp = regs->gpr[1]; 90 - 91 - /* 92 - * We can't access below the stack pointer in the 32bit ABI and 93 - * can access 288 bytes in the 64bit big-endian ABI, 94 - * or 512 bytes with the new ELFv2 little-endian ABI. 95 - */ 96 - if (!is_32bit_task()) 97 - usp -= USER_REDZONE_SIZE; 98 - 99 - return (void __user *) (usp - len); 100 - } 101 - 102 86 /* 103 87 * ipc64_perm is actually 32/64bit clean but since the compat layer refers to 104 88 * it we may as well define it.
-10
arch/s390/include/asm/compat.h
··· 176 176 return test_thread_flag(TIF_31BIT); 177 177 } 178 178 179 - static inline void __user *arch_compat_alloc_user_space(long len) 180 - { 181 - unsigned long stack; 182 - 183 - stack = KSTK_ESP(current); 184 - if (is_compat_task()) 185 - stack &= 0x7fffffffUL; 186 - return (void __user *) (stack - len); 187 - } 188 - 189 179 #endif 190 180 191 181 struct compat_ipc64_perm {
-3
arch/s390/include/asm/uaccess.h
··· 227 227 __get_user(x, ptr); \ 228 228 }) 229 229 230 - unsigned long __must_check 231 - raw_copy_in_user(void __user *to, const void __user *from, unsigned long n); 232 - 233 230 /* 234 231 * Copy a null terminated string from userspace. 235 232 */
-63
arch/s390/lib/uaccess.c
··· 204 204 } 205 205 EXPORT_SYMBOL(raw_copy_to_user); 206 206 207 - static inline unsigned long copy_in_user_mvcos(void __user *to, const void __user *from, 208 - unsigned long size) 209 - { 210 - unsigned long tmp1, tmp2; 211 - 212 - tmp1 = -4096UL; 213 - /* FIXME: copy with reduced length. */ 214 - asm volatile( 215 - " lgr 0,%[spec]\n" 216 - "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n" 217 - " jz 2f\n" 218 - "1: algr %0,%3\n" 219 - " slgr %1,%3\n" 220 - " slgr %2,%3\n" 221 - " j 0b\n" 222 - "2:slgr %0,%0\n" 223 - "3: \n" 224 - EX_TABLE(0b,3b) 225 - : "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2) 226 - : [spec] "d" (0x810081UL) 227 - : "cc", "memory", "0"); 228 - return size; 229 - } 230 - 231 - static inline unsigned long copy_in_user_mvc(void __user *to, const void __user *from, 232 - unsigned long size) 233 - { 234 - unsigned long tmp1; 235 - 236 - asm volatile( 237 - " sacf 256\n" 238 - " aghi %0,-1\n" 239 - " jo 5f\n" 240 - " bras %3,3f\n" 241 - "0: aghi %0,257\n" 242 - "1: mvc 0(1,%1),0(%2)\n" 243 - " la %1,1(%1)\n" 244 - " la %2,1(%2)\n" 245 - " aghi %0,-1\n" 246 - " jnz 1b\n" 247 - " j 5f\n" 248 - "2: mvc 0(256,%1),0(%2)\n" 249 - " la %1,256(%1)\n" 250 - " la %2,256(%2)\n" 251 - "3: aghi %0,-256\n" 252 - " jnm 2b\n" 253 - "4: ex %0,1b-0b(%3)\n" 254 - "5: slgr %0,%0\n" 255 - "6: sacf 768\n" 256 - EX_TABLE(1b,6b) EX_TABLE(2b,0b) EX_TABLE(4b,0b) 257 - : "+a" (size), "+a" (to), "+a" (from), "=a" (tmp1) 258 - : : "cc", "memory"); 259 - return size; 260 - } 261 - 262 - unsigned long raw_copy_in_user(void __user *to, const void __user *from, unsigned long n) 263 - { 264 - if (copy_with_mvcos()) 265 - return copy_in_user_mvcos(to, from, n); 266 - return copy_in_user_mvc(to, from, n); 267 - } 268 - EXPORT_SYMBOL(raw_copy_in_user); 269 - 270 207 static inline unsigned long clear_user_mvcos(void __user *to, unsigned long size) 271 208 { 272 209 unsigned long tmp1, tmp2;
-19
arch/sparc/include/asm/compat.h
··· 116 116 117 117 #define COMPAT_OFF_T_MAX 0x7fffffff 118 118 119 - #ifdef CONFIG_COMPAT 120 - static inline void __user *arch_compat_alloc_user_space(long len) 121 - { 122 - struct pt_regs *regs = current_thread_info()->kregs; 123 - unsigned long usp = regs->u_regs[UREG_I6]; 124 - 125 - if (test_thread_64bit_stack(usp)) 126 - usp += STACK_BIAS; 127 - 128 - if (test_thread_flag(TIF_32BIT)) 129 - usp &= 0xffffffffUL; 130 - 131 - usp -= len; 132 - usp &= ~0x7UL; 133 - 134 - return (void __user *) usp; 135 - } 136 - #endif 137 - 138 119 struct compat_ipc64_perm { 139 120 compat_key_t key; 140 121 __compat_uid32_t uid;
+1 -1
arch/sparc/kernel/process_64.c
··· 455 455 456 456 distance = fp - psp; 457 457 rval = (csp - distance); 458 - if (copy_in_user((void __user *) rval, (void __user *) psp, distance)) 458 + if (raw_copy_in_user((void __user *)rval, (void __user *)psp, distance)) 459 459 rval = 0; 460 460 else if (!stack_64bit) { 461 461 if (put_user(((u32)csp),
+6 -6
arch/sparc/kernel/signal32.c
··· 435 435 (_COMPAT_NSIG_WORDS - 1) * sizeof(unsigned int)); 436 436 437 437 if (!wsaved) { 438 - err |= copy_in_user((u32 __user *)sf, 439 - (u32 __user *)(regs->u_regs[UREG_FP]), 440 - sizeof(struct reg_window32)); 438 + err |= raw_copy_in_user((u32 __user *)sf, 439 + (u32 __user *)(regs->u_regs[UREG_FP]), 440 + sizeof(struct reg_window32)); 441 441 } else { 442 442 struct reg_window *rp; 443 443 ··· 567 567 err |= put_compat_sigset(&sf->mask, oldset, sizeof(compat_sigset_t)); 568 568 569 569 if (!wsaved) { 570 - err |= copy_in_user((u32 __user *)sf, 571 - (u32 __user *)(regs->u_regs[UREG_FP]), 572 - sizeof(struct reg_window32)); 570 + err |= raw_copy_in_user((u32 __user *)sf, 571 + (u32 __user *)(regs->u_regs[UREG_FP]), 572 + sizeof(struct reg_window32)); 573 573 } else { 574 574 struct reg_window *rp; 575 575
+4 -4
arch/sparc/kernel/signal_64.c
··· 406 406 err |= copy_to_user(&sf->mask, sigmask_to_save(), sizeof(sigset_t)); 407 407 408 408 if (!wsaved) { 409 - err |= copy_in_user((u64 __user *)sf, 410 - (u64 __user *)(regs->u_regs[UREG_FP] + 411 - STACK_BIAS), 412 - sizeof(struct reg_window)); 409 + err |= raw_copy_in_user((u64 __user *)sf, 410 + (u64 __user *)(regs->u_regs[UREG_FP] + 411 + STACK_BIAS), 412 + sizeof(struct reg_window)); 413 413 } else { 414 414 struct reg_window *rp; 415 415
-13
arch/x86/include/asm/compat.h
··· 156 156 (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)) 157 157 #endif 158 158 159 - static inline void __user *arch_compat_alloc_user_space(long len) 160 - { 161 - compat_uptr_t sp = task_pt_regs(current)->sp; 162 - 163 - /* 164 - * -128 for the x32 ABI redzone. For IA32, it is not strictly 165 - * necessary, but not harmful. 166 - */ 167 - sp -= 128; 168 - 169 - return (void __user *)round_down(sp - len, 16); 170 - } 171 - 172 159 static inline bool in_x32_syscall(void) 173 160 { 174 161 #ifdef CONFIG_X86_X32_ABI
-7
arch/x86/include/asm/uaccess_64.h
··· 58 58 return copy_user_generic((__force void *)dst, src, size); 59 59 } 60 60 61 - static __always_inline __must_check 62 - unsigned long raw_copy_in_user(void __user *dst, const void __user *src, unsigned long size) 63 - { 64 - return copy_user_generic((__force void *)dst, 65 - (__force void *)src, size); 66 - } 67 - 68 61 extern long __copy_user_nocache(void *dst, const void __user *src, 69 62 unsigned size, int zerorest); 70 63
-2
include/linux/compat.h
··· 511 511 512 512 struct epoll_event; /* fortunately, this one is fixed-layout */ 513 513 514 - extern void __user *compat_alloc_user_space(unsigned long len); 515 - 516 514 int compat_restore_altstack(const compat_stack_t __user *uss); 517 515 int __compat_save_altstack(compat_stack_t __user *, unsigned long); 518 516 #define unsafe_compat_save_altstack(uss, sp, label) do { \
-10
include/linux/uaccess.h
··· 200 200 n = _copy_to_user(to, from, n); 201 201 return n; 202 202 } 203 - #ifdef CONFIG_COMPAT 204 - static __always_inline unsigned long __must_check 205 - copy_in_user(void __user *to, const void __user *from, unsigned long n) 206 - { 207 - might_fault(); 208 - if (access_ok(to, n) && access_ok(from, n)) 209 - n = raw_copy_in_user(to, from, n); 210 - return n; 211 - } 212 - #endif 213 203 214 204 #ifndef copy_mc_to_kernel 215 205 /*
-21
kernel/compat.c
··· 269 269 return 0; 270 270 } 271 271 EXPORT_SYMBOL_GPL(get_compat_sigset); 272 - 273 - /* 274 - * Allocate user-space memory for the duration of a single system call, 275 - * in order to marshall parameters inside a compat thunk. 276 - */ 277 - void __user *compat_alloc_user_space(unsigned long len) 278 - { 279 - void __user *ptr; 280 - 281 - /* If len would occupy more than half of the entire compat space... */ 282 - if (unlikely(len > (((compat_uptr_t)~0) >> 1))) 283 - return NULL; 284 - 285 - ptr = arch_compat_alloc_user_space(len); 286 - 287 - if (unlikely(!access_ok(ptr, len))) 288 - return NULL; 289 - 290 - return ptr; 291 - } 292 - EXPORT_SYMBOL_GPL(compat_alloc_user_space);