arm64: uaccess: Mask __user pointers for __arch_{clear, copy_*}_user
authorWill Deacon <will.deacon@arm.com>
Mon, 5 Feb 2018 15:34:23 +0000 (15:34 +0000)
committerCatalin Marinas <catalin.marinas@arm.com>
Tue, 6 Feb 2018 22:53:40 +0000 (22:53 +0000)
Like we've done for get_user and put_user, ensure that user pointers
are masked before invoking the underlying __arch_{clear,copy_*}_user
operations.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/uaccess.h
arch/arm64/kernel/arm64ksyms.c
arch/arm64/lib/clear_user.S
arch/arm64/lib/copy_in_user.S

index e5002bc7130dbff962049e197a796d0ffc75f21d..543e11f0f657e932aa17916a0750f7d83cf5d7b8 100644 (file)
@@ -403,20 +403,35 @@ do {                                                                      \
 #define put_user       __put_user
 
 extern unsigned long __must_check __arch_copy_from_user(void *to, const void __user *from, unsigned long n);
-#define raw_copy_from_user __arch_copy_from_user
+#define raw_copy_from_user(to, from, n)                                        \
+({                                                                     \
+       __arch_copy_from_user((to), __uaccess_mask_ptr(from), (n));     \
+})
+
 extern unsigned long __must_check __arch_copy_to_user(void __user *to, const void *from, unsigned long n);
-#define raw_copy_to_user __arch_copy_to_user
-extern unsigned long __must_check raw_copy_in_user(void __user *to, const void __user *from, unsigned long n);
-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
+#define raw_copy_to_user(to, from, n)                                  \
+({                                                                     \
+       __arch_copy_to_user(__uaccess_mask_ptr(to), (from), (n));       \
+})
+
+extern unsigned long __must_check __arch_copy_in_user(void __user *to, const void __user *from, unsigned long n);
+#define raw_copy_in_user(to, from, n)                                  \
+({                                                                     \
+       __arch_copy_in_user(__uaccess_mask_ptr(to),                     \
+                           __uaccess_mask_ptr(from), (n));             \
+})
+
 #define INLINE_COPY_TO_USER
 #define INLINE_COPY_FROM_USER
 
-static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
+extern unsigned long __must_check __arch_clear_user(void __user *to, unsigned long n);
+static inline unsigned long __must_check __clear_user(void __user *to, unsigned long n)
 {
        if (access_ok(VERIFY_WRITE, to, n))
-               n = __clear_user(__uaccess_mask_ptr(to), n);
+               n = __arch_clear_user(__uaccess_mask_ptr(to), n);
        return n;
 }
+#define clear_user     __clear_user
 
 extern long strncpy_from_user(char *dest, const char __user *src, long count);
 
@@ -430,7 +445,7 @@ extern unsigned long __must_check __copy_user_flushcache(void *to, const void __
 static inline int __copy_from_user_flushcache(void *dst, const void __user *src, unsigned size)
 {
        kasan_check_write(dst, size);
-       return __copy_user_flushcache(dst, src, size);
+       return __copy_user_flushcache(dst, __uaccess_mask_ptr(src), size);
 }
 #endif
 
index 67368c7329c03e762a6873eef5305b4b20c2b7b7..66be504edb6cf5be422afa59d82aa2db4fd3ed7f 100644 (file)
@@ -37,8 +37,8 @@ EXPORT_SYMBOL(clear_page);
        /* user mem (segment) */
 EXPORT_SYMBOL(__arch_copy_from_user);
 EXPORT_SYMBOL(__arch_copy_to_user);
-EXPORT_SYMBOL(__clear_user);
-EXPORT_SYMBOL(raw_copy_in_user);
+EXPORT_SYMBOL(__arch_clear_user);
+EXPORT_SYMBOL(__arch_copy_in_user);
 
        /* physical memory */
 EXPORT_SYMBOL(memstart_addr);
index 3d69a8d41fa5e59217d5a451cf2ed67bb460a483..21ba0b29621b2fab087aa8adaeb15e0d589966ac 100644 (file)
@@ -21,7 +21,7 @@
 
        .text
 
-/* Prototype: int __clear_user(void *addr, size_t sz)
+/* Prototype: int __arch_clear_user(void *addr, size_t sz)
  * Purpose  : clear some user memory
  * Params   : addr - user memory address to clear
  *          : sz   - number of bytes to clear
@@ -29,7 +29,7 @@
  *
  * Alignment fixed up by hardware.
  */
-ENTRY(__clear_user)
+ENTRY(__arch_clear_user)
        uaccess_enable_not_uao x2, x3, x4
        mov     x2, x1                  // save the size for fixup return
        subs    x1, x1, #8
@@ -52,7 +52,7 @@ uao_user_alternative 9f, strb, sttrb, wzr, x0, 0
 5:     mov     x0, #0
        uaccess_disable_not_uao x2, x3
        ret
-ENDPROC(__clear_user)
+ENDPROC(__arch_clear_user)
 
        .section .fixup,"ax"
        .align  2
index fbb090f431a5c0790c9c98ac7b947505cf7c48d8..54b75deb1d1606c2d5c317b35ee2f5bbc78144ba 100644 (file)
        .endm
 
 end    .req    x5
-ENTRY(raw_copy_in_user)
+
+ENTRY(__arch_copy_in_user)
        uaccess_enable_not_uao x3, x4, x5
        add     end, x0, x2
 #include "copy_template.S"
        uaccess_disable_not_uao x3, x4
        mov     x0, #0
        ret
-ENDPROC(raw_copy_in_user)
+ENDPROC(__arch_copy_in_user)
 
        .section .fixup,"ax"
        .align  2