diff options
author | Sean Christopherson <sean.j.christopherson@intel.com> | 2020-03-03 00:56:08 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-03-16 17:57:57 +0100 |
commit | 0fc62671876c29a80c16d41cbce782ff10795bef (patch) | |
tree | dbd82c8956f872b326b101d1bbbfd75af3e26025 /arch/x86/kvm/cpuid.c | |
parent | KVM: x86: Clean up error handling in kvm_dev_ioctl_get_cpuid() (diff) | |
download | linux-0fc62671876c29a80c16d41cbce782ff10795bef.tar.xz linux-0fc62671876c29a80c16d41cbce782ff10795bef.zip |
KVM: x86: Check userspace CPUID array size after validating sub-leaf
Verify that the next sub-leaf of CPUID 0x4 (or 0x8000001d) is valid
before rejecting the entire KVM_GET_SUPPORTED_CPUID due to insufficent
space in the userspace array.
Note, although this is technically a bug, it's not visible to userspace
as KVM_GET_SUPPORTED_CPUID is guaranteed to fail on KVM_CPUID_SIGNATURE,
which is hardcoded to be added after the affected leafs. The real
motivation for the change is to tightly couple the nent/maxnent and
do_host_cpuid() sequences in preparation for future cleanup.
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to '')
-rw-r--r-- | arch/x86/kvm/cpuid.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 11d5f311ef10..e5cf1e0cf84a 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -552,12 +552,12 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, /* read more entries until cache_type is zero */ for (i = 1; ; ++i) { - if (*nent >= maxnent) - goto out; - cache_type = entry[i - 1].eax & 0x1f; if (!cache_type) break; + + if (*nent >= maxnent) + goto out; do_host_cpuid(&entry[i], function, i); ++*nent; } |