Skip to content

Commit 573cc0e

Browse files
Philipp Stannersean-jc
authored andcommitted
KVM: x86: Harden copying of userspace-array against overflow
cpuid.c utilizes vmemdup_user() and array_size() to copy two userspace arrays. This, currently, does not check for an overflow. Use the new wrapper vmemdup_array_user() to copy the arrays more safely, as vmemdup_user() doesn't check for overflow. Note, KVM explicitly checks the number of entries before duplicating the array, i.e. adding the overflow check should be a glorified nop. Suggested-by: Dave Airlie <airlied@redhat.com> Signed-off-by: Philipp Stanner <pstanner@redhat.com> Link: https://lore.kernel.org/r/20231102181526.43279-2-pstanner@redhat.com [sean: call out that KVM pre-checks the number of entries] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 6391224 commit 573cc0e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
469469
return -E2BIG;
470470

471471
if (cpuid->nent) {
472-
e = vmemdup_user(entries, array_size(sizeof(*e), cpuid->nent));
472+
e = vmemdup_array_user(entries, cpuid->nent, sizeof(*e));
473473
if (IS_ERR(e))
474474
return PTR_ERR(e);
475475

@@ -513,7 +513,7 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
513513
return -E2BIG;
514514

515515
if (cpuid->nent) {
516-
e2 = vmemdup_user(entries, array_size(sizeof(*e2), cpuid->nent));
516+
e2 = vmemdup_array_user(entries, cpuid->nent, sizeof(*e2));
517517
if (IS_ERR(e2))
518518
return PTR_ERR(e2);
519519
}

0 commit comments

Comments
 (0)