qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Cornelia Huck" <cornelia.huck@de.ibm.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"Alexander Graf" <agraf@suse.de>,
	"Anthony Liguori" <anthony@codemonkey.ws>,
	patches@linaro.org
Subject: [Qemu-devel] [PATCH 0/2] object_initialize: check size of passed in memory
Date: Fri, 23 Aug 2013 14:38:54 +0100	[thread overview]
Message-ID: <1377265136-8559-1-git-send-email-peter.maydell@linaro.org> (raw)

This patchset addresses a concern that came up with Andreas' recent
patches for using embedded objects in some of the ARM CPU devices:
object_initialize() doesn't check that there's actually enough space
for the type being added, so if you have:

struct MyDevice {
   ...
   SomeObject obj;
};

    object_initialize(&mydev->obj, "some-object");

then there's no compile time or runtime check that SomeObject
is really big enough for the "some-object" object -- if the
implementation is changed later then there will be silent
memory corruption.

These patches make object_initialize() a macro which can then
use sizeof(*PTR) to pass the size into the implementation to
be checked.

The virtio patch is worth applying anyway -- it removes some
pointless casts which would otherwise have caused false
positives.

Disclaimer: I've eyeballed all the uses of object_initialize()
but I haven't necessarily tested them all.

Peter Maydell (2):
  virtio: Remove unnecessary OBJECT casts
  qom: Make object_initialize and object_initialize_with_type check
    size

 hw/core/qdev.c             |    2 +-
 hw/s390x/s390-virtio-bus.c |   12 ++++++------
 hw/s390x/virtio-ccw.c      |   14 +++++++-------
 hw/virtio/virtio-pci.c     |   16 ++++++++--------
 include/qom/object.h       |   36 ++++++++++++++++++++++++++++++++++--
 qom/object.c               |    9 +++++----
 6 files changed, 61 insertions(+), 28 deletions(-)

-- 
1.7.9.5

             reply	other threads:[~2013-08-23 13:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-23 13:38 Peter Maydell [this message]
2013-08-23 13:38 ` [Qemu-devel] [PATCH 1/2] virtio: Remove unnecessary OBJECT casts Peter Maydell
2013-08-23 14:19   ` Andreas Färber
2013-08-23 13:38 ` [Qemu-devel] [PATCH 2/2] qom: Make object_initialize and object_initialize_with_type check size Peter Maydell
2013-08-23 14:13 ` [Qemu-devel] [PATCH 0/2] object_initialize: check size of passed in memory Andreas Färber

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=1377265136-8559-1-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=anthony@codemonkey.ws \
    --cc=cornelia.huck@de.ibm.com \
    --cc=patches@linaro.org \
    --cc=qemu-devel@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).