KVM: x86: No lock protection was applied in handle_ept_misconfig of kernel 5.10?
Hi all,
I noticed that in handle_ept_misconfig(), kvm_io_bus_write() is called. And within kvm_io_bus_write(), BUS is obtained through srcu_dereference(). During this process, kvm->slots_lock is not acquired, nor is srcu_read_lock() called for protection. If another process is synchronizing BUS at the same time, synchronize_srcu_expedited() cannot safely reclaim space(it cannot protect srcu_dereference() outside the critical section?), how can we ensure that BUS obtained by kvm_io_bus_write() is the latest?
Thanks,
Junjie Cai
Reported by: Junjie Cai <[email protected]>
Sean Christopherson
reviewerQuoted 6 lines · zoudongjie (A)
Hi all,
I noticed that in
handle_ept_misconfig(),kvm_io_bus_write()is called. And withinkvm_io_bus_write(), BUS is obtained throughsrcu_dereference(). During this process,kvm->slots_lockis not acquired, nor issrcu_read_lock()called for protection.
srcu_read_lock() is called via kvm_vcpu_srcu_read_lock() in the VM-Exit path of vcpu_enter_guest(). KVM grabs kvm->srcu early during KVM_RUN (again via kvm_vcpu_srcu_read_lock(), in kvm_arch_vcpu_ioctl_run()), and holds the lock for essentially the entire duration of KVM_RUN. SRCU protection is temporarily dropped only when the vCPU blocks and when the vCPU enters the guest.
Quoted 9 lines
If another process is synchronizing BUS at the same time,
synchronize_srcu_expedited()cannot safely reclaimspace(it cannot protect srcu_dereference() outside the critical section?), how can we ensure that BUS obtained bykvm_io_bus_write()is the latest?Thanks,
Junjie CaiReported by: Junjie Cai <[email protected]>