x86/lib: Revert to _ASM_EXTABLE_UA() for {get,put}_user() fixups

During memory error injection test on kernels >= v6.4, the kernel panics
like below. However, this issue couldn't be reproduced on kernels <= v6.3.

mce: [Hardware Error]: CPU 296: Machine Check Exception: f Bank 1: bd80000000100134
mce: [Hardware Error]: RIP 10:<ffffffff821b9776> {__get_user_nocheck_4+0x6/0x20}
mce: [Hardware Error]: TSC 411a93533ed ADDR 346a8730040 MISC 86
mce: [Hardware Error]: PROCESSOR 0:a06d0 TIME 1706000767 SOCKET 1 APIC 211 microcode 80001490
mce: [Hardware Error]: Run the above through 'mcelog --ascii'
mce: [Hardware Error]: Machine check: Data load in unrecoverable area of kernel
Kernel panic - not syncing: Fatal local machine check

The MCA code can recover from an in-kernel #MC if the fixup type is
EX_TYPE_UACCESS, explicitly indicating that the kernel is attempting to
access userspace memory. However, if the fixup type is EX_TYPE_DEFAULT
the only thing that is raised for an in-kernel #MC is a panic.

ex_handler_uaccess() would warn if users gave a non-canonical addresses
(with bit 63 clear) to {get, put}_user(), which was unexpected.

Therefore, commit

b19b74bc99b1 ("x86/mm: Rework address range check in get_user() and put_user()")

replaced _ASM_EXTABLE_UA() with _ASM_EXTABLE() for {get, put}_user()
fixups. However, the new fixup type EX_TYPE_DEFAULT results in a panic.

Commit

6014bc27561f ("x86-64: make access_ok() independent of LAM")

added the check gp_fault_address_ok() right before the WARN_ONCE() in
ex_handler_uaccess() to not warn about non-canonical user addresses due
to LAM.

With that in place, revert back to _ASM_EXTABLE_UA() for {get,put}_user()
exception fixups in order to be able to handle in-kernel MCEs correctly
again.

[ bp: Massage commit message. ]

Fixes: b19b74bc99b1 ("x86/mm: Rework address range check in get_user() and put_user()")
Signed-off-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: <stable@kernel.org>
Link: https://lore.kernel.org/r/20240129063842.61584-1-qiuxu.zhuo@intel.com

authored by Qiuxu Zhuo and committed by Borislav Petkov (AMD) 8eed4e00 41bccc98

Changed files
+22 -22
arch
+12 -12
arch/x86/lib/getuser.S
··· 163 163 #endif 164 164 165 165 /* get_user */ 166 - _ASM_EXTABLE(1b, __get_user_handle_exception) 167 - _ASM_EXTABLE(2b, __get_user_handle_exception) 168 - _ASM_EXTABLE(3b, __get_user_handle_exception) 166 + _ASM_EXTABLE_UA(1b, __get_user_handle_exception) 167 + _ASM_EXTABLE_UA(2b, __get_user_handle_exception) 168 + _ASM_EXTABLE_UA(3b, __get_user_handle_exception) 169 169 #ifdef CONFIG_X86_64 170 - _ASM_EXTABLE(4b, __get_user_handle_exception) 170 + _ASM_EXTABLE_UA(4b, __get_user_handle_exception) 171 171 #else 172 - _ASM_EXTABLE(4b, __get_user_8_handle_exception) 173 - _ASM_EXTABLE(5b, __get_user_8_handle_exception) 172 + _ASM_EXTABLE_UA(4b, __get_user_8_handle_exception) 173 + _ASM_EXTABLE_UA(5b, __get_user_8_handle_exception) 174 174 #endif 175 175 176 176 /* __get_user */ 177 - _ASM_EXTABLE(6b, __get_user_handle_exception) 178 - _ASM_EXTABLE(7b, __get_user_handle_exception) 179 - _ASM_EXTABLE(8b, __get_user_handle_exception) 177 + _ASM_EXTABLE_UA(6b, __get_user_handle_exception) 178 + _ASM_EXTABLE_UA(7b, __get_user_handle_exception) 179 + _ASM_EXTABLE_UA(8b, __get_user_handle_exception) 180 180 #ifdef CONFIG_X86_64 181 - _ASM_EXTABLE(9b, __get_user_handle_exception) 181 + _ASM_EXTABLE_UA(9b, __get_user_handle_exception) 182 182 #else 183 - _ASM_EXTABLE(9b, __get_user_8_handle_exception) 184 - _ASM_EXTABLE(10b, __get_user_8_handle_exception) 183 + _ASM_EXTABLE_UA(9b, __get_user_8_handle_exception) 184 + _ASM_EXTABLE_UA(10b, __get_user_8_handle_exception) 185 185 #endif
+10 -10
arch/x86/lib/putuser.S
··· 133 133 RET 134 134 SYM_CODE_END(__put_user_handle_exception) 135 135 136 - _ASM_EXTABLE(1b, __put_user_handle_exception) 137 - _ASM_EXTABLE(2b, __put_user_handle_exception) 138 - _ASM_EXTABLE(3b, __put_user_handle_exception) 139 - _ASM_EXTABLE(4b, __put_user_handle_exception) 140 - _ASM_EXTABLE(5b, __put_user_handle_exception) 141 - _ASM_EXTABLE(6b, __put_user_handle_exception) 142 - _ASM_EXTABLE(7b, __put_user_handle_exception) 143 - _ASM_EXTABLE(9b, __put_user_handle_exception) 136 + _ASM_EXTABLE_UA(1b, __put_user_handle_exception) 137 + _ASM_EXTABLE_UA(2b, __put_user_handle_exception) 138 + _ASM_EXTABLE_UA(3b, __put_user_handle_exception) 139 + _ASM_EXTABLE_UA(4b, __put_user_handle_exception) 140 + _ASM_EXTABLE_UA(5b, __put_user_handle_exception) 141 + _ASM_EXTABLE_UA(6b, __put_user_handle_exception) 142 + _ASM_EXTABLE_UA(7b, __put_user_handle_exception) 143 + _ASM_EXTABLE_UA(9b, __put_user_handle_exception) 144 144 #ifdef CONFIG_X86_32 145 - _ASM_EXTABLE(8b, __put_user_handle_exception) 146 - _ASM_EXTABLE(10b, __put_user_handle_exception) 145 + _ASM_EXTABLE_UA(8b, __put_user_handle_exception) 146 + _ASM_EXTABLE_UA(10b, __put_user_handle_exception) 147 147 #endif