Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: 9324/1: fix get_user() broken with veneer

The 32-bit ARM kernel stops working if the kernel grows to the point
where veneers for __get_user_* are created.

AAPCS32 [1] states, "Register r12 (IP) may be used by a linker as a
scratch register between a routine and any subroutine it calls. It
can also be used within a routine to hold intermediate values between
subroutine calls."

However, bl instructions buried within the inline asm are unpredictable
for compilers; hence, "ip" must be added to the clobber list.

This becomes critical when veneers for __get_user_* are created because
veneers use the ip register since commit 02e541db0540 ("ARM: 8323/1:
force linker to use PIC veneers").

[1]: https://github.com/ARM-software/abi-aa/blob/2023Q1/aapcs32/aapcs32.rst

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

authored by

Masahiro Yamada and committed by
Russell King (Oracle)
24d3ba0a 399da29f

+2 -12
+2 -12
arch/arm/include/asm/uaccess.h
··· 109 109 extern int __get_user_64t_2(void *); 110 110 extern int __get_user_64t_4(void *); 111 111 112 - #define __GUP_CLOBBER_1 "lr", "cc" 113 - #ifdef CONFIG_CPU_USE_DOMAINS 114 - #define __GUP_CLOBBER_2 "ip", "lr", "cc" 115 - #else 116 - #define __GUP_CLOBBER_2 "lr", "cc" 117 - #endif 118 - #define __GUP_CLOBBER_4 "lr", "cc" 119 - #define __GUP_CLOBBER_32t_8 "lr", "cc" 120 - #define __GUP_CLOBBER_8 "lr", "cc" 121 - 122 112 #define __get_user_x(__r2, __p, __e, __l, __s) \ 123 113 __asm__ __volatile__ ( \ 124 114 __asmeq("%0", "r0") __asmeq("%1", "r2") \ ··· 116 126 "bl __get_user_" #__s \ 117 127 : "=&r" (__e), "=r" (__r2) \ 118 128 : "0" (__p), "r" (__l) \ 119 - : __GUP_CLOBBER_##__s) 129 + : "ip", "lr", "cc") 120 130 121 131 /* narrowing a double-word get into a single 32bit word register: */ 122 132 #ifdef __ARMEB__ ··· 138 148 "bl __get_user_64t_" #__s \ 139 149 : "=&r" (__e), "=r" (__r2) \ 140 150 : "0" (__p), "r" (__l) \ 141 - : __GUP_CLOBBER_##__s) 151 + : "ip", "lr", "cc") 142 152 #else 143 153 #define __get_user_x_64t __get_user_x 144 154 #endif