lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230410141820.57328-1-itazur@amazon.com>
Date:   Mon, 10 Apr 2023 15:18:20 +0100
From:   Takahiro Itazuri <itazur@...zon.com>
To:     <kvm@...r.kernel.org>
CC:     Sean Christopherson <seanjc@...gle.com>,
        Paolo Bonzini <pbonzini@...hat.com>,
        <linux-kernel@...r.kernel.org>,
        Takahiro Itazuri <zulinx86@...il.com>,
        Takahiro Itazuri <itazur@...zon.com>
Subject: [PATCH] kvm: x86: Update KVM_GET_CPUID2 to return valid entry count

Modify the KVM_GET_CPUID2 API to return the number of valid entries in
nent field of kvm_cpuid2, even when the API is successful.

Previously, the KVM_GET_CPUID2 API only updated the nent field when an
error was returned. If the API was called with an entry count larger
than necessary (e.g., KVM_MAX_CPUID_ENTRIES), it would succeed, but the
nent field would continue to show a value larger than the actual number
of entries filled by the KVM_GET_CPUID2 API. With this change, users can
rely on the updated nent field and there is no need to traverse
unnecessary entries and check whether an entry is valid or not.

Signed-off-by: Takahiro Itazuri <itazur@...zon.com>
---
 arch/x86/kvm/cpuid.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 599aebec2d52..31838dfddda6 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -523,10 +523,13 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
 			      struct kvm_cpuid2 *cpuid,
 			      struct kvm_cpuid_entry2 __user *entries)
 {
-	int r;
+	int nent, r;
+
+	nent = cpuid->nent;
+	cpuid->nent = vcpu->arch.cpuid_nent;
 
 	r = -E2BIG;
-	if (cpuid->nent < vcpu->arch.cpuid_nent)
+	if (nent < vcpu->arch.cpuid_nent)
 		goto out;
 	r = -EFAULT;
 	if (copy_to_user(entries, vcpu->arch.cpuid_entries,
@@ -535,7 +538,6 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
 	return 0;
 
 out:
-	cpuid->nent = vcpu->arch.cpuid_nent;
 	return r;
 }
 
-- 
2.39.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ