From: Paul Mackerras <paulus@ozlabs.org>
To: "Geyslan Gregório Bem" <geyslan@gmail.com>
Cc: Gleb Natapov <gleb@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Alexander Graf <agraf@suse.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Michael Ellerman <mpe@ellerman.id.au>,
kvm@vger.kernel.org, kvm-ppc@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC] kvm - possible out of bounds
Date: Mon, 30 Nov 2015 08:33:00 +1100 [thread overview]
Message-ID: <20151129213300.GA28845@fergus.ozlabs.ibm.com> (raw)
In-Reply-To: <CAGG-pUS04iVsi3s4hkB8goWkCM3sq+QiLw7L74bbef93Z=+qwg@mail.gmail.com>
On Sun, Nov 29, 2015 at 05:14:03PM -0300, Geyslan Gregório Bem wrote:
> Hello,
>
> I have found a possible out of bounds reading in
> arch/powerpc/kvm/book3s_64_mmu.c (kvmppc_mmu_book3s_64_xlate
> function). pteg[] array could be accessed twice using the i variable
> after the for iteration. What happens is that in the last iteration
> the i index is incremented to 16, checked (i<16) then confirmed
> exiting the loop.
>
> 277 for (i=0; i<16; i+=2) { ...
>
> Later there are reading attempts to the pteg last elements, but using
> again the already incremented i (16).
>
> 303 v = be64_to_cpu(pteg[i]); /* pteg[16] */
> 304 r = be64_to_cpu(pteg[i+1]); /* pteg[17] */
Was it some automated tool that came up with this?
There is actually no problem because the accesses outside the loop are
only done if the 'found' variable is true; 'found' is initialized to
false and only ever set to true inside the loop just before a break
statement. Thus there is a correlation between the value of 'i' and
the value of 'found' -- if 'found' is true then we know 'i' is less
than 16.
> I really don't know if the for lace will somehow iterate until i is
> 16, anyway I think that the last readings must be using a defined max
> len/index or another more clear method.
I think it's perfectly clear to a human programmer, though some tools
(such as gcc) struggle with this kind of correlation between
variables. That's why I asked whether your report was based on the
output from some tool.
> Eg.
>
> v = be64_to_cpu(pteg[PTEG_LEN - 2]);
> r = be64_to_cpu(pteg[PTEG_LEN - 1]);
>
> Or just.
>
> v = be64_to_cpu(pteg[14]);
> r = be64_to_cpu(pteg[15]);
Either of those options would cause the code to malfunction.
> I found in the same file a variable that is not used.
>
> 380 struct kvmppc_vcpu_book3s *vcpu_book3s;
> ...
> 387 vcpu_book3s = to_book3s(vcpu);
True. It could be removed.
> A question, the kvmppc_mmu_book3s_64_init function is accessed by
> unconventional way? Because I have not found any calling to it.
Try arch/powerpc/kvm/book3s_pr.c line 410:
kvmppc_mmu_book3s_64_init(vcpu);
Grep (or git grep) is your friend.
Paul.
next prev parent reply other threads:[~2015-11-29 21:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-29 20:14 [RFC] kvm - possible out of bounds Geyslan Gregório Bem
2015-11-29 21:33 ` Paul Mackerras [this message]
2015-11-29 22:05 ` Geyslan Gregório Bem
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=20151129213300.GA28845@fergus.ozlabs.ibm.com \
--to=paulus@ozlabs.org \
--cc=agraf@suse.com \
--cc=benh@kernel.crashing.org \
--cc=geyslan@gmail.com \
--cc=gleb@kernel.org \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=pbonzini@redhat.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