All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roel Kluin <roel.kluin@gmail.com>
To: Avi Kivity <avi@redhat.com>,
	kvm@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] KVM: prevent read from desc->shadow_ptes[-1] in rmap_desc_remove_entry()
Date: Sat, 29 Aug 2009 14:13:24 +0200	[thread overview]
Message-ID: <4A991B64.3050903@gmail.com> (raw)

prevent read from desc->shadow_ptes[-1]

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
If in rmap_remove() (bottom) we do:

while (desc) {
        for (i = 0; i < RMAP_EXT && desc->shadow_ptes[i]; ++i)
                if (desc->shadow_ptes[i] == spte) {
                        rmap_desc_remove_entry(rmapp,
                                               desc, i,
                                               prev_desc);
                        return;
                }
        prev_desc = desc;
        desc = desc->more;
}

If in the first iteration esc->shadow_ptes[0] == spte, then we
call rmap_desc_remove_entry() with i == 0, and then we read in
the last iteration from desc->shadow_ptes[-1].

I found this by code analysis.

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 0ef5bb2..e1b2e46 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -541,7 +541,7 @@ static void rmap_desc_remove_entry(unsigned long *rmapp,
 {
 	int j;
 
-	for (j = RMAP_EXT - 1; !desc->shadow_ptes[j] && j > i; --j)
+	for (j = RMAP_EXT - 1; j > i && !desc->shadow_ptes[j]; --j)
 		;
 	desc->shadow_ptes[i] = desc->shadow_ptes[j];
 	desc->shadow_ptes[j] = NULL;

             reply	other threads:[~2009-08-29 12:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-29 12:13 Roel Kluin [this message]
2009-08-29 17:57 ` [PATCH] KVM: prevent read from desc->shadow_ptes[-1] in rmap_desc_remove_entry() 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=4A991B64.3050903@gmail.com \
    --to=roel.kluin@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    /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.