From: David Gibson <david@gibson.dropbear.id.au>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH 3/9] pci: Make bounds checks on config space accesses actually work
Date: Fri, 13 Jan 2012 12:44:12 +1100 [thread overview]
Message-ID: <20120113014412.GB4935@truffala.fritz.box> (raw)
In-Reply-To: <20120113012336.GA3903@redhat.com>
On Fri, Jan 13, 2012 at 03:23:37AM +0200, Michael S. Tsirkin wrote:
> On Fri, Jan 13, 2012 at 11:26:12AM +1100, David Gibson wrote:
> > On Thu, Jan 12, 2012 at 03:32:32PM +0200, Michael S. Tsirkin wrote:
> > > On Thu, Jan 12, 2012 at 04:46:22PM +1100, David Gibson wrote:
> > > > The pci_host_config_{read,write}_common() functions perform PCI config
> > > > accesses. They take a limit parameter which they appear to be supposed
> > > > to bounds check against, however the bounds checking logic, such as it is,
> > > > is completely broken.
> > > >
> > > > Currently, it takes the minimum of the supplied length and the remaining
> > > > space in the region and passes that as the length to the underlying
> > > > config_{read,write} function pointer. This means that accesses which
> > > > partially overrun the region will be silently truncated - which makes
> > > > little sense.
> > >
> > > Why does it make little sense? Makes sense to me.
> >
> > Well, for starters a partial overrun would have to be an unaligned
> > config space access, which is not supported by PCI. The behaviour if
> > you try is undefined on most bridges and unlikely to be a partial
> > read/write (ignoring the low addr bits would be more likely).
>
> Yes, bus level cycles have dword granularity in PCI.
> But look e.g. at our express implementation.
> Config is memory mapped, so we simply map this as memory into guest.
So?
> If you do a large read, what happens on real hardware?
> I'm not sure, but it looks possible that it will get split
> and multiple dword transactions generated on the bus.
Totally irrelevant in this context. The function definition only
allows a maximum of 4 byte transfers (because of the uint32_ts), so
the bus emulation logic would already have to split a long read into
multiple calls to the function.
> OTOH our implementation passes the read on as is, so
> it can get a multi-dword.
> I'll try to play with some real systems to see what they do.
>
> > Even if a bridge somehow did a partial access, it's still wrong for
> > reads, since the overrunning bits would typically return 0xff not
> > 0x00, and so you'd need to 0xff pad the result.
>
> Or maybe an error needs to be generated. We really don't know,
> it's up to the caller.
>
> > There's just no point doing anything other than simply failing partial
> > overruns.
>
> There's no point in random code churn either.
Removing an insane semantic os not random code churn.
> > > > Accesses which entirely overrun the region will *not*
> > > > be blocked (an exploitable bug)
> > > >, because in that case (limit - addr) will
> > > > be negative and so the unsigned MIN will always return len instead. Even
> > > > if signed arithmetic was used, the config_{read,write} callback wouldn't
> > > > know what to do with a negative len parameter.
> > >
> > > The assumption was callers never pass in such values.
> >
> > So, callers are to to treat this function, taking a limit parameter as
> > having semantics of "checks a pointless edge case, but not the obvious
> > type of overrun". You think that's a sensible semantic for a general
> > helper function? Seriously?
>
> I don't mind adding an extra check at this level. But
> the comment would need to be reworded from
> 'fix a bug' to 'pseries wants to pass out of range
> values so let's check this'.
Oh, FFS, you're just making excuses for not making a simple fix to
stupid code.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
next prev parent reply other threads:[~2012-01-13 1:44 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-12 5:46 [Qemu-devel] [0/9] Bugfixes and pseries enhancements David Gibson
2012-01-12 5:46 ` [Qemu-devel] [PATCH 1/9] load_image_targphys() should enforce the max size David Gibson
2012-01-12 5:46 ` [Qemu-devel] [PATCH 2/9] Fix dirty logging with 32-bit qemu & 64-bit guests David Gibson
2012-01-12 5:46 ` [Qemu-devel] [PATCH 3/9] pci: Make bounds checks on config space accesses actually work David Gibson
2012-01-12 13:19 ` Alexander Graf
2012-01-12 13:33 ` Michael S. Tsirkin
2012-01-12 13:32 ` Michael S. Tsirkin
2012-01-13 0:26 ` [Qemu-devel] [Qemu-ppc] " David Gibson
2012-01-13 1:23 ` Michael S. Tsirkin
2012-01-13 1:44 ` David Gibson [this message]
2012-01-16 11:24 ` Alexander Graf
2012-01-12 5:46 ` [Qemu-devel] [PATCH 4/9] Update gitignore file David Gibson
2012-01-12 5:46 ` [Qemu-devel] [PATCH 5/9] Correct types in bmdma_addr_{read,write} David Gibson
2012-01-12 5:46 ` [Qemu-devel] [PATCH 6/9] pseries: Support PCI extended config space in RTAS calls David Gibson
2012-01-12 5:46 ` [Qemu-devel] [PATCH 7/9] pseries: Use correct dispatcher for PCI config space accesses David Gibson
2012-01-12 5:46 ` [Qemu-devel] [PATCH 8/9] pseries: Don't try to munmap() a malloc()ed TCE table David Gibson
2012-01-12 5:46 ` [Qemu-devel] [PATCH 9/9] pseries: SLOF PCI flag day David Gibson
2012-01-13 14:15 ` [Qemu-devel] [0/9] Bugfixes and pseries enhancements Alexander Graf
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=20120113014412.GB4935@truffala.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.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 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).