From 25fd4e84076114e676c2b02c5d98a7eaa71fda1c Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 10 Sep 2016 16:50:00 -0400 Subject: [PATCH] arm64: don't zero in __copy_from_user{,_inatomic} Signed-off-by: Al Viro [sw0312.kim: backport mainline commit 4855bd255f9f for gcc 9 build to array-bounds warning] Signed-off-by: Seung-Woo Kim Change-Id: Id32687d129f625f2c430a7b9a1b440a4614b8a17 --- arch/arm64/include/asm/uaccess.h | 9 +++++---- arch/arm64/lib/copy_from_user.S | 4 ---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 3bf8f4e99a5..17fa313ba67 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -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) diff --git a/arch/arm64/lib/copy_from_user.S b/arch/arm64/lib/copy_from_user.S index 5e27add9d36..81e72b33d4c 100644 --- a/arch/arm64/lib/copy_from_user.S +++ b/arch/arm64/lib/copy_from_user.S @@ -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 -- 2.34.1