[SRU][F][PATCH 1/1] KVM: arm64: vgic-v2: Check for non-NULL vCPU in vgic_v2_parse_attr()
Massimiliano Pellizzer
massimiliano.pellizzer at canonical.com
Thu Sep 26 15:13:09 UTC 2024
From: Oliver Upton <oliver.upton at linux.dev>
[ Upstream commit 6ddb4f372fc63210034b903d96ebbeb3c7195adb ]
vgic_v2_parse_attr() is responsible for finding the vCPU that matches
the user-provided CPUID, which (of course) may not be valid. If the ID
is invalid, kvm_get_vcpu_by_id() returns NULL, which isn't handled
gracefully.
Similar to the GICv3 uaccess flow, check that kvm_get_vcpu_by_id()
actually returns something and fail the ioctl if not.
Cc: stable at vger.kernel.org
Fixes: 7d450e282171 ("KVM: arm/arm64: vgic-new: Add userland access to VGIC dist registers")
Reported-by: Alexander Potapenko <glider at google.com>
Tested-by: Alexander Potapenko <glider at google.com>
Reviewed-by: Alexander Potapenko <glider at google.com>
Reviewed-by: Marc Zyngier <maz at kernel.org>
Link: https://lore.kernel.org/r/20240424173959.3776798-2-oliver.upton@linux.dev
Signed-off-by: Oliver Upton <oliver.upton at linux.dev>
Signed-off-by: Sasha Levin <sashal at kernel.org>
(backported from commit 4404465a1bee3607ad90a4c5f9e16dfd75b85728 linux-5.10.y)
[mpellizzer: backported applying the patch to virt/kvm/arm/vgic/vgic-kvm-device.c
and solving the merge conflicts due to different context]
CVE-2024-36953
Signed-off-by: Massimiliano Pellizzer <massimiliano.pellizzer at canonical.com>
---
virt/kvm/arm/vgic/vgic-kvm-device.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/virt/kvm/arm/vgic/vgic-kvm-device.c b/virt/kvm/arm/vgic/vgic-kvm-device.c
index 5eaede3e3b5a..9497e8368b90 100644
--- a/virt/kvm/arm/vgic/vgic-kvm-device.c
+++ b/virt/kvm/arm/vgic/vgic-kvm-device.c
@@ -289,8 +289,10 @@ int vgic_v2_parse_attr(struct kvm_device *dev, struct kvm_device_attr *attr,
if (cpuid >= atomic_read(&dev->kvm->online_vcpus))
return -EINVAL;
- reg_attr->vcpu = kvm_get_vcpu(dev->kvm, cpuid);
reg_attr->addr = attr->attr & KVM_DEV_ARM_VGIC_OFFSET_MASK;
+ reg_attr->vcpu = kvm_get_vcpu(dev->kvm, cpuid);
+ if (!reg_attr->vcpu)
+ return -EINVAL;
return 0;
}
--
2.43.0
More information about the kernel-team
mailing list