uaccess: fix nios2 and microblaze get_user_8()
[ Upstream commit a97b693c3712f040c5802f32b2d685352e08cefa ] These two architectures implement 8-byte get_user() through a memcpy() into a four-byte variable, which won't fit. Use a temporary 64-bit variable instead here, and use a double cast the way that risc-v and openrisc do to avoid compile-time warnings. Fixes:6a090e9797
("arch/microblaze: support get_user() of size 8 bytes") Fixes:5ccc6af5e8
("nios2: Memory management") Reviewed-by: Christoph Hellwig <hch@lst.de> Acked-by: Dinh Nguyen <dinguyen@kernel.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
19894751f6
commit
7ce3e6e103
|
@ -167,27 +167,27 @@ extern long __user_bad(void);
|
|||
|
||||
#define __get_user(x, ptr) \
|
||||
({ \
|
||||
unsigned long __gu_val = 0; \
|
||||
long __gu_err; \
|
||||
switch (sizeof(*(ptr))) { \
|
||||
case 1: \
|
||||
__get_user_asm("lbu", (ptr), __gu_val, __gu_err); \
|
||||
__get_user_asm("lbu", (ptr), x, __gu_err); \
|
||||
break; \
|
||||
case 2: \
|
||||
__get_user_asm("lhu", (ptr), __gu_val, __gu_err); \
|
||||
__get_user_asm("lhu", (ptr), x, __gu_err); \
|
||||
break; \
|
||||
case 4: \
|
||||
__get_user_asm("lw", (ptr), __gu_val, __gu_err); \
|
||||
__get_user_asm("lw", (ptr), x, __gu_err); \
|
||||
break; \
|
||||
case 8: \
|
||||
__gu_err = __copy_from_user(&__gu_val, ptr, 8); \
|
||||
if (__gu_err) \
|
||||
__gu_err = -EFAULT; \
|
||||
case 8: { \
|
||||
__u64 __x = 0; \
|
||||
__gu_err = raw_copy_from_user(&__x, ptr, 8) ? \
|
||||
-EFAULT : 0; \
|
||||
(x) = (typeof(x))(typeof((x) - (x)))__x; \
|
||||
break; \
|
||||
} \
|
||||
default: \
|
||||
/* __gu_val = 0; __gu_err = -EINVAL;*/ __gu_err = __user_bad();\
|
||||
} \
|
||||
x = (__force __typeof__(*(ptr))) __gu_val; \
|
||||
__gu_err; \
|
||||
})
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ extern __must_check long strnlen_user(const char __user *s, long n);
|
|||
/* Optimized macros */
|
||||
#define __get_user_asm(val, insn, addr, err) \
|
||||
{ \
|
||||
unsigned long __gu_val; \
|
||||
__asm__ __volatile__( \
|
||||
" movi %0, %3\n" \
|
||||
"1: " insn " %1, 0(%2)\n" \
|
||||
|
@ -97,14 +98,20 @@ extern __must_check long strnlen_user(const char __user *s, long n);
|
|||
" .section __ex_table,\"a\"\n" \
|
||||
" .word 1b, 2b\n" \
|
||||
" .previous" \
|
||||
: "=&r" (err), "=r" (val) \
|
||||
: "=&r" (err), "=r" (__gu_val) \
|
||||
: "r" (addr), "i" (-EFAULT)); \
|
||||
val = (__force __typeof__(*(addr)))__gu_val; \
|
||||
}
|
||||
|
||||
#define __get_user_unknown(val, size, ptr, err) do { \
|
||||
extern void __get_user_unknown(void);
|
||||
|
||||
#define __get_user_8(val, ptr, err) do { \
|
||||
u64 __val = 0; \
|
||||
err = 0; \
|
||||
if (__copy_from_user(&(val), ptr, size)) { \
|
||||
if (raw_copy_from_user(&(__val), ptr, sizeof(val))) { \
|
||||
err = -EFAULT; \
|
||||
} else { \
|
||||
val = (typeof(val))(typeof((val) - (val)))__val; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
@ -120,8 +127,11 @@ do { \
|
|||
case 4: \
|
||||
__get_user_asm(val, "ldw", ptr, err); \
|
||||
break; \
|
||||
case 8: \
|
||||
__get_user_8(val, ptr, err); \
|
||||
break; \
|
||||
default: \
|
||||
__get_user_unknown(val, size, ptr, err); \
|
||||
__get_user_unknown(); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
@ -130,9 +140,7 @@ do { \
|
|||
({ \
|
||||
long __gu_err = -EFAULT; \
|
||||
const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
|
||||
unsigned long __gu_val = 0; \
|
||||
__get_user_common(__gu_val, sizeof(*(ptr)), __gu_ptr, __gu_err);\
|
||||
(x) = (__force __typeof__(x))__gu_val; \
|
||||
__get_user_common(x, sizeof(*(ptr)), __gu_ptr, __gu_err); \
|
||||
__gu_err; \
|
||||
})
|
||||
|
||||
|
@ -140,11 +148,9 @@ do { \
|
|||
({ \
|
||||
long __gu_err = -EFAULT; \
|
||||
const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
|
||||
unsigned long __gu_val = 0; \
|
||||
if (access_ok( __gu_ptr, sizeof(*__gu_ptr))) \
|
||||
__get_user_common(__gu_val, sizeof(*__gu_ptr), \
|
||||
__get_user_common(x, sizeof(*__gu_ptr), \
|
||||
__gu_ptr, __gu_err); \
|
||||
(x) = (__force __typeof__(x))__gu_val; \
|
||||
__gu_err; \
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user