Skip to content

Commit 9f0748b

Browse files
committed
Merge: CVE-2024-58083: KVM: Explicitly verify target vCPU is online in kvm_get_vcpu()
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6541 JIRA: https://issues.redhat.com/browse/RHEL-82650 CVE: CVE-2024-58083 ``` commit 1e7381f Author: Sean Christopherson <seanjc@google.com> Date: Wed Oct 9 08:04:50 2024 -0700 KVM: Explicitly verify target vCPU is online in kvm_get_vcpu() Explicitly verify the target vCPU is fully online _prior_ to clamping the index in kvm_get_vcpu(). If the index is "bad", the nospec clamping will generate '0', i.e. KVM will return vCPU0 instead of NULL. In practice, the bug is unlikely to cause problems, as it will only come into play if userspace or the guest is buggy or misbehaving, e.g. KVM may send interrupts to vCPU0 instead of dropping them on the floor. However, returning vCPU0 when it shouldn't exist per online_vcpus is problematic now that KVM uses an xarray for the vCPUs array, as KVM needs to insert into the xarray before publishing the vCPU to userspace (see commit c5b0775 ("KVM: Convert the kvm->vcpus array to a xarray")), i.e. before vCPU creation is guaranteed to succeed. As a result, incorrectly providing access to vCPU0 will trigger a use-after-free if vCPU0 is dereferenced and kvm_vm_ioctl_create_vcpu() bails out of vCPU creation due to an error and frees vCPU0. Commit afb2acb ("KVM: Fix vcpu_array[0] races") papered over that issue, but in doing so introduced an unsolvable teardown conundrum. Preventing accesses to vCPU0 before it's fully online will allow reverting commit afb2acb, without re-introducing the vcpu_array[0] UAF race. Fixes: 1d487e9 ("KVM: fix spectrev1 gadgets") Cc: stable@vger.kernel.org Cc: Will Deacon <will@kernel.org> Cc: Michal Luczaj <mhal@rbox.co> Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com> Acked-by: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20241009150455.1057573-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>``` Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com> --- <small>Created 2025-03-07 11:50 UTC by backporter - [KWF FAQ](https://red.ht/kernel_workflow_doc) - [Slack #team-kernel-workflow](https://redhat-internal.slack.com/archives/C04LRUPMJQ5) - [Source](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/webhook/utils/backporter.py) - [Documentation](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/docs/README.backporter.md) - [Report an issue](https://gitlab.com/cki-project/kernel-workflow/-/issues/new?issue%5Btitle%5D=backporter%20webhook%20issue)</small> Approved-by: Jon Maloy <jmaloy@redhat.com> Approved-by: Leonardo Brás <leobras@redhat.com> Approved-by: Vitaly Kuznetsov <vkuznets@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Augusto Caringi <acaringi@redhat.com>
2 parents 350b822 + fc587d9 commit 9f0748b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

include/linux/kvm_host.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,15 @@ static inline struct kvm_io_bus *kvm_get_bus(struct kvm *kvm, enum kvm_bus idx)
955955
static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
956956
{
957957
int num_vcpus = atomic_read(&kvm->online_vcpus);
958+
959+
/*
960+
* Explicitly verify the target vCPU is online, as the anti-speculation
961+
* logic only limits the CPU's ability to speculate, e.g. given a "bad"
962+
* index, clamping the index to 0 would return vCPU0, not NULL.
963+
*/
964+
if (i >= num_vcpus)
965+
return NULL;
966+
958967
i = array_index_nospec(i, num_vcpus);
959968

960969
/* Pairs with smp_wmb() in kvm_vm_ioctl_create_vcpu. */

0 commit comments

Comments
 (0)