]> Git Repo - linux.git/commitdiff
KVM: arm64: Fix race when enabling KVM_ARM_CAP_MTE
authorSteven Price <[email protected]>
Thu, 29 Jul 2021 16:00:36 +0000 (17:00 +0100)
committerMarc Zyngier <[email protected]>
Thu, 29 Jul 2021 16:34:01 +0000 (17:34 +0100)
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: 673638f434ee ("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]
arch/arm64/kvm/arm.c

index e9a2b8f277922f85ed33ac4c09eefb75f7c5613c..0ca72f5cda41bbe7b52434606359c2e41bf4c95f 100644 (file)
@@ -94,10 +94,14 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
                kvm->arch.return_nisv_io_abort_to_user = true;
                break;
        case KVM_CAP_ARM_MTE:
-               if (!system_supports_mte() || kvm->created_vcpus)
-                       return -EINVAL;
-               r = 0;
-               kvm->arch.mte_enabled = true;
+               mutex_lock(&kvm->lock);
+               if (!system_supports_mte() || kvm->created_vcpus) {
+                       r = -EINVAL;
+               } else {
+                       r = 0;
+                       kvm->arch.mte_enabled = true;
+               }
+               mutex_unlock(&kvm->lock);
                break;
        default:
                r = -EINVAL;
This page took 0.064725 seconds and 4 git commands to generate.