kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Evgeny Yakovlev <wrfsh@yandex-team.ru>, kvm@vger.kernel.org
Cc: rkrcmar@redhat.com, yc-core@yandex-team.ru
Subject: Re: [kvm-unit-tests RESEND PATCH] x86: Fix id_map buffer overflow and PT corruption
Date: Wed, 11 Sep 2019 17:37:40 +0200	[thread overview]
Message-ID: <e121f8a3-32c3-5923-1cdc-f8d96de4b59c@redhat.com> (raw)
In-Reply-To: <1566979099-23628-1-git-send-email-wrfsh@yandex-team.ru>

On 28/08/19 09:58, Evgeny Yakovlev wrote:
> Commit 18a34cce introduced init_apic_map. It iterates over
> sizeof(online_cpus) * 8 items and sets APIC ids in id_map.
> However, online_cpus is defined (in x86/cstart[64].S) as a 64-bit
> variable. After i >= 64, init_apic_map begins to read out of bounds of
> online_cpus. If it finds a non-zero value there enough times,
> it then proceeds to potentially overflow id_map in assignment.
> 
> In our test case id_map was linked close to pg_base. As a result page
> table was corrupted and we've seen sporadic failures of ioapic test.
> 
> Signed-off-by: Evgeny Yakovlev <wrfsh@yandex-team.ru>

Superseded by

[PATCH] x86: Fix out of bounds access when processing online_cpus
[PATCH] x86: Declare online_cpus based on MAX_TEST_CPUS
[PATCH] x86: Bump max number of test CPUs to 255


Thanks,

Paolo

> ---
>  lib/x86/apic.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/x86/apic.c b/lib/x86/apic.c
> index 504299e..1ed8bab 100644
> --- a/lib/x86/apic.c
> +++ b/lib/x86/apic.c
> @@ -228,14 +228,17 @@ void mask_pic_interrupts(void)
>      outb(0xff, 0xa1);
>  }
>  
> -extern unsigned char online_cpus[256 / 8];
> +/* Should hold MAX_TEST_CPUS bits */
> +extern uint64_t online_cpus;
>  
>  void init_apic_map(void)
>  {
>  	unsigned int i, j = 0;
>  
> -	for (i = 0; i < sizeof(online_cpus) * 8; i++) {
> -		if ((1ul << (i % 8)) & (online_cpus[i / 8]))
> +	assert(MAX_TEST_CPUS <= sizeof(online_cpus) * 8);
> +
> +	for (i = 0; i < MAX_TEST_CPUS; i++) {
> +		if (online_cpus & ((uint64_t)1 << i))
>  			id_map[j++] = i;
>  	}
>  }
> 


       reply	other threads:[~2019-09-11 15:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1566979099-23628-1-git-send-email-wrfsh@yandex-team.ru>
2019-09-11 15:37 ` Paolo Bonzini [this message]
2019-09-06  7:49 [kvm-unit-tests RESEND PATCH] x86: Fix id_map buffer overflow and PT corruption Evgeny Yakovlev
2019-09-06 16:27 ` Sean Christopherson
2019-09-09  9:15   ` Evgeny Yakovlev

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=e121f8a3-32c3-5923-1cdc-f8d96de4b59c@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=rkrcmar@redhat.com \
    --cc=wrfsh@yandex-team.ru \
    --cc=yc-core@yandex-team.ru \
    /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).