Skip to content

Commit a2f7340

Browse files
aeglsuryasaimadhu
authored andcommitted
x86/mce: Avoid tail copy when machine check terminated a copy from user
In the page fault case it is ok to see if a few more unaligned bytes can be copied from the source address. Worst case is that the page fault will be triggered again. Machine checks are more serious. Just give up at the point where the main copy loop triggered the #MC and return from the copy code as if the copy succeeded. The machine check handler will use task_work_add() to make sure that the task is sent a SIGBUS. Signed-off-by: Tony Luck <tony.luck@intel.com> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/20201006210910.21062-5-tony.luck@intel.com
1 parent 278b917 commit a2f7340

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

arch/x86/lib/copy_user_64.S

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <asm/asm.h>
1616
#include <asm/smap.h>
1717
#include <asm/export.h>
18+
#include <asm/trapnr.h>
1819

1920
.macro ALIGN_DESTINATION
2021
/* check for bad alignment of destination */
@@ -221,6 +222,7 @@ EXPORT_SYMBOL(copy_user_enhanced_fast_string)
221222
* Try to copy last bytes and clear the rest if needed.
222223
* Since protection fault in copy_from/to_user is not a normal situation,
223224
* it is not necessary to optimize tail handling.
225+
* Don't try to copy the tail if machine check happened
224226
*
225227
* Input:
226228
* rdi destination
@@ -232,11 +234,24 @@ EXPORT_SYMBOL(copy_user_enhanced_fast_string)
232234
*/
233235
SYM_CODE_START_LOCAL(.Lcopy_user_handle_tail)
234236
movl %edx,%ecx
237+
cmp $X86_TRAP_MC,%eax /* check if X86_TRAP_MC */
238+
je 3f
235239
1: rep movsb
236240
2: mov %ecx,%eax
237241
ASM_CLAC
238242
ret
239243

244+
/*
245+
* Return zero to pretend that this copy succeeded. This
246+
* is counter-intuitive, but needed to prevent the code
247+
* in lib/iov_iter.c from retrying and running back into
248+
* the poison cache line again. The machine check handler
249+
* will ensure that a SIGBUS is sent to the task.
250+
*/
251+
3: xorl %eax,%eax
252+
ASM_CLAC
253+
ret
254+
240255
_ASM_EXTABLE_CPY(1b, 2b)
241256
SYM_CODE_END(.Lcopy_user_handle_tail)
242257

0 commit comments

Comments
 (0)