From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: Re: [PATCH v2] KVM: Don't fail KVM_GET_SUPPORTED_CPUID if nent is just right Date: Thu, 24 Nov 2011 13:53:42 +0200 Message-ID: <1322135622.4248.17.camel@lappy> References: <1322131547-8330-1-git-send-email-levinsasha928@gmail.com> <4ECE20EA.4060701@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Marcelo Tosatti To: Avi Kivity Return-path: Received: from mail-bw0-f46.google.com ([209.85.214.46]:39998 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750735Ab1KXLxq (ORCPT ); Thu, 24 Nov 2011 06:53:46 -0500 Received: by bke11 with SMTP id 11so2836527bke.19 for ; Thu, 24 Nov 2011 03:53:45 -0800 (PST) In-Reply-To: <4ECE20EA.4060701@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Thu, 2011-11-24 at 12:48 +0200, Avi Kivity wrote: > On 11/24/2011 12:45 PM, Sasha Levin wrote: > > If we pass just enough entries to KVM_GET_SUPPORTED_CPUID, we would still > > fail with -E2BIG due to wrong comparisons. > > > > Cc: Avi Kivity > > Cc: Marcelo Tosatti > > Signed-off-by: Sasha Levin > > --- > > arch/x86/kvm/x86.c | 2 +- > > 1 files changed, 1 insertions(+), 1 deletions(-) > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 9eff4af..83fef71 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -2710,7 +2710,7 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, > > cpuid->nent); > > > > r = -E2BIG; > > - if (nent >= cpuid->nent) > > + if (nent > cpuid->nent) > > goto out_free; > > > > > > This is just a landmine for the next entry to be added there; surely > whoever adds it will forget to correct the > back to >=. > Slapping a big warning before that should do the trick? Or maybe add something similar to 'final_nent = nent - 1;'? -- Sasha.