]> git.baikalelectronics.ru Git - kernel.git/commit
x86/xen: Add xenpv_restore_regs_and_return_to_usermode()
authorLai Jiangshan <laijs@linux.alibaba.com>
Fri, 26 Nov 2021 10:11:23 +0000 (18:11 +0800)
committerBorislav Petkov <bp@suse.de>
Fri, 3 Dec 2021 18:21:15 +0000 (19:21 +0100)
commit0b0ca0fd5c680e2b0dcc4204ecfaba1216748c52
treeaf181fe3385b6f16e32938c3f537134bd5d4706e
parent88d1548f8cce4c922f6167c18943195df0e97d8e
x86/xen: Add xenpv_restore_regs_and_return_to_usermode()

In the native case, PER_CPU_VAR(cpu_tss_rw + TSS_sp0) is the
trampoline stack. But XEN pv doesn't use trampoline stack, so
PER_CPU_VAR(cpu_tss_rw + TSS_sp0) is also the kernel stack.

In that case, source and destination stacks are identical, which means
that reusing swapgs_restore_regs_and_return_to_usermode() in XEN pv
would cause %rsp to move up to the top of the kernel stack and leave the
IRET frame below %rsp.

This is dangerous as it can be corrupted if #NMI / #MC hit as either of
these events occurring in the middle of the stack pushing would clobber
data on the (original) stack.

And, with  XEN pv, swapgs_restore_regs_and_return_to_usermode() pushing
the IRET frame on to the original address is useless and error-prone
when there is any future attempt to modify the code.

 [ bp: Massage commit message. ]

Fixes: a70e6a0fb8d2 ("x86/entry/64: Use a per-CPU trampoline stack for IDT entries")
Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Link: https://lkml.kernel.org/r/20211126101209.8613-4-jiangshanlai@gmail.com
arch/x86/entry/entry_64.S
arch/x86/xen/xen-asm.S