linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Wanpeng Li <kernellwp@gmail.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: "Radim Krčmář" <rkrcmar@redhat.com>,
	"Wanpeng Li" <wanpeng.li@hotmail.com>,
	Moguofang <moguofang@huawei.com>
Subject: Re: [PATCH] KVM: cpuid: Fix read/write out-of-bounds vulnerability in cpuid emulation
Date: Wed, 7 Jun 2017 14:55:05 +0200	[thread overview]
Message-ID: <f8c7f463-9ce1-d57c-6c72-3c4b10c4347b@redhat.com> (raw)
In-Reply-To: <1496838615-8532-1-git-send-email-wanpeng.li@hotmail.com>



On 07/06/2017 14:30, Wanpeng Li wrote:
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index a181ae7..b927a42 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -779,19 +779,20 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
>  
>  static int move_to_next_stateful_cpuid_entry(struct kvm_vcpu *vcpu, int i)
>  {
> +	int j = i, nent = vcpu->arch.cpuid_nent;
>  	struct kvm_cpuid_entry2 *e = &vcpu->arch.cpuid_entries[i];
> -	int j, nent = vcpu->arch.cpuid_nent;
> +	struct kvm_cpuid_entry2 *ej;
>  
>  	e->flags &= ~KVM_CPUID_FLAG_STATE_READ_NEXT;
>  	/* when no next entry is found, the current entry[i] is reselected */
> -	for (j = i + 1; ; j = (j + 1) % nent) {
> -		struct kvm_cpuid_entry2 *ej = &vcpu->arch.cpuid_entries[j];
> -		if (ej->function == e->function) {

It reads ej->maxphyaddr, which is user controlled.

> -			ej->flags |= KVM_CPUID_FLAG_STATE_READ_NEXT;

After cpuid_entries there is

        int maxphyaddr;
        struct x86_emulate_ctxt emulate_ctxt;  /* 16-byte aligned */

So indeed we have:

- cpuid_entries at offset 1B50 (6992)
- maxphyaddr at offset 27D0 (6992 + 3200 = 10192)
- padding at 27D4...27DF
- emulate_ctxt at 27E0

So this indeed writes in the padding.  Pfew, writing the ops field of
emulate_ctxt would have been much worse.

Thanks,

Paolo

> -			return j;
> -		}
> -	}
> -	return 0; /* silence gcc, even though control never reaches here */
> +	do {
> +		j = (j + 1) % nent;
> +		ej = &vcpu->arch.cpuid_entries[j];
> +	} while(ej->function != e->function);
> +
> +	ej->flags |= KVM_CPUID_FLAG_STATE_READ_NEXT;
> +
> +	return j;
>  }
>  
>  /* find an entry with matching function, matching index (if needed), and that
> 

      reply	other threads:[~2017-06-07 12:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-07 12:30 [PATCH] KVM: cpuid: Fix read/write out-of-bounds vulnerability in cpuid emulation Wanpeng Li
2017-06-07 12:55 ` Paolo Bonzini [this message]

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=f8c7f463-9ce1-d57c-6c72-3c4b10c4347b@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=moguofang@huawei.com \
    --cc=rkrcmar@redhat.com \
    --cc=wanpeng.li@hotmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).