Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef __ASM_GENERIC_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define __ASM_GENERIC_UACCESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * User space memory access functions, these should work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * on any machine that has kernel and user data in the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * address space, e.g. all NOMMU machines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #ifdef CONFIG_UACCESS_MEMCPY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static __always_inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) __get_user_fn(size_t size, const void __user *from, void *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	BUILD_BUG_ON(!__builtin_constant_p(size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	switch (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 		*(u8 *)to = get_unaligned((u8 __force *)from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		*(u16 *)to = get_unaligned((u16 __force *)from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		*(u32 *)to = get_unaligned((u32 __force *)from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		*(u64 *)to = get_unaligned((u64 __force *)from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		BUILD_BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define __get_user_fn(sz, u, k)	__get_user_fn(sz, u, k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static __always_inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) __put_user_fn(size_t size, void __user *to, void *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	BUILD_BUG_ON(!__builtin_constant_p(size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	switch (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		put_unaligned(*(u8 *)from, (u8 __force *)to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		put_unaligned(*(u16 *)from, (u16 __force *)to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	case 4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		put_unaligned(*(u32 *)from, (u32 __force *)to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		put_unaligned(*(u64 *)from, (u64 __force *)to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		BUILD_BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define __put_user_fn(sz, u, k)	__put_user_fn(sz, u, k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define __get_kernel_nofault(dst, src, type, err_label)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	*((type *)dst) = get_unaligned((type *)(src));			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (0) /* make sure the label looks used to the compiler */	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		goto err_label;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define __put_kernel_nofault(dst, src, type, err_label)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	put_unaligned(*((type *)src), (type *)(dst));			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (0) /* make sure the label looks used to the compiler */	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		goto err_label;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #define HAVE_GET_KERNEL_NOFAULT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static inline __must_check unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) raw_copy_from_user(void *to, const void __user * from, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	memcpy(to, (const void __force *)from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static inline __must_check unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) raw_copy_to_user(void __user *to, const void *from, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	memcpy((void __force *)to, from, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #define INLINE_COPY_FROM_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #define INLINE_COPY_TO_USER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #endif /* CONFIG_UACCESS_MEMCPY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #ifdef CONFIG_SET_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define MAKE_MM_SEG(s)	((mm_segment_t) { (s) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #ifndef KERNEL_DS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define KERNEL_DS	MAKE_MM_SEG(~0UL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #ifndef USER_DS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define USER_DS		MAKE_MM_SEG(TASK_SIZE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #ifndef get_fs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define get_fs()	(current_thread_info()->addr_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static inline void set_fs(mm_segment_t fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	current_thread_info()->addr_limit = fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #ifndef uaccess_kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define uaccess_kernel() (get_fs().seg == KERNEL_DS.seg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #endif /* CONFIG_SET_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define access_ok(addr, size) __access_ok((unsigned long)(addr),(size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * The architecture should really override this if possible, at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * doing a check on the get_fs()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #ifndef __access_ok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static inline int __access_ok(unsigned long addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * These are the main single-value transfer routines.  They automatically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * use the right size if we just have the right pointer type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * This version just falls back to copy_{from,to}_user, which should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * provide a fast-path for small values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #define __put_user(x, ptr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	__typeof__(*(ptr)) __x = (x);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	int __pu_err = -EFAULT;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)         __chk_user_ptr(ptr);                                    \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	switch (sizeof (*(ptr))) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	case 1:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	case 2:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	case 4:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	case 8:							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		__pu_err = __put_user_fn(sizeof (*(ptr)),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 					 ptr, &__x);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	default:						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		__put_user_bad();				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 }							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	__pu_err;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) #define put_user(x, ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	void __user *__p = (ptr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	might_fault();						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	access_ok(__p, sizeof(*ptr)) ?		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		__put_user((x), ((__typeof__(*(ptr)) __user *)__p)) :	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		-EFAULT;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #ifndef __put_user_fn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static inline int __put_user_fn(size_t size, void __user *ptr, void *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return unlikely(raw_copy_to_user(ptr, x, size)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #define __put_user_fn(sz, u, k)	__put_user_fn(sz, u, k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) extern int __put_user_bad(void) __attribute__((noreturn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define __get_user(x, ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	int __gu_err = -EFAULT;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	__chk_user_ptr(ptr);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	switch (sizeof(*(ptr))) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	case 1: {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		unsigned char __x = 0;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		__gu_err = __get_user_fn(sizeof (*(ptr)),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 					 ptr, &__x);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		(x) = *(__force __typeof__(*(ptr)) *) &__x;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	};							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	case 2: {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		unsigned short __x = 0;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		__gu_err = __get_user_fn(sizeof (*(ptr)),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 					 ptr, &__x);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		(x) = *(__force __typeof__(*(ptr)) *) &__x;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	};							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	case 4: {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		unsigned int __x = 0;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		__gu_err = __get_user_fn(sizeof (*(ptr)),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 					 ptr, &__x);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		(x) = *(__force __typeof__(*(ptr)) *) &__x;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	};							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	case 8: {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		unsigned long long __x = 0;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		__gu_err = __get_user_fn(sizeof (*(ptr)),	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 					 ptr, &__x);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		(x) = *(__force __typeof__(*(ptr)) *) &__x;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	};							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	default:						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		__get_user_bad();				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		break;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	__gu_err;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #define get_user(x, ptr)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	const void __user *__p = (ptr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	might_fault();						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	access_ok(__p, sizeof(*ptr)) ?		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		__get_user((x), (__typeof__(*(ptr)) __user *)__p) :\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		((x) = (__typeof__(*(ptr)))0,-EFAULT);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #ifndef __get_user_fn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static inline int __get_user_fn(size_t size, const void __user *ptr, void *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	return unlikely(raw_copy_from_user(x, ptr, size)) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #define __get_user_fn(sz, u, k)	__get_user_fn(sz, u, k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) extern int __get_user_bad(void) __attribute__((noreturn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * Copy a null terminated string from userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #ifndef __strncpy_from_user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static inline long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) __strncpy_from_user(char *dst, const char __user *src, long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	char *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	strncpy(dst, (const char __force *)src, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	for (tmp = dst; *tmp && count > 0; tmp++, count--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return (tmp - dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static inline long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) strncpy_from_user(char *dst, const char __user *src, long count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (!access_ok(src, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	return __strncpy_from_user(dst, src, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  * Return the size of a string (including the ending 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  * Return 0 on exception, a value greater than N if too long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) #ifndef __strnlen_user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #define __strnlen_user(s, n) (strnlen((s), (n)) + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  * Unlike strnlen, strnlen_user includes the nul terminator in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  * its returned count. Callers should check for a returned value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * greater than N as an indication the string is too long.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static inline long strnlen_user(const char __user *src, long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (!access_ok(src, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	return __strnlen_user(src, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * Zero Userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #ifndef __clear_user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static inline __must_check unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) __clear_user(void __user *to, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	memset((void __force *)to, 0, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static inline __must_check unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) clear_user(void __user *to, unsigned long n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	might_fault();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (!access_ok(to, n))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	return __clear_user(to, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) #include <asm/extable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) #endif /* __ASM_GENERIC_UACCESS_H */