arm64: don't zero in __copy_from_user{,_inatomic} 55/220855/1
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 10 Sep 2016 20:50:00 +0000 (16:50 -0400)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 24 Dec 2019 04:12:28 +0000 (13:12 +0900)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
[sw0312.kim: backport mainline commit 4855bd255f9f for gcc 9 build to array-bounds warning]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Id32687d129f625f2c430a7b9a1b440a4614b8a17

arch/arm64/include/asm/uaccess.h
arch/arm64/lib/copy_from_user.S

index 3bf8f4e99a511c67a3a2d9c4a739929cedd5889f..17fa313ba6788ad123724bc8889a02b65c4713c1 100644 (file)
@@ -243,11 +243,12 @@ extern unsigned long __must_check __clear_user(void __user *addr, unsigned long
 
 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
 {
+       unsigned long res = n;
        if (access_ok(VERIFY_READ, from, n))
-               n = __copy_from_user(to, from, n);
-       else /* security hole - plug it */
-               memset(to, 0, n);
-       return n;
+               res = __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)
index 5e27add9d3624e653cab6cf9e583586112d14e02..81e72b33d4c8df19a7c9aa0fa3e124eab867b902 100644 (file)
@@ -57,10 +57,6 @@ ENDPROC(__copy_from_user)
        .section .fixup,"ax"
        .align  2
 9:     sub     x2, x4, x1
-       mov     x3, x2
-10:    strb    wzr, [x0], #1                   // zero remaining buffer space
-       subs    x3, x3, #1
-       b.ne    10b
        mov     x0, x2                          // bytes not copied
        ret
        .previous