From 2820cfdc08178c55efa1c0fa402f082ef09bfe70 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Thu, 16 Jan 2020 15:58:41 +0100 Subject: hexagon: use generic strncpy/strnlen from_user Remove the hexagon implementation of strncpy/strnlen and instead use the generic version. The hexagon version reads the data twice for strncpy() by doing an extra strnlen(), and it apparently lacks a check for user_addr_max(). Reviewed-by: Christoph Hellwig Signed-off-by: Arnd Bergmann --- arch/hexagon/include/asm/uaccess.h | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) (limited to 'arch/hexagon/include') diff --git a/arch/hexagon/include/asm/uaccess.h b/arch/hexagon/include/asm/uaccess.h index 59aa3a50744f..d950df12d8c5 100644 --- a/arch/hexagon/include/asm/uaccess.h +++ b/arch/hexagon/include/asm/uaccess.h @@ -57,42 +57,13 @@ unsigned long raw_copy_to_user(void __user *to, const void *from, __kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count); #define __clear_user(a, s) __clear_user_hexagon((a), (s)) -extern long __strnlen_user(const char __user *src, long n); - -static inline strnlen_user(const char __user *src, long n) -{ - if (!access_ok(src, 1)) - return 0; - - return __strnlen_user(src, n); -} -/* get around the ifndef in asm-generic/uaccess.h */ +extern long strnlen_user(const char __user *src, long n); #define strnlen_user strnlen_user -static inline long strncpy_from_user(char *dst, const char __user *src, long n); +extern long strncpy_from_user(char *dst, const char __user *src, long n) #define strncpy_from_user strncpy_from_user #include -/* Todo: an actual accelerated version of this. */ -static inline long strncpy_from_user(char *dst, const char __user *src, long n) -{ - long res = strnlen_user(src, n); - - if (unlikely(!res)) - return -EFAULT; - - if (res > n) { - long left = raw_copy_from_user(dst, src, n); - if (unlikely(left)) - memset(dst + (n - left), 0, left); - return n; - } else { - long left = raw_copy_from_user(dst, src, res); - if (unlikely(left)) - memset(dst + (res - left), 0, left); - return res-1; - } -} #endif -- cgit