[PATCH] x86-kasan-instrument-user-memory-access-api-fix

From: Andrey Ryabinin
Date: Tue May 10 2016 - 05:06:53 EST


Move kasan check under the condition, otherwise we may fail and not
do a user copy.

Reported-by: Ingo Molnar <mingo@xxxxxxxxxx>
Signed-off-by: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx>
---
lib/strncpy_from_user.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
index e3472b0..33f655e 100644
--- a/lib/strncpy_from_user.c
+++ b/lib/strncpy_from_user.c
@@ -104,13 +104,13 @@ long strncpy_from_user(char *dst, const char __user *src, long count)
if (unlikely(count <= 0))
return 0;

- kasan_check_write(dst, count);
max_addr = user_addr_max();
src_addr = (unsigned long)src;
if (likely(src_addr < max_addr)) {
unsigned long max = max_addr - src_addr;
long retval;

+ kasan_check_write(dst, count);
user_access_begin();
retval = do_strncpy_from_user(dst, src, count, max);
user_access_end();
--
2.7.3