linux-stable/arch/x86
Paolo Bonzini 8771d9673e KVM: x86/mmu: do compare-and-exchange of gPTE via the user address
commit 2a8859f373 upstream.

FNAME(cmpxchg_gpte) is an inefficient mess.  It is at least decent if it
can go through get_user_pages_fast(), but if it cannot then it tries to
use memremap(); that is not just terribly slow, it is also wrong because
it assumes that the VM_PFNMAP VMA is contiguous.

The right way to do it would be to do the same thing as
hva_to_pfn_remapped() does since commit add6a0cd1c ("KVM: MMU: try to
fix up page faults before giving up", 2016-07-05), using follow_pte()
and fixup_user_fault() to determine the correct address to use for
memremap().  To do this, one could for example extract hva_to_pfn()
for use outside virt/kvm/kvm_main.c.  But really there is no reason to
do that either, because there is already a perfectly valid address to
do the cmpxchg() on, only it is a userspace address.  That means doing
user_access_begin()/user_access_end() and writing the code in assembly
to handle exceptions correctly.  Worse, the guest PTE can be 8-byte
even on i686 so there is the extra complication of using cmpxchg8b to
account for.  But at least it is an efficient mess.

(Thanks to Linus for suggesting improvement on the inline assembly).

Reported-by: Qiuhao Li <qiuhao@sysec.org>
Reported-by: Gaoning Pan <pgn@zju.edu.cn>
Reported-by: Yongkang Jia <kangel@zju.edu.cn>
Reported-by: syzbot+6cde2282daa792c49ab8@syzkaller.appspotmail.com
Debugged-by: Tadeusz Struk <tadeusz.struk@linaro.org>
Tested-by: Maxim Levitsky <mlevitsk@redhat.com>
Cc: stable@vger.kernel.org
Fixes: bd53cb35a3 ("X86/KVM: Handle PFNs outside of kernel reach when touching GPTEs")
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-04-08 14:24:17 +02:00
..
boot x86/boot/compressed: Move CLANG_FLAGS to beginning of KBUILD_CFLAGS 2022-01-27 11:03:47 +01:00
configs x86/kbuild: Enable CONFIG_KALLSYMS_ALL=y in the defconfigs 2022-01-27 11:04:56 +01:00
crypto crypto: x86/aesni - don't require alignment of data 2022-01-27 11:02:51 +01:00
entry x86/xen: Add xenpv_restore_regs_and_return_to_usermode() 2021-12-08 09:04:54 +01:00
events perf/x86/intel/pt: Fix address filter config for 32-bit kernel 2022-04-08 14:23:11 +02:00
hyperv x86/hyperv: Properly deal with empty cpumasks in hyperv_flush_tlb_multi() 2022-03-08 19:12:36 +01:00
ia32 binfmt: remove in-tree usage of MAP_DENYWRITE 2021-09-03 18:42:01 +02:00
include x86/speculation: Add eIBRS + Retpoline options 2022-03-11 12:22:31 +01:00
kernel KVM: x86: fix sending PV IPI 2022-04-08 14:24:07 +02:00
kvm KVM: x86/mmu: do compare-and-exchange of gPTE via the user address 2022-04-08 14:24:17 +02:00
lib x86/speculation: Rename RETPOLINE_AMD to RETPOLINE_LFENCE 2022-03-11 12:22:31 +01:00
math-emu x86/math-emu: Rename frstor() 2021-06-23 18:16:33 +02:00
mm x86/boot: Add setup_indirect support in early_memremap_is_setup_data() 2022-03-16 14:23:45 +01:00
net bpf: Fix extable address check. 2021-12-22 09:32:50 +01:00
pci PCI/sysfs: Find shadow ROM before static attribute initialization 2022-02-01 17:27:05 +01:00
platform x86/sme: Explicitly map new EFI memmap table as encrypted 2021-12-14 10:57:08 +01:00
power x86/power: Fix kernel-doc warnings in cpu.c 2021-08-12 10:15:40 +02:00
purgatory kernel.h: split out panic and oops helpers 2021-07-01 11:06:04 -07:00
ras
realmode x86/mm: Flush global TLB when switching to trampoline page-table 2022-01-27 11:04:35 +01:00
tools - Remove cc-option checks which are old and already supported by the 2021-08-30 13:27:16 -07:00
um um: registers: Rename function names to avoid conflicts and build problems 2022-01-27 11:04:48 +01:00
video
xen xen: fix is_xen_pmu() 2022-04-08 14:23:52 +02:00
.gitignore
Kbuild
Kconfig x86/sme: Explicitly map new EFI memmap table as encrypted 2021-12-14 10:57:08 +01:00
Kconfig.assembler
Kconfig.cpu
Kconfig.debug tracing: Refactor TRACE_IRQFLAGS_SUPPORT in Kconfig 2021-08-16 11:37:21 -04:00
Makefile Kbuild updates for v5.15 2021-09-03 15:33:47 -07:00
Makefile.um um: allow not setting extra rpaths in the linux binary 2021-06-17 21:54:15 +02:00
Makefile_32.cpu x86/build: Do not add -falign flags unconditionally for clang 2021-09-19 10:35:53 +09:00