The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* UNTRAIN_RET in native_irq_return_ldt
@ 2022-07-12 18:20 Alexandre Chartre
  2022-07-13  9:50 ` Peter Zijlstra
  2022-07-14 11:08 ` [tip: x86/urgent] x86/entry: Remove UNTRAIN_RET from native_irq_return_ldt tip-bot2 for Alexandre Chartre
  0 siblings, 2 replies; 3+ messages in thread
From: Alexandre Chartre @ 2022-07-12 18:20 UTC (permalink / raw)
  To: Peter Zijlstra, Borislav Petkov; +Cc: X86 ML, LKML


Hi,

I think there is an issue in native_irq_return_ldt: UNTRAIN_RET is used and can
clobber %rax which is expected to be the user rax.

A simple fix would be to preserve %rax:

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index a4ba162e52c3..f1fe05289d84 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -728,7 +728,11 @@ native_irq_return_ldt:
         pushq   %rdi                            /* Stash user RDI */
         swapgs                                  /* to kernel GS */
         SWITCH_TO_KERNEL_CR3 scratch_reg=%rdi   /* to kernel CR3 */
+
+       /* UNTRAIN_RET can clobber %rax, so preserve it */
+       movq    %rax, %rdi
         UNTRAIN_RET
+       movq    %rdi, %rax
  
         movq    PER_CPU_VAR(espfix_waddr), %rdi
         movq    %rax, (0*8)(%rdi)               /* user RAX */


But I wonder if we really need to use UNTRAIN_RET in native_irq_return_ldt because
I think we reach this point from the kernel after untrain has already be done,
and it looks like we don't do ret afterward (the code just fixup the stack and
then iret).

Thanks,

alex.

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-14 11:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-12 18:20 UNTRAIN_RET in native_irq_return_ldt Alexandre Chartre
2022-07-13  9:50 ` Peter Zijlstra
2022-07-14 11:08 ` [tip: x86/urgent] x86/entry: Remove UNTRAIN_RET from native_irq_return_ldt tip-bot2 for Alexandre Chartre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox