From f27180dd63e1e6eca3230b9d3fdcc33564a81117 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Thu, 16 Jan 2020 13:18:38 +0100 Subject: asm-generic/uaccess.h: remove __strncpy_from_user/__strnlen_user This is a preparation for changing over architectures to the generic implementation one at a time. As there are no callers of either __strncpy_from_user() or __strnlen_user(), fold these into the strncpy_from_user() and strnlen_user() functions to make each implementation independent of the others. Many of these implementations have known bugs, but the intention here is to not change behavior at all and stay compatible with those bugs for the moment. Reviewed-by: Christoph Hellwig Signed-off-by: Arnd Bergmann --- arch/csky/include/asm/uaccess.h | 8 ++++---- arch/csky/lib/usercopy.c | 14 ++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'arch/csky') diff --git a/arch/csky/include/asm/uaccess.h b/arch/csky/include/asm/uaccess.h index ac83823fc437..e17c02a6709f 100644 --- a/arch/csky/include/asm/uaccess.h +++ b/arch/csky/include/asm/uaccess.h @@ -209,11 +209,11 @@ unsigned long raw_copy_to_user(void *to, const void *from, unsigned long n); unsigned long __clear_user(void __user *to, unsigned long n); #define __clear_user __clear_user -long __strncpy_from_user(char *dst, const char *src, long count); -#define __strncpy_from_user __strncpy_from_user +long strncpy_from_user(char *dst, const char *src, long count); +#define strncpy_from_user strncpy_from_user -long __strnlen_user(const char *s, long n); -#define __strnlen_user __strnlen_user +long strnlen_user(const char *s, long n); +#define strnlen_user strnlen_user #include #include diff --git a/arch/csky/lib/usercopy.c b/arch/csky/lib/usercopy.c index c5d394a0ae78..05b36e9fd7d3 100644 --- a/arch/csky/lib/usercopy.c +++ b/arch/csky/lib/usercopy.c @@ -163,11 +163,14 @@ EXPORT_SYMBOL(raw_copy_to_user); * If @count is smaller than the length of the string, copies @count bytes * and returns @count. */ -long __strncpy_from_user(char *dst, const char *src, long count) +long strncpy_from_user(char *dst, const char *src, long count) { long res, faultres; int tmp; + if (!access_ok(s, 1)) + return -EFAULT; + __asm__ __volatile__( " cmpnei %3, 0 \n" " bf 4f \n" @@ -198,7 +201,7 @@ long __strncpy_from_user(char *dst, const char *src, long count) return res; } -EXPORT_SYMBOL(__strncpy_from_user); +EXPORT_SYMBOL(strncpy_from_user); /* * strnlen_user: - Get the size of a string in user space. @@ -211,10 +214,13 @@ EXPORT_SYMBOL(__strncpy_from_user); * On exception, returns 0. * If the string is too long, returns a value greater than @n. */ -long __strnlen_user(const char *s, long n) +long strnlen_user(const char *s, long n) { unsigned long res, tmp; + if (!access_ok(s, 1)) + return -EFAULT; + __asm__ __volatile__( " cmpnei %1, 0 \n" " bf 3f \n" @@ -242,7 +248,7 @@ long __strnlen_user(const char *s, long n) return res; } -EXPORT_SYMBOL(__strnlen_user); +EXPORT_SYMBOL(strnlen_user); /* * __clear_user: - Zero a block of memory in user space, with less checking. -- cgit v1.2.3