From: Cornelia Huck <cohuck@redhat.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>,
Janosch Frank <frankja@linux.ibm.com>,
Paolo Bonzini <pbonzini@redhat.com>,
David Hildenbrand <david@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+d889b59b2bb87d4047a2@syzkaller.appspotmail.com
Subject: Re: [PATCH 1/2] KVM: Check validity of resolved slot when searching memslots
Date: Wed, 8 Apr 2020 09:04:36 +0200 [thread overview]
Message-ID: <20200408090436.2bd1f303.cohuck@redhat.com> (raw)
In-Reply-To: <20200408064059.8957-2-sean.j.christopherson@intel.com>
On Tue, 7 Apr 2020 23:40:58 -0700
Sean Christopherson <sean.j.christopherson@intel.com> wrote:
> Check that the resolved slot (somewhat confusingly named 'start') is a
> valid/allocated slot before doing the final comparison to see if the
> specified gfn resides in the associated slot. The resolved slot can be
> invalid if the binary search loop terminated because the search index
> was incremented beyond the number of used slots.
>
> This bug has existed since the binary search algorithm was introduced,
> but went unnoticed because KVM statically allocated memory for the max
> number of slots, i.e. the access would only be truly out-of-bounds if
> all possible slots were allocated and the specified gfn was less than
> the base of the lowest memslot. Commit 36947254e5f98 ("KVM: Dynamically
> size memslot array based on number of used slots") eliminated the "all
> possible slots allocated" condition and made the bug embarrasingly easy
> to hit.
>
> Fixes: 9c1a5d38780e6 ("kvm: optimize GFN to memslot lookup with large slots amount")
> Reported-by: syzbot+d889b59b2bb87d4047a2@syzkaller.appspotmail.com
> Cc: stable@vger.kernel.org
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
> include/linux/kvm_host.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 6d58beb65454..01276e3d01b9 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -1048,7 +1048,7 @@ search_memslots(struct kvm_memslots *slots, gfn_t gfn)
> start = slot + 1;
> }
>
> - if (gfn >= memslots[start].base_gfn &&
> + if (start < slots->used_slots && gfn >= memslots[start].base_gfn &&
> gfn < memslots[start].base_gfn + memslots[start].npages) {
> atomic_set(&slots->lru_slot, start);
> return &memslots[start];
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
next prev parent reply other threads:[~2020-04-08 7:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-08 6:40 [PATCH 0/2] KVM: Fix out-of-bounds memslot access Sean Christopherson
2020-04-08 6:40 ` [PATCH 1/2] KVM: Check validity of resolved slot when searching memslots Sean Christopherson
2020-04-08 7:04 ` Cornelia Huck [this message]
2020-04-08 6:40 ` [PATCH 2/2] KVM: s390: Return last valid slot if approx index is out-of-bounds Sean Christopherson
2020-04-08 7:10 ` Cornelia Huck
2020-04-08 9:08 ` Paolo Bonzini
2020-04-08 7:28 ` Christian Borntraeger
2020-04-08 10:21 ` Claudio Imbrenda
2020-04-08 11:33 ` Paolo Bonzini
2020-04-08 11:40 ` Christian Borntraeger
2020-04-08 6:55 ` [PATCH 0/2] KVM: Fix out-of-bounds memslot access Christian Borntraeger
2020-04-08 7:24 ` Christian Borntraeger
2020-04-08 8:10 ` Cornelia Huck
2020-04-08 14:23 ` Sean Christopherson
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=20200408090436.2bd1f303.cohuck@redhat.com \
--to=cohuck@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=david@redhat.com \
--cc=frankja@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=syzbot+d889b59b2bb87d4047a2@syzkaller.appspotmail.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.