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>] [day] [month] [year] [list]
Message-ID: <5ac7a51dbcc7408d87b14be75b41f1dc@huawei.com>
Date:   Mon, 24 Feb 2020 01:44:43 +0000
From:   linmiaohe <linmiaohe@...wei.com>
To:     Sean Christopherson <sean.j.christopherson@...el.com>
CC:     "pbonzini@...hat.com" <pbonzini@...hat.com>,
        "rkrcmar@...hat.com" <rkrcmar@...hat.com>,
        "vkuznets@...hat.com" <vkuznets@...hat.com>,
        "wanpengli@...cent.com" <wanpengli@...cent.com>,
        "jmattson@...gle.com" <jmattson@...gle.com>,
        "joro@...tes.org" <joro@...tes.org>,
        "tglx@...utronix.de" <tglx@...utronix.de>,
        "mingo@...hat.com" <mingo@...hat.com>,
        "bp@...en8.de" <bp@...en8.de>, "hpa@...or.com" <hpa@...or.com>,
        "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "x86@...nel.org" <x86@...nel.org>
Subject: Re: [PATCH] KVM: X86: eliminate some meaningless code

Sean Christopherson <sean.j.christopherson@...el.com> wrote:
> On Fri, Feb 21, 2020 at 10:05:26PM +0800, linmiaohe wrote:
>> From: Miaohe Lin <linmiaohe@...wei.com>
>> 
>> When kvm_vcpu_ioctl_get_cpuid2() fails, we set cpuid->nent to the 
>> value of
>> vcpu->arch.cpuid_nent. But this is in vain as cpuid->nent is not 
>> vcpu->copied to
>> userspace by copy_to_user() from call site. Get rid of this 
>> meaningless assignment and further cleanup the var r and out jump label.
>
>Ha, took me a while to see that.

Sorry about it. I'am not good at it. :(

>>
>> On the other hand, when kvm_vcpu_ioctl_get_cpuid2() succeeds, we do 
>>  			 vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
>> -		goto out;
>> -	return 0;
>
>Hmm, so this ioctl() is straight up broken.  cpuid->nent should be updated on success so that userspace knows how many entries were retrieved, i.e.
>the code should look something like below, with kvm_arch_vcpu_ioctl() unchanged.
>
>I'm guessing no VMM actually uses this ioctl(), e.g. neither Qemu or CrosVM use it, which is why the broken behavior has gone unnoticed.  Don't suppose you'd want to write a selftest to hammer KVM_{SET,GET}_CPUID2?
>
>int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
>                              struct kvm_cpuid2 *cpuid,
>                              struct kvm_cpuid_entry2 __user *entries) {
>        if (cpuid->nent < vcpu->arch.cpuid_nent)
>                return -E2BIG;
>
>        if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
>                         vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
>                return -EFAULT;
>
>	cpuid->nent = vcpu->arch.cpuid_nent;
>
>        return 0;
>}
>

I searched KVM_GET_CPUID2 from Qemu, it's not used. So maybe we could just drop KVM_GET_CPUID2 altogether as
suggested by Paolo. Thanks for your review.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ