From: David Gibson <david@gibson.dropbear.id.au>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: qemu-trivial@nongnu.org,
Peter Crosthwaite <peter.crosthwaite@petalogix.com>,
Jon Loeliger <jdl@jdl.com>,
agraf@suse.de, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] device_tree: load_device_tree(): Allow NULL sizep
Date: Thu, 16 Aug 2012 12:14:11 +1000 [thread overview]
Message-ID: <20120816021411.GE4171@truffula.fritz.box> (raw)
In-Reply-To: <20120815134156.GD10742@stefanha-thinkpad.localdomain>
On Wed, Aug 15, 2012 at 02:41:56PM +0100, Stefan Hajnoczi wrote:
> On Sat, Aug 11, 2012 at 01:33:42PM +0100, Stefan Hajnoczi wrote:
> > On Sat, Aug 11, 2012 at 12:11 AM, Peter Crosthwaite
> > <peter.crosthwaite@petalogix.com> wrote:
> > > On Fri, Aug 10, 2012 at 11:42 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> > >> On Fri, Aug 10, 2012 at 01:54:26PM +1000, Peter A. G. Crosthwaite wrote:
> > >>> The sizep arg is populated with the size of the loaded device tree. Since this
> > >>> is one of those informational "please populate" type arguments it should be
> > >>> optional. Guarded writes to *sizep against NULL accordingly.
> > >>>
> > >>> Signed-off-by: Peter A. G. Crosthwaite <peter.crosthwaite@petalogix.com>
> > >>> Acked-by: Alexander Graf <agraf@suse.de>
> > >>> ---
> > >>> device_tree.c | 8 ++++++--
> > >>> 1 files changed, 6 insertions(+), 2 deletions(-)
> > >>>
> > >>> diff --git a/device_tree.c b/device_tree.c
> > >>> index d7a9b6b..641a48a 100644
> > >>> --- a/device_tree.c
> > >>> +++ b/device_tree.c
> > >>> @@ -71,7 +71,9 @@ void *load_device_tree(const char *filename_path, int *sizep)
> > >>> int ret;
> > >>> void *fdt = NULL;
> > >>>
> > >>> - *sizep = 0;
> > >>> + if (sizep) {
> > >>> + *sizep = 0;
> > >>> + }
> > >>> dt_size = get_image_size(filename_path);
> > >>> if (dt_size < 0) {
> > >>> printf("Unable to get size of device tree file '%s'\n",
> > >>> @@ -104,7 +106,9 @@ void *load_device_tree(const char *filename_path, int *sizep)
> > >>> filename_path);
> > >>> goto fail;
> > >>> }
> > >>> - *sizep = dt_size;
> > >>> + if (sizep) {
> > >>> + *sizep = dt_size;
> > >>> + }
> > >>
> > >> What can the caller do with this void* buffer without knowing its size?
> > >>
> > >
> > > Sanity check the machine:
> > >
> > > dtb = load_device_tree( ... ); //dont care how big it is
> > > foo = fdt_gep_prop( dtb, ... );
> > > if (foo != object_get_prop(foo_device, foo_prop, ... )) {
> > > hw_error("your dtb is bad because ... !\n", ... );
> > > }
> >
> > What happens if the fdt is corrupt or malicious? I guess we'll access
> > memory beyond the end of blob.
> >
> > This seems to be libfdt's fault. I didn't see an API to validate the
> > blob's size.
> >
> > I'm "happy" with this patch but if fdt's can ever come from untrusted
> > sources then we're in trouble.
>
> Jon/David, can you confirm that libfdt has no way of check the size of
> the fdt blob?
That's not rentirely true.
> For example, if I pass a corrupt or malicious blob to libfdt, is there a
> way to detect that or will it access memory beyond the end of the blob
> as we query the device tree?
So, libfdt does trust the blob size that's given in the blob header,
since libfdt itself doesn't really have any other source for the
blob/buffer size. If you have another source for your buffer size
though, you can check that quite easily against fdt_totalsize(blob)
(which returns the header value). If you can think of a helper
function that would make this easier, I'd be happy to add it to
libfdt.
Once the header size is validated, though, libfdt *is* supposed to be
safe against a corrupt or malicious blob. I can't guarantee that we
don't have bugs here, but any crash on malicious data I do consider a
bug and will fix once I'm aware of it.
--
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-08-16 2:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-10 3:54 [Qemu-devel] [PULL 0/1] device_tree: load_device_tree(): Allow NULL sizep Peter A. G. Crosthwaite
2012-08-10 3:54 ` [Qemu-devel] [PATCH] " Peter A. G. Crosthwaite
2012-08-10 13:42 ` Stefan Hajnoczi
2012-08-10 23:11 ` Peter Crosthwaite
2012-08-11 12:33 ` Stefan Hajnoczi
2012-08-15 13:41 ` Stefan Hajnoczi
2012-08-16 2:14 ` David Gibson [this message]
2012-08-20 13:58 ` Stefan Hajnoczi
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=20120816021411.GE4171@truffula.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=agraf@suse.de \
--cc=jdl@jdl.com \
--cc=peter.crosthwaite@petalogix.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=stefanha@gmail.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;
as well as URLs for NNTP newsgroup(s).