summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Hogan <james.hogan@imgtec.com>2017-05-02 19:41:06 +0100
committerSasha Levin <alexander.levin@verizon.com>2017-05-17 15:08:24 -0400
commit327d78550aea59481ef99d500b42927c3735ae5b (patch)
tree96ad76febb6c0677b4e03fc57891ff19edc93151
parent31390049dfd2b65da315f0e4f5d98f115ce09352 (diff)
downloadlinux-stable-327d78550aea59481ef99d500b42927c3735ae5b.tar.gz
linux-stable-327d78550aea59481ef99d500b42927c3735ae5b.tar.bz2
linux-stable-327d78550aea59481ef99d500b42927c3735ae5b.zip
metag/uaccess: Check access_ok in strncpy_from_user
[ Upstream commit 3a158a62da0673db918b53ac1440845a5b64fd90 ] The metag implementation of strncpy_from_user() doesn't validate the src pointer, which could allow reading of arbitrary kernel memory. Add a short access_ok() check to prevent that. Its still possible for it to read across the user/kernel boundary, but it will invariably reach a NUL character after only 9 bytes, leaking only a static kernel address being loaded into D0Re0 at the beginning of __start, which is acceptable for the immediate fix. Reported-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: James Hogan <james.hogan@imgtec.com> Cc: linux-metag@vger.kernel.org Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
-rw-r--r--arch/metag/include/asm/uaccess.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/arch/metag/include/asm/uaccess.h b/arch/metag/include/asm/uaccess.h
index ed6cd90ec5ca..3db381205928 100644
--- a/arch/metag/include/asm/uaccess.h
+++ b/arch/metag/include/asm/uaccess.h
@@ -194,8 +194,13 @@ do { \
extern long __must_check __strncpy_from_user(char *dst, const char __user *src,
long count);
-#define strncpy_from_user(dst, src, count) __strncpy_from_user(dst, src, count)
-
+static inline long
+strncpy_from_user(char *dst, const char __user *src, long count)
+{
+ if (!access_ok(VERIFY_READ, src, 1))
+ return -EFAULT;
+ return __strncpy_from_user(dst, src, count);
+}
/*
* Return the size of a string (including the ending 0)
*