[PW_SID:1098830] RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler#1990
[PW_SID:1098830] RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler#1990linux-riscv-bot wants to merge 2 commits into
Conversation
The SBI SUSP handler kvm_sbi_ext_susp_handler() checks that all other vCPUs are stopped before entering system suspend, but it does not hold mp_state_lock during the iteration. A concurrent HSM HART_START from another vCPU can start a target vCPU after the SUSP handler has already checked it, violating the invariant that all vCPUs must be stopped before suspend. Fix this with a two-phase approach: 1. Set a VM-wide suspend_in_progress flag before the iteration to block concurrent HSM HART_START. The HSM start handler checks this flag under its existing mp_state_lock, closing the race. 2. Hold mp_state_lock during each per-vCPU stopped check so that mp_state reads are ordered against concurrent power_on/power_off writes on the other side of the lock. The flag is self-clearing: it resets when any vCPU re-enters kvm_arch_vcpu_ioctl_run after the suspend-resume cycle completes. Fixes: 023c151 ("RISC-V: KVM: Add SBI system suspend support") Signed-off-by: Jiakai Xu <jiakaiPeanut@gmail.com> Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn> Assisted-by: YuanSheng:DeepSeek-V3.2 Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
|
Patch 1: "RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler" |
a1231b7 to
c03cdce
Compare
PR for series 1098830 applied to workflow__riscv__fixes
Name: RISC-V: KVM: Fix TOCTOU race in SBI system suspend handler
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1098830
Version: 1