Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[cascardo/linux.git] / arch / arm64 / include / asm / uaccess.h
index c47257c..bcaf6fb 100644 (file)
@@ -278,14 +278,16 @@ static inline unsigned long __must_check __copy_to_user(void __user *to, const v
 
 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
 {
+       unsigned long res = n;
        kasan_check_write(to, n);
 
        if (access_ok(VERIFY_READ, from, n)) {
                check_object_size(to, n, false);
-               n = __arch_copy_from_user(to, from, n);
-       } else /* security hole - plug it */
-               memset(to, 0, n);
-       return n;
+               res = __arch_copy_from_user(to, from, n);
+       }
+       if (unlikely(res))
+               memset(to + (n - res), 0, res);
+       return res;
 }
 
 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)