Skip to content

Commit ca19dd1

Browse files
James Hogangregkh
authored andcommitted
metag/uaccess: Check access_ok in strncpy_from_user
commit 3a158a62da0673db918b53ac1440845a5b64fd90 upstream. 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 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2d9b2e7 commit ca19dd1

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

arch/metag/include/asm/uaccess.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,13 @@ do { \
194194
extern long __must_check __strncpy_from_user(char *dst, const char __user *src,
195195
long count);
196196

197-
#define strncpy_from_user(dst, src, count) __strncpy_from_user(dst, src, count)
198-
197+
static inline long
198+
strncpy_from_user(char *dst, const char __user *src, long count)
199+
{
200+
if (!access_ok(VERIFY_READ, src, 1))
201+
return -EFAULT;
202+
return __strncpy_from_user(dst, src, count);
203+
}
199204
/*
200205
* Return the size of a string (including the ending 0)
201206
*

0 commit comments

Comments
 (0)