Commit c4d7c518 authored by Steven Price's avatar Steven Price Committed by Marc Zyngier

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: default avatarAlexandru Elisei <alexandru.elisei@arm.com>
Fixes: 673638f4 ("KVM: arm64: Expose KVM_ARM_CAP_MTE")
Signed-off-by: default avatarSteven Price <steven.price@arm.com>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210729160036.20433-1-steven.price@arm.com
parent facee1be
...@@ -94,10 +94,14 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, ...@@ -94,10 +94,14 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
kvm->arch.return_nisv_io_abort_to_user = true; kvm->arch.return_nisv_io_abort_to_user = true;
break; break;
case KVM_CAP_ARM_MTE: case KVM_CAP_ARM_MTE:
if (!system_supports_mte() || kvm->created_vcpus) mutex_lock(&kvm->lock);
return -EINVAL; if (!system_supports_mte() || kvm->created_vcpus) {
r = -EINVAL;
} else {
r = 0; r = 0;
kvm->arch.mte_enabled = true; kvm->arch.mte_enabled = true;
}
mutex_unlock(&kvm->lock);
break; break;
default: default:
r = -EINVAL; r = -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment