Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 6ddb4f3

Browse files
committed
KVM: arm64: vgic-v2: Check for non-NULL vCPU in vgic_v2_parse_attr()
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>
1 parent fec50db commit 6ddb4f3

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
@@ -338,12 +338,12 @@ int kvm_register_vgic_device(unsigned long type)
338338
int vgic_v2_parse_attr(struct kvm_device *dev, struct kvm_device_attr *attr,
339339
struct vgic_reg_attr *reg_attr)
340340
{
341-
int cpuid;
341+
int cpuid = FIELD_GET(KVM_DEV_ARM_VGIC_CPUID_MASK, attr->attr);
342342

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

348348
return 0;
349349
}

0 commit comments

Comments
 (0)