From: Sean Christopherson <sean.j.christopherson@intel.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>
Cc: kvm@vger.kernel.org, Evgeny Yakovlev <wrfsh@yandex-team.ru>
Subject: [kvm-unit-tests PATCH 1/3] x86: Fix out of bounds access when processing online_cpus
Date: Fri, 6 Sep 2019 09:34:48 -0700 [thread overview]
Message-ID: <20190906163450.30797-2-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20190906163450.30797-1-sean.j.christopherson@intel.com>
online_cpus is misdeclared as a 64 *byte* variable instead of a 64 *bit*
variable. This causes init_apic_map() to test random bytes when it
iterates over online_cpus, which in turn can cause it to overflow id_map
and corrupt rnadom memory, e.g. pg_base. Declare online_cpus using
MAX_TEST_CPUS, which presumably is set explicitly to match the storage
size of online_cpus (64-bit values == max of 64 CPUS).
Reported-by: Evgeny Yakovlev <wrfsh@yandex-team.ru>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
lib/x86/apic.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/x86/apic.c b/lib/x86/apic.c
index b3e39ae..f43e9ef 100644
--- a/lib/x86/apic.c
+++ b/lib/x86/apic.c
@@ -232,13 +232,13 @@ void mask_pic_interrupts(void)
outb(0xff, 0xa1);
}
-extern unsigned char online_cpus[256 / 8];
+extern unsigned char online_cpus[MAX_TEST_CPUS / 8];
void init_apic_map(void)
{
unsigned int i, j = 0;
- for (i = 0; i < sizeof(online_cpus) * 8; i++) {
+ for (i = 0; i < MAX_TEST_CPUS; i++) {
if ((1ul << (i % 8)) & (online_cpus[i / 8]))
id_map[j++] = i;
}
--
2.22.0
next prev parent reply other threads:[~2019-09-06 16:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-06 16:34 [kvm-unit-tests PATCH 0/3] x86: Cleanup max test CPUs Sean Christopherson
2019-09-06 16:34 ` Sean Christopherson [this message]
2019-09-06 16:34 ` [kvm-unit-tests PATCH 2/3] x86: Declare online_cpus based on MAX_TEST_CPUS Sean Christopherson
2019-09-06 16:34 ` [kvm-unit-tests PATCH 3/3] x86: Bump max number of test CPUs to 255 Sean Christopherson
2019-09-10 14:46 ` Paolo Bonzini
2019-09-10 7:57 ` [kvm-unit-tests PATCH 0/3] x86: Cleanup max test CPUs Peter Xu
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=20190906163450.30797-2-sean.j.christopherson@intel.com \
--to=sean.j.christopherson@intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=wrfsh@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).