All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: kvm@vger.kernel.org, Avi Kivity <avi@redhat.com>
Subject: Re: [PATCH 1/2] KVM: Don't fail KVM_GET_SUPPORTED_CPUID if nent is just right
Date: Thu, 24 Nov 2011 08:09:31 -0200	[thread overview]
Message-ID: <20111124100931.GA16626@amt.cnet> (raw)
In-Reply-To: <1321525125-28966-1-git-send-email-levinsasha928@gmail.com>

On Thu, Nov 17, 2011 at 12:18:44PM +0200, 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 <avi@redhat.com>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
>  arch/x86/kvm/x86.c |   12 ++++++------
>  1 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 9eff4af..460c49b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2664,7 +2664,7 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
>  		do_cpuid_ent(&cpuid_entries[nent], func, 0,
>  			     &nent, cpuid->nent);
>  	r = -E2BIG;
> -	if (nent >= cpuid->nent)
> +	if (nent > cpuid->nent)
>  		goto out_free;

"int nent" variable contains the index into the array. 
"__u32 cpuid->nent", from userspace, contains the number
of entries in the array.

So the ">=" comparison is necessary to avoid overwriting past the end of
the array.

The protocol goes like "try size x, if it fails with -E2BIG, increase x,
try again". Its awkward.


  parent reply	other threads:[~2011-11-24 10:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-17 10:18 [PATCH 1/2] KVM: Don't fail KVM_GET_SUPPORTED_CPUID if nent is just right Sasha Levin
2011-11-17 10:18 ` [PATCH 2/2] KVM: Correct documentation of KVM_GET_SUPPORTED_CPUID Sasha Levin
2011-12-04 17:37   ` Sasha Levin
2011-11-24 10:09 ` Marcelo Tosatti [this message]
2011-11-24 10:31   ` [PATCH 1/2] KVM: Don't fail KVM_GET_SUPPORTED_CPUID if nent is just right Sasha Levin
2011-11-24 10:33     ` Avi Kivity
2011-11-24 10:37       ` Sasha Levin
2011-11-24 10:45         ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111124100931.GA16626@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.