Skip to content

Commit c4d7c51

Browse files
Steven PriceMarc Zyngier
authored andcommitted
KVM: arm64: Fix race when enabling KVM_ARM_CAP_MTE
When enabling KVM_CAP_ARM_MTE the ioctl checks that there are no VCPUs created to ensure that the capability is enabled before the VM is running. However no locks are held at that point so it is (theoretically) possible for another thread in the VMM to create VCPUs between the check and actually setting mte_enabled. Close the race by taking kvm->lock. Reported-by: Alexandru Elisei <[email protected]> Fixes: 673638f ("KVM: arm64: Expose KVM_ARM_CAP_MTE") Signed-off-by: Steven Price <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent facee1b commit c4d7c51

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

arch/arm64/kvm/arm.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,14 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
9494
kvm->arch.return_nisv_io_abort_to_user = true;
9595
break;
9696
case KVM_CAP_ARM_MTE:
97-
if (!system_supports_mte() || kvm->created_vcpus)
98-
return -EINVAL;
99-
r = 0;
100-
kvm->arch.mte_enabled = true;
97+
mutex_lock(&kvm->lock);
98+
if (!system_supports_mte() || kvm->created_vcpus) {
99+
r = -EINVAL;
100+
} else {
101+
r = 0;
102+
kvm->arch.mte_enabled = true;
103+
}
104+
mutex_unlock(&kvm->lock);
101105
break;
102106
default:
103107
r = -EINVAL;

0 commit comments

Comments
 (0)