2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 03, 04 by Ralf Baechle
|
|
|
|
* Copyright (C) 1999, 2000 Silicon Graphics, Inc.
|
2007-10-23 12:43:25 +01:00
|
|
|
* Copyright (C) 2007 Maciej W. Rozycki
|
2013-12-11 11:25:33 +00:00
|
|
|
* Copyright (C) 2014, Imagination Technologies Ltd.
|
2005-04-16 15:20:36 -07:00
|
|
|
*/
|
|
|
|
#ifndef _ASM_UACCESS_H
|
|
|
|
#define _ASM_UACCESS_H
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2016-08-20 16:18:53 -04:00
|
|
|
#include <linux/string.h>
|
2013-12-11 11:25:33 +00:00
|
|
|
#include <asm/asm-eva.h>
|
2016-09-05 11:35:50 -04:00
|
|
|
#include <asm/extable.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-09-03 15:56:16 -07:00
|
|
|
#ifdef CONFIG_32BIT
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2012-11-21 18:34:03 -08:00
|
|
|
#define __UA_LIMIT 0x80000000UL
|
2022-02-14 14:50:29 +01:00
|
|
|
#define TASK_SIZE_MAX KSEG0
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
#define __UA_ADDR ".word"
|
|
|
|
#define __UA_LA "la"
|
|
|
|
#define __UA_ADDU "addu"
|
|
|
|
#define __UA_t0 "$8"
|
|
|
|
#define __UA_t1 "$9"
|
|
|
|
|
2005-09-03 15:56:16 -07:00
|
|
|
#endif /* CONFIG_32BIT */
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-09-03 15:56:16 -07:00
|
|
|
#ifdef CONFIG_64BIT
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2010-10-14 11:32:33 -07:00
|
|
|
extern u64 __ua_limit;
|
|
|
|
|
|
|
|
#define __UA_LIMIT __ua_limit
|
2022-02-14 14:50:29 +01:00
|
|
|
#define TASK_SIZE_MAX XKSSEG
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
#define __UA_ADDR ".dword"
|
|
|
|
#define __UA_LA "dla"
|
|
|
|
#define __UA_ADDU "daddu"
|
|
|
|
#define __UA_t0 "$12"
|
|
|
|
#define __UA_t1 "$13"
|
|
|
|
|
2005-09-03 15:56:16 -07:00
|
|
|
#endif /* CONFIG_64BIT */
|
2005-04-16 15:20:36 -07:00
|
|
|
|
uaccess: generalize access_ok()
There are many different ways that access_ok() is defined across
architectures, but in the end, they all just compare against the
user_addr_max() value or they accept anything.
Provide one definition that works for most architectures, checking
against TASK_SIZE_MAX for user processes or skipping the check inside
of uaccess_kernel() sections.
For architectures without CONFIG_SET_FS(), this should be the fastest
check, as it comes down to a single comparison of a pointer against a
compile-time constant, while the architecture specific versions tend to
do something more complex for historic reasons or get something wrong.
Type checking for __user annotations is handled inconsistently across
architectures, but this is easily simplified as well by using an inline
function that takes a 'const void __user *' argument. A handful of
callers need an extra __user annotation for this.
Some architectures had trick to use 33-bit or 65-bit arithmetic on the
addresses to calculate the overflow, however this simpler version uses
fewer registers, which means it can produce better object code in the
end despite needing a second (statically predicted) branch.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Mark Rutland <mark.rutland@arm.com> [arm64, asm-generic]
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Stafford Horne <shorne@gmail.com>
Acked-by: Dinh Nguyen <dinguyen@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2022-02-15 17:55:04 +01:00
|
|
|
#include <asm-generic/access_ok.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* put_user: - Write a simple value into user space.
|
2013-01-22 12:59:30 +01:00
|
|
|
* @x: Value to copy to user space.
|
2005-04-16 15:20:36 -07:00
|
|
|
* @ptr: Destination address, in user space.
|
|
|
|
*
|
2015-05-11 17:52:08 +02:00
|
|
|
* Context: User context only. This function may sleep if pagefaults are
|
|
|
|
* enabled.
|
2005-04-16 15:20:36 -07:00
|
|
|
*
|
|
|
|
* This macro copies a single simple value from kernel space to user
|
|
|
|
* space. It supports simple types like char and int, but not larger
|
|
|
|
* data types like structures or arrays.
|
|
|
|
*
|
|
|
|
* @ptr must have pointer-to-simple-variable type, and @x must be assignable
|
|
|
|
* to the result of dereferencing @ptr.
|
|
|
|
*
|
|
|
|
* Returns zero on success, or -EFAULT on error.
|
|
|
|
*/
|
2021-04-08 20:14:37 +02:00
|
|
|
#define put_user(x, ptr) \
|
|
|
|
({ \
|
|
|
|
__typeof__(*(ptr)) __user *__p = (ptr); \
|
|
|
|
\
|
|
|
|
might_fault(); \
|
|
|
|
access_ok(__p, sizeof(*__p)) ? __put_user((x), __p) : -EFAULT; \
|
|
|
|
})
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* get_user: - Get a simple variable from user space.
|
2013-01-22 12:59:30 +01:00
|
|
|
* @x: Variable to store result.
|
2005-04-16 15:20:36 -07:00
|
|
|
* @ptr: Source address, in user space.
|
|
|
|
*
|
2015-05-11 17:52:08 +02:00
|
|
|
* Context: User context only. This function may sleep if pagefaults are
|
|
|
|
* enabled.
|
2005-04-16 15:20:36 -07:00
|
|
|
*
|
|
|
|
* This macro copies a single simple variable from user space to kernel
|
|
|
|
* space. It supports simple types like char and int, but not larger
|
|
|
|
* data types like structures or arrays.
|
|
|
|
*
|
|
|
|
* @ptr must have pointer-to-simple-variable type, and the result of
|
|
|
|
* dereferencing @ptr must be assignable to @x without a cast.
|
|
|
|
*
|
|
|
|
* Returns zero on success, or -EFAULT on error.
|
|
|
|
* On error, the variable @x is set to zero.
|
|
|
|
*/
|
2021-04-08 20:14:37 +02:00
|
|
|
#define get_user(x, ptr) \
|
|
|
|
({ \
|
|
|
|
const __typeof__(*(ptr)) __user *__p = (ptr); \
|
|
|
|
\
|
|
|
|
might_fault(); \
|
|
|
|
access_ok(__p, sizeof(*__p)) ? __get_user((x), __p) : \
|
|
|
|
((x) = 0, -EFAULT); \
|
|
|
|
})
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* __put_user: - Write a simple value into user space, with less checking.
|
2013-01-22 12:59:30 +01:00
|
|
|
* @x: Value to copy to user space.
|
2005-04-16 15:20:36 -07:00
|
|
|
* @ptr: Destination address, in user space.
|
|
|
|
*
|
2015-05-11 17:52:08 +02:00
|
|
|
* Context: User context only. This function may sleep if pagefaults are
|
|
|
|
* enabled.
|
2005-04-16 15:20:36 -07:00
|
|
|
*
|
|
|
|
* This macro copies a single simple value from kernel space to user
|
|
|
|
* space. It supports simple types like char and int, but not larger
|
|
|
|
* data types like structures or arrays.
|
|
|
|
*
|
|
|
|
* @ptr must have pointer-to-simple-variable type, and @x must be assignable
|
|
|
|
* to the result of dereferencing @ptr.
|
|
|
|
*
|
|
|
|
* Caller must check the pointer with access_ok() before calling this
|
|
|
|
* function.
|
|
|
|
*
|
|
|
|
* Returns zero on success, or -EFAULT on error.
|
|
|
|
*/
|
2021-04-08 20:14:37 +02:00
|
|
|
#define __put_user(x, ptr) \
|
|
|
|
({ \
|
|
|
|
__typeof__(*(ptr)) __user *__pu_ptr = (ptr); \
|
|
|
|
__typeof__(*(ptr)) __pu_val = (x); \
|
|
|
|
int __pu_err = 0; \
|
|
|
|
\
|
|
|
|
__chk_user_ptr(__pu_ptr); \
|
|
|
|
switch (sizeof(*__pu_ptr)) { \
|
|
|
|
case 1: \
|
|
|
|
__put_data_asm(user_sb, __pu_ptr); \
|
|
|
|
break; \
|
|
|
|
case 2: \
|
|
|
|
__put_data_asm(user_sh, __pu_ptr); \
|
|
|
|
break; \
|
|
|
|
case 4: \
|
|
|
|
__put_data_asm(user_sw, __pu_ptr); \
|
|
|
|
break; \
|
|
|
|
case 8: \
|
|
|
|
__PUT_DW(user_sd, __pu_ptr); \
|
|
|
|
break; \
|
|
|
|
default: \
|
|
|
|
BUILD_BUG(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
__pu_err; \
|
|
|
|
})
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* __get_user: - Get a simple variable from user space, with less checking.
|
2013-01-22 12:59:30 +01:00
|
|
|
* @x: Variable to store result.
|
2005-04-16 15:20:36 -07:00
|
|
|
* @ptr: Source address, in user space.
|
|
|
|
*
|
2015-05-11 17:52:08 +02:00
|
|
|
* Context: User context only. This function may sleep if pagefaults are
|
|
|
|
* enabled.
|
2005-04-16 15:20:36 -07:00
|
|
|
*
|
|
|
|
* This macro copies a single simple variable from user space to kernel
|
|
|
|
* space. It supports simple types like char and int, but not larger
|
|
|
|
* data types like structures or arrays.
|
|
|
|
*
|
|
|
|
* @ptr must have pointer-to-simple-variable type, and the result of
|
|
|
|
* dereferencing @ptr must be assignable to @x without a cast.
|
|
|
|
*
|
|
|
|
* Caller must check the pointer with access_ok() before calling this
|
|
|
|
* function.
|
|
|
|
*
|
|
|
|
* Returns zero on success, or -EFAULT on error.
|
|
|
|
* On error, the variable @x is set to zero.
|
|
|
|
*/
|
2021-04-08 20:14:37 +02:00
|
|
|
#define __get_user(x, ptr) \
|
|
|
|
({ \
|
|
|
|
const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
|
|
|
|
int __gu_err = 0; \
|
|
|
|
\
|
|
|
|
__chk_user_ptr(__gu_ptr); \
|
|
|
|
switch (sizeof(*__gu_ptr)) { \
|
|
|
|
case 1: \
|
|
|
|
__get_data_asm((x), user_lb, __gu_ptr); \
|
|
|
|
break; \
|
|
|
|
case 2: \
|
|
|
|
__get_data_asm((x), user_lh, __gu_ptr); \
|
|
|
|
break; \
|
|
|
|
case 4: \
|
|
|
|
__get_data_asm((x), user_lw, __gu_ptr); \
|
|
|
|
break; \
|
|
|
|
case 8: \
|
|
|
|
__GET_DW((x), user_ld, __gu_ptr); \
|
|
|
|
break; \
|
|
|
|
default: \
|
|
|
|
BUILD_BUG(); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
__gu_err; \
|
|
|
|
})
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
struct __large_struct { unsigned long buf[100]; };
|
2005-03-01 19:22:29 +00:00
|
|
|
#define __m(x) (*(struct __large_struct __user *)(x))
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-01-23 16:15:30 +00:00
|
|
|
#ifdef CONFIG_32BIT
|
2014-01-06 12:48:28 +00:00
|
|
|
#define __GET_DW(val, insn, ptr) __get_data_asm_ll32(val, insn, ptr)
|
2006-01-23 16:15:30 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_64BIT
|
2014-01-06 12:48:28 +00:00
|
|
|
#define __GET_DW(val, insn, ptr) __get_data_asm(val, insn, ptr)
|
2005-04-16 15:20:36 -07:00
|
|
|
#endif
|
|
|
|
|
2014-01-06 12:48:28 +00:00
|
|
|
#define __get_data_asm(val, insn, addr) \
|
2005-03-01 19:22:29 +00:00
|
|
|
{ \
|
2006-01-23 16:15:30 +00:00
|
|
|
long __gu_tmp; \
|
|
|
|
\
|
2005-04-16 15:20:36 -07:00
|
|
|
__asm__ __volatile__( \
|
2013-12-11 11:25:33 +00:00
|
|
|
"1: "insn("%1", "%3")" \n" \
|
2005-04-16 15:20:36 -07:00
|
|
|
"2: \n" \
|
2013-03-25 13:22:59 -05:00
|
|
|
" .insn \n" \
|
2005-04-16 15:20:36 -07:00
|
|
|
" .section .fixup,\"ax\" \n" \
|
|
|
|
"3: li %0, %4 \n" \
|
2014-11-18 18:47:13 +01:00
|
|
|
" move %1, $0 \n" \
|
2005-04-16 15:20:36 -07:00
|
|
|
" j 2b \n" \
|
|
|
|
" .previous \n" \
|
|
|
|
" .section __ex_table,\"a\" \n" \
|
|
|
|
" "__UA_ADDR "\t1b, 3b \n" \
|
|
|
|
" .previous \n" \
|
2006-01-23 16:15:30 +00:00
|
|
|
: "=r" (__gu_err), "=r" (__gu_tmp) \
|
2005-03-01 19:22:29 +00:00
|
|
|
: "0" (0), "o" (__m(addr)), "i" (-EFAULT)); \
|
2006-01-23 16:15:30 +00:00
|
|
|
\
|
2006-02-14 15:57:50 +09:00
|
|
|
(val) = (__typeof__(*(addr))) __gu_tmp; \
|
2005-03-01 19:22:29 +00:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a long long 64 using 32 bit registers.
|
|
|
|
*/
|
2014-01-06 12:48:28 +00:00
|
|
|
#define __get_data_asm_ll32(val, insn, addr) \
|
2005-03-01 19:22:29 +00:00
|
|
|
{ \
|
2007-02-13 11:45:24 +00:00
|
|
|
union { \
|
|
|
|
unsigned long long l; \
|
|
|
|
__typeof__(*(addr)) t; \
|
|
|
|
} __gu_tmp; \
|
2007-02-12 23:12:38 +00:00
|
|
|
\
|
2005-04-16 15:20:36 -07:00
|
|
|
__asm__ __volatile__( \
|
2013-12-11 11:25:33 +00:00
|
|
|
"1: " insn("%1", "(%3)")" \n" \
|
|
|
|
"2: " insn("%D1", "4(%3)")" \n" \
|
2013-03-25 13:22:59 -05:00
|
|
|
"3: \n" \
|
|
|
|
" .insn \n" \
|
|
|
|
" .section .fixup,\"ax\" \n" \
|
2005-03-01 19:22:29 +00:00
|
|
|
"4: li %0, %4 \n" \
|
2005-04-16 15:20:36 -07:00
|
|
|
" move %1, $0 \n" \
|
|
|
|
" move %D1, $0 \n" \
|
|
|
|
" j 3b \n" \
|
|
|
|
" .previous \n" \
|
|
|
|
" .section __ex_table,\"a\" \n" \
|
|
|
|
" " __UA_ADDR " 1b, 4b \n" \
|
|
|
|
" " __UA_ADDR " 2b, 4b \n" \
|
|
|
|
" .previous \n" \
|
2007-02-13 11:45:24 +00:00
|
|
|
: "=r" (__gu_err), "=&r" (__gu_tmp.l) \
|
2005-03-01 19:22:29 +00:00
|
|
|
: "0" (0), "r" (addr), "i" (-EFAULT)); \
|
2007-02-13 11:45:24 +00:00
|
|
|
\
|
|
|
|
(val) = __gu_tmp.t; \
|
2005-03-01 19:22:29 +00:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2021-04-01 14:56:35 +02:00
|
|
|
#define __get_kernel_nofault(dst, src, type, err_label) \
|
|
|
|
do { \
|
|
|
|
int __gu_err; \
|
|
|
|
\
|
2021-04-01 14:56:37 +02:00
|
|
|
switch (sizeof(type)) { \
|
|
|
|
case 1: \
|
|
|
|
__get_data_asm(*(type *)(dst), kernel_lb, \
|
|
|
|
(__force type *)(src)); \
|
|
|
|
break; \
|
|
|
|
case 2: \
|
|
|
|
__get_data_asm(*(type *)(dst), kernel_lh, \
|
|
|
|
(__force type *)(src)); \
|
|
|
|
break; \
|
|
|
|
case 4: \
|
|
|
|
__get_data_asm(*(type *)(dst), kernel_lw, \
|
|
|
|
(__force type *)(src)); \
|
|
|
|
break; \
|
|
|
|
case 8: \
|
|
|
|
__GET_DW(*(type *)(dst), kernel_ld, \
|
|
|
|
(__force type *)(src)); \
|
|
|
|
break; \
|
|
|
|
default: \
|
2021-04-08 20:14:37 +02:00
|
|
|
BUILD_BUG(); \
|
2021-04-01 14:56:37 +02:00
|
|
|
break; \
|
|
|
|
} \
|
2021-04-01 14:56:35 +02:00
|
|
|
if (unlikely(__gu_err)) \
|
|
|
|
goto err_label; \
|
|
|
|
} while (0)
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* Yuck. We need two variants, one for 64bit operation and one
|
|
|
|
* for 32 bit mode and old iron.
|
|
|
|
*/
|
2006-01-23 16:15:30 +00:00
|
|
|
#ifdef CONFIG_32BIT
|
2014-01-06 12:48:28 +00:00
|
|
|
#define __PUT_DW(insn, ptr) __put_data_asm_ll32(insn, ptr)
|
2005-04-16 15:20:36 -07:00
|
|
|
#endif
|
2006-01-23 16:15:30 +00:00
|
|
|
#ifdef CONFIG_64BIT
|
2014-01-06 12:48:28 +00:00
|
|
|
#define __PUT_DW(insn, ptr) __put_data_asm(insn, ptr)
|
2006-01-23 16:15:30 +00:00
|
|
|
#endif
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2014-01-06 12:48:28 +00:00
|
|
|
#define __put_data_asm(insn, ptr) \
|
2005-03-01 19:22:29 +00:00
|
|
|
{ \
|
2005-04-16 15:20:36 -07:00
|
|
|
__asm__ __volatile__( \
|
2014-01-06 12:48:28 +00:00
|
|
|
"1: "insn("%z2", "%3")" # __put_data_asm \n" \
|
2005-04-16 15:20:36 -07:00
|
|
|
"2: \n" \
|
2013-03-25 13:22:59 -05:00
|
|
|
" .insn \n" \
|
2005-04-16 15:20:36 -07:00
|
|
|
" .section .fixup,\"ax\" \n" \
|
|
|
|
"3: li %0, %4 \n" \
|
|
|
|
" j 2b \n" \
|
|
|
|
" .previous \n" \
|
|
|
|
" .section __ex_table,\"a\" \n" \
|
|
|
|
" " __UA_ADDR " 1b, 3b \n" \
|
|
|
|
" .previous \n" \
|
|
|
|
: "=r" (__pu_err) \
|
2005-03-01 19:22:29 +00:00
|
|
|
: "0" (0), "Jr" (__pu_val), "o" (__m(ptr)), \
|
2005-04-16 15:20:36 -07:00
|
|
|
"i" (-EFAULT)); \
|
2005-03-01 19:22:29 +00:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2014-01-06 12:48:28 +00:00
|
|
|
#define __put_data_asm_ll32(insn, ptr) \
|
2005-03-01 19:22:29 +00:00
|
|
|
{ \
|
2005-04-16 15:20:36 -07:00
|
|
|
__asm__ __volatile__( \
|
2014-01-06 12:48:28 +00:00
|
|
|
"1: "insn("%2", "(%3)")" # __put_data_asm_ll32 \n" \
|
2013-12-11 11:25:33 +00:00
|
|
|
"2: "insn("%D2", "4(%3)")" \n" \
|
2005-04-16 15:20:36 -07:00
|
|
|
"3: \n" \
|
2013-03-25 13:22:59 -05:00
|
|
|
" .insn \n" \
|
2005-04-16 15:20:36 -07:00
|
|
|
" .section .fixup,\"ax\" \n" \
|
2005-03-01 19:22:29 +00:00
|
|
|
"4: li %0, %4 \n" \
|
2005-04-16 15:20:36 -07:00
|
|
|
" j 3b \n" \
|
|
|
|
" .previous \n" \
|
|
|
|
" .section __ex_table,\"a\" \n" \
|
|
|
|
" " __UA_ADDR " 1b, 4b \n" \
|
|
|
|
" " __UA_ADDR " 2b, 4b \n" \
|
|
|
|
" .previous" \
|
|
|
|
: "=r" (__pu_err) \
|
2005-03-01 19:22:29 +00:00
|
|
|
: "0" (0), "r" (__pu_val), "r" (ptr), \
|
|
|
|
"i" (-EFAULT)); \
|
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2021-04-01 14:56:35 +02:00
|
|
|
#define __put_kernel_nofault(dst, src, type, err_label) \
|
|
|
|
do { \
|
|
|
|
type __pu_val; \
|
|
|
|
int __pu_err = 0; \
|
|
|
|
\
|
|
|
|
__pu_val = *(__force type *)(src); \
|
2021-04-01 14:56:37 +02:00
|
|
|
switch (sizeof(type)) { \
|
|
|
|
case 1: \
|
|
|
|
__put_data_asm(kernel_sb, (type *)(dst)); \
|
|
|
|
break; \
|
|
|
|
case 2: \
|
|
|
|
__put_data_asm(kernel_sh, (type *)(dst)); \
|
|
|
|
break; \
|
|
|
|
case 4: \
|
|
|
|
__put_data_asm(kernel_sw, (type *)(dst)) \
|
|
|
|
break; \
|
|
|
|
case 8: \
|
|
|
|
__PUT_DW(kernel_sd, (type *)(dst)); \
|
|
|
|
break; \
|
|
|
|
default: \
|
2021-04-08 20:14:37 +02:00
|
|
|
BUILD_BUG(); \
|
2021-04-01 14:56:37 +02:00
|
|
|
break; \
|
|
|
|
} \
|
2021-04-01 14:56:35 +02:00
|
|
|
if (unlikely(__pu_err)) \
|
|
|
|
goto err_label; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* We're generating jump to subroutines which will be outside the range of
|
|
|
|
* jump instructions
|
|
|
|
*/
|
|
|
|
#ifdef MODULE
|
|
|
|
#define __MODULE_JAL(destination) \
|
|
|
|
".set\tnoat\n\t" \
|
2013-01-22 12:59:30 +01:00
|
|
|
__UA_LA "\t$1, " #destination "\n\t" \
|
2005-04-16 15:20:36 -07:00
|
|
|
"jalr\t$1\n\t" \
|
|
|
|
".set\tat\n\t"
|
|
|
|
#else
|
|
|
|
#define __MODULE_JAL(destination) \
|
|
|
|
"jal\t" #destination "\n\t"
|
|
|
|
#endif
|
|
|
|
|
2014-11-17 09:30:23 +00:00
|
|
|
#if defined(CONFIG_CPU_DADDI_WORKAROUNDS) || (defined(CONFIG_EVA) && \
|
|
|
|
defined(CONFIG_CPU_HAS_PREFETCH))
|
2007-10-23 12:43:25 +01:00
|
|
|
#define DADDI_SCRATCH "$3"
|
2014-11-17 09:30:23 +00:00
|
|
|
#else
|
|
|
|
#define DADDI_SCRATCH "$0"
|
2007-10-23 12:43:25 +01:00
|
|
|
#endif
|
|
|
|
|
2021-04-01 14:56:37 +02:00
|
|
|
extern size_t __raw_copy_from_user(void *__to, const void *__from, size_t __n);
|
|
|
|
extern size_t __raw_copy_to_user(void *__to, const void *__from, size_t __n);
|
2013-12-11 16:47:10 +00:00
|
|
|
|
2017-03-28 15:59:26 -04:00
|
|
|
static inline unsigned long
|
2021-04-01 14:56:37 +02:00
|
|
|
raw_copy_from_user(void *to, const void __user *from, unsigned long n)
|
2017-03-28 15:59:26 -04:00
|
|
|
{
|
2021-04-01 14:56:37 +02:00
|
|
|
register void *__cu_to_r __asm__("$4");
|
|
|
|
register const void __user *__cu_from_r __asm__("$5");
|
|
|
|
register long __cu_len_r __asm__("$6");
|
|
|
|
|
|
|
|
__cu_to_r = to;
|
|
|
|
__cu_from_r = from;
|
|
|
|
__cu_len_r = n;
|
|
|
|
|
|
|
|
__asm__ __volatile__(
|
|
|
|
".set\tnoreorder\n\t"
|
|
|
|
__MODULE_JAL(__raw_copy_from_user)
|
|
|
|
".set\tnoat\n\t"
|
|
|
|
__UA_ADDU "\t$1, %1, %2\n\t"
|
|
|
|
".set\tat\n\t"
|
|
|
|
".set\treorder"
|
|
|
|
: "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r)
|
|
|
|
:
|
|
|
|
: "$8", "$9", "$10", "$11", "$12", "$14", "$15", "$24", "$31",
|
|
|
|
DADDI_SCRATCH, "memory");
|
|
|
|
|
|
|
|
return __cu_len_r;
|
2017-03-28 15:59:26 -04:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2017-03-28 15:59:26 -04:00
|
|
|
static inline unsigned long
|
2021-04-01 14:56:37 +02:00
|
|
|
raw_copy_to_user(void __user *to, const void *from, unsigned long n)
|
2017-03-28 15:59:26 -04:00
|
|
|
{
|
2021-04-01 14:56:37 +02:00
|
|
|
register void __user *__cu_to_r __asm__("$4");
|
|
|
|
register const void *__cu_from_r __asm__("$5");
|
|
|
|
register long __cu_len_r __asm__("$6");
|
|
|
|
|
|
|
|
__cu_to_r = (to);
|
|
|
|
__cu_from_r = (from);
|
|
|
|
__cu_len_r = (n);
|
|
|
|
|
|
|
|
__asm__ __volatile__(
|
|
|
|
__MODULE_JAL(__raw_copy_to_user)
|
|
|
|
: "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r)
|
|
|
|
:
|
|
|
|
: "$8", "$9", "$10", "$11", "$12", "$14", "$15", "$24", "$31",
|
|
|
|
DADDI_SCRATCH, "memory");
|
|
|
|
|
|
|
|
return __cu_len_r;
|
2017-03-28 15:59:26 -04:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2017-03-28 15:59:26 -04:00
|
|
|
#define INLINE_COPY_FROM_USER
|
|
|
|
#define INLINE_COPY_TO_USER
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2017-01-17 16:18:35 +01:00
|
|
|
extern __kernel_size_t __bzero(void __user *addr, __kernel_size_t size);
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* __clear_user: - Zero a block of memory in user space, with less checking.
|
2013-01-22 12:59:30 +01:00
|
|
|
* @to: Destination address, in user space.
|
|
|
|
* @n: Number of bytes to zero.
|
2005-04-16 15:20:36 -07:00
|
|
|
*
|
|
|
|
* Zero a block of memory in user space. Caller must check
|
|
|
|
* the specified block with access_ok() before calling this function.
|
|
|
|
*
|
|
|
|
* Returns number of bytes that could not be cleared.
|
|
|
|
* On success, this will be zero.
|
|
|
|
*/
|
|
|
|
static inline __kernel_size_t
|
2005-03-01 19:22:29 +00:00
|
|
|
__clear_user(void __user *addr, __kernel_size_t size)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
__kernel_size_t res;
|
|
|
|
|
2018-04-17 16:40:01 +01:00
|
|
|
#ifdef CONFIG_CPU_MICROMIPS
|
|
|
|
/* micromips memset / bzero also clobbers t7 & t8 */
|
|
|
|
#define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$15", "$24", "$31"
|
|
|
|
#else
|
|
|
|
#define bzero_clobbers "$4", "$5", "$6", __UA_t0, __UA_t1, "$31"
|
|
|
|
#endif /* CONFIG_CPU_MICROMIPS */
|
|
|
|
|
2021-04-01 14:56:37 +02:00
|
|
|
might_fault();
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"move\t$4, %1\n\t"
|
|
|
|
"move\t$5, $0\n\t"
|
|
|
|
"move\t$6, %2\n\t"
|
|
|
|
__MODULE_JAL(__bzero)
|
|
|
|
"move\t%0, $6"
|
|
|
|
: "=r" (res)
|
|
|
|
: "r" (addr), "r" (size)
|
|
|
|
: bzero_clobbers);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define clear_user(addr,n) \
|
|
|
|
({ \
|
2005-03-01 19:22:29 +00:00
|
|
|
void __user * __cl_addr = (addr); \
|
2005-04-16 15:20:36 -07:00
|
|
|
unsigned long __cl_size = (n); \
|
Remove 'type' argument from access_ok() function
Nobody has actually used the type (VERIFY_READ vs VERIFY_WRITE) argument
of the user address range verification function since we got rid of the
old racy i386-only code to walk page tables by hand.
It existed because the original 80386 would not honor the write protect
bit when in kernel mode, so you had to do COW by hand before doing any
user access. But we haven't supported that in a long time, and these
days the 'type' argument is a purely historical artifact.
A discussion about extending 'user_access_begin()' to do the range
checking resulted this patch, because there is no way we're going to
move the old VERIFY_xyz interface to that model. And it's best done at
the end of the merge window when I've done most of my merges, so let's
just get this done once and for all.
This patch was mostly done with a sed-script, with manual fix-ups for
the cases that weren't of the trivial 'access_ok(VERIFY_xyz' form.
There were a couple of notable cases:
- csky still had the old "verify_area()" name as an alias.
- the iter_iov code had magical hardcoded knowledge of the actual
values of VERIFY_{READ,WRITE} (not that they mattered, since nothing
really used it)
- microblaze used the type argument for a debug printout
but other than those oddities this should be a total no-op patch.
I tried to fix up all architectures, did fairly extensive grepping for
access_ok() uses, and the changes are trivial, but I may have missed
something. Any missed conversion should be trivially fixable, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-01-03 18:57:57 -08:00
|
|
|
if (__cl_size && access_ok(__cl_addr, __cl_size)) \
|
2005-04-16 15:20:36 -07:00
|
|
|
__cl_size = __clear_user(__cl_addr, __cl_size); \
|
|
|
|
__cl_size; \
|
|
|
|
})
|
|
|
|
|
2017-01-17 16:18:35 +01:00
|
|
|
extern long __strncpy_from_user_asm(char *__to, const char __user *__from, long __len);
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* strncpy_from_user: - Copy a NUL terminated string from userspace.
|
|
|
|
* @dst: Destination address, in kernel space. This buffer must be at
|
2013-01-22 12:59:30 +01:00
|
|
|
* least @count bytes long.
|
2005-04-16 15:20:36 -07:00
|
|
|
* @src: Source address, in user space.
|
|
|
|
* @count: Maximum number of bytes to copy, including the trailing NUL.
|
|
|
|
*
|
|
|
|
* Copies a NUL-terminated string from userspace to kernel space.
|
|
|
|
*
|
|
|
|
* On success, returns the length of the string (not including the trailing
|
|
|
|
* NUL).
|
|
|
|
*
|
|
|
|
* If access to userspace fails, returns -EFAULT (some data may have been
|
|
|
|
* copied).
|
|
|
|
*
|
|
|
|
* If @count is smaller than the length of the string, copies @count bytes
|
|
|
|
* and returns @count.
|
|
|
|
*/
|
|
|
|
static inline long
|
2005-03-01 19:22:29 +00:00
|
|
|
strncpy_from_user(char *__to, const char __user *__from, long __len)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
long res;
|
|
|
|
|
2021-04-01 14:56:37 +02:00
|
|
|
if (!access_ok(__from, __len))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
might_fault();
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"move\t$4, %1\n\t"
|
|
|
|
"move\t$5, %2\n\t"
|
|
|
|
"move\t$6, %3\n\t"
|
|
|
|
__MODULE_JAL(__strncpy_from_user_asm)
|
|
|
|
"move\t%0, $2"
|
|
|
|
: "=r" (res)
|
|
|
|
: "r" (__to), "r" (__from), "r" (__len)
|
|
|
|
: "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-01-17 16:18:35 +01:00
|
|
|
extern long __strnlen_user_asm(const char __user *s, long n);
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
2014-11-04 02:23:45 +01:00
|
|
|
* strnlen_user: - Get the size of a string in user space.
|
2005-04-16 15:20:36 -07:00
|
|
|
* @str: The string to measure.
|
|
|
|
*
|
2015-05-11 17:52:08 +02:00
|
|
|
* Context: User context only. This function may sleep if pagefaults are
|
|
|
|
* enabled.
|
2005-04-16 15:20:36 -07:00
|
|
|
*
|
|
|
|
* Get the size of a NUL-terminated string in user space.
|
|
|
|
*
|
|
|
|
* Returns the size of the string INCLUDING the terminating NUL.
|
|
|
|
* On exception, returns 0.
|
2014-11-04 02:23:45 +01:00
|
|
|
* If the string is too long, returns a value greater than @n.
|
2005-04-16 15:20:36 -07:00
|
|
|
*/
|
2005-03-01 19:22:29 +00:00
|
|
|
static inline long strnlen_user(const char __user *s, long n)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
long res;
|
|
|
|
|
2021-04-15 23:21:11 +02:00
|
|
|
if (!access_ok(s, 1))
|
|
|
|
return 0;
|
2021-04-01 14:56:37 +02:00
|
|
|
|
2009-04-28 14:17:54 +02:00
|
|
|
might_fault();
|
2021-04-01 14:56:37 +02:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"move\t$4, %1\n\t"
|
|
|
|
"move\t$5, %2\n\t"
|
|
|
|
__MODULE_JAL(__strnlen_user_asm)
|
|
|
|
"move\t%0, $2"
|
|
|
|
: "=r" (res)
|
|
|
|
: "r" (s), "r" (n)
|
|
|
|
: "$2", "$4", "$5", __UA_t0, "$31");
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _ASM_UACCESS_H */
|