Skip to content

Commit c52fb3b

Browse files
committed
KVM: arm64: vgic-v2: Check for non-NULL vCPU in vgic_v2_parse_attr()
jira LE-1907 Rebuild_History Non-Buildable kernel-5.14.0-427.28.1.el9_4 commit-author Oliver Upton <oliver.upton@linux.dev> commit 6ddb4f3 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@vger.kernel.org Fixes: 7d450e2 ("KVM: arm/arm64: vgic-new: Add userland access to VGIC dist registers") Reported-by: Alexander Potapenko <glider@google.com> Tested-by: Alexander Potapenko <glider@google.com> Reviewed-by: Alexander Potapenko <glider@google.com> Reviewed-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20240424173959.3776798-2-oliver.upton@linux.dev Signed-off-by: Oliver Upton <oliver.upton@linux.dev> (cherry picked from commit 6ddb4f3) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 1735004 commit c52fb3b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/arm64/kvm/vgic/vgic-kvm-device.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ int kvm_register_vgic_device(unsigned long type)
337337
int vgic_v2_parse_attr(struct kvm_device *dev, struct kvm_device_attr *attr,
338338
struct vgic_reg_attr *reg_attr)
339339
{
340-
int cpuid;
340+
int cpuid = FIELD_GET(KVM_DEV_ARM_VGIC_CPUID_MASK, attr->attr);
341341

342-
cpuid = FIELD_GET(KVM_DEV_ARM_VGIC_CPUID_MASK, attr->attr);
343-
344-
reg_attr->vcpu = kvm_get_vcpu_by_id(dev->kvm, cpuid);
345342
reg_attr->addr = attr->attr & KVM_DEV_ARM_VGIC_OFFSET_MASK;
343+
reg_attr->vcpu = kvm_get_vcpu_by_id(dev->kvm, cpuid);
344+
if (!reg_attr->vcpu)
345+
return -EINVAL;
346346

347347
return 0;
348348
}

0 commit comments

Comments
 (0)