linux-stable/arch
Sean Christopherson a9bd6bb6f0 KVM: x86: Mark target gfn of emulated atomic instruction as dirty
commit 910c57dfa4 upstream.

When emulating an atomic access on behalf of the guest, mark the target
gfn dirty if the CMPXCHG by KVM is attempted and doesn't fault.  This
fixes a bug where KVM effectively corrupts guest memory during live
migration by writing to guest memory without informing userspace that the
page is dirty.

Marking the page dirty got unintentionally dropped when KVM's emulated
CMPXCHG was converted to do a user access.  Before that, KVM explicitly
mapped the guest page into kernel memory, and marked the page dirty during
the unmap phase.

Mark the page dirty even if the CMPXCHG fails, as the old data is written
back on failure, i.e. the page is still written.  The value written is
guaranteed to be the same because the operation is atomic, but KVM's ABI
is that all writes are dirty logged regardless of the value written.  And
more importantly, that's what KVM did before the buggy commit.

Huge kudos to the folks on the Cc list (and many others), who did all the
actual work of triaging and debugging.

Fixes: 1c2361f667 ("KVM: x86: Use __try_cmpxchg_user() to emulate atomic accesses")
Cc: stable@vger.kernel.org
Cc: David Matlack <dmatlack@google.com>
Cc: Pasha Tatashin <tatashin@google.com>
Cc: Michael Krebs <mkrebs@google.com>
base-commit: 6769ea8da8a93ed4630f1ce64df6aafcaabfce64
Reviewed-by: Jim Mattson <jmattson@google.com>
Link: https://lore.kernel.org/r/20240215010004.1456078-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-10 16:19:37 +02:00
..
alpha alpha: remove __init annotation from exported page_is_ram() 2023-08-16 18:22:03 +02:00
arc ARC: fix spare error 2024-01-25 14:52:30 -08:00
arm arm: dts: marvell: Fix maxium->maxim typo in brownstone dts 2024-04-10 16:18:34 +02:00
arm64 arm64: dts: qcom: sc7180-trogdor: mark bluetooth address as broken 2024-04-10 16:19:36 +02:00
csky arch: consolidate arch_irq_work_raise prototypes 2024-02-23 08:54:39 +01:00
h8300
hexagon hexagon: vmlinux.lds.S: handle attributes section 2024-04-10 16:19:31 +02:00
ia64 arch: Introduce CONFIG_FUNCTION_ALIGNMENT 2024-04-10 16:18:49 +02:00
m68k memblock: allow to specify flags with memblock_add_node() 2023-12-20 15:17:33 +01:00
microblaze
mips MIPS: Clear Cause.BD in instruction_pointer_set 2024-03-26 18:21:12 -04:00
nds32
nios2 nios2: dts: Fix tse_mac "max-frame-size" property 2023-06-21 15:59:14 +02:00
openrisc openrisc: Properly store r31 to pt_regs on unhandled exceptions 2023-05-11 23:00:37 +09:00
parisc parisc: Strip upper 32 bit of sum in csum_ipv6_magic for 64-bit builds 2024-04-10 16:18:36 +02:00
powerpc powerpc: xor_vmx: Add '-mhard-float' to CFLAGS 2024-04-10 16:19:30 +02:00
riscv riscv: dts: sifive: add missing #interrupt-cells to pmic 2024-03-26 18:21:12 -04:00
s390 s390/vtime: fix average steal time calculation 2024-03-26 18:21:35 -04:00
sh sh: bios: Revive earlyprintk support 2023-11-20 11:08:23 +01:00
sparc sparc: vDSO: fix return value of __setup handler 2024-04-10 16:18:34 +02:00
um um: time-travel: fix time corruption 2024-02-23 08:54:50 +01:00
x86 KVM: x86: Mark target gfn of emulated atomic instruction as dirty 2024-04-10 16:19:37 +02:00
xtensa xtensa: boot/lib: fix function prototypes 2023-10-06 13:18:14 +02:00
.gitignore
Kconfig arch: Introduce CONFIG_FUNCTION_ALIGNMENT 2024-04-10 16:18:49 +02:00