qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: benoit.canet@irqsave.net, ppandit@redhat.com,
	qemu-devel@nongnu.org, stefanha@redhat.com,
	qemu-stable@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 1/5] qcow1: Make padding in the header explicit
Date: Fri, 16 May 2014 12:41:11 +0200	[thread overview]
Message-ID: <20140516104111.GD4508@noname.redhat.com> (raw)
In-Reply-To: <5374E217.7090607@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1848 bytes --]

Am 15.05.2014 um 17:49 hat Eric Blake geschrieben:
> On 05/15/2014 08:21 AM, Kevin Wolf wrote:
> > We were relying on all compilers inserting the same padding in the
> > header struct that is used for the on-disk format. Let's not do that.
> > Mark the struct as packed and insert an explicit padding field for
> > compatibility.
> > 
> > Cc: qemu-stable@nongnu.org
> > Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> > Reviewed-by: Benoit Canet <benoit@irqsave.net>
> > ---
> >  block/qcow.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/block/qcow.c b/block/qcow.c
> > index 937dd6d..3684794 100644
> > --- a/block/qcow.c
> > +++ b/block/qcow.c
> > @@ -48,9 +48,10 @@ typedef struct QCowHeader {
> >      uint64_t size; /* in bytes */
> >      uint8_t cluster_bits;
> >      uint8_t l2_bits;
> > +    uint16_t padding;
> >      uint32_t crypt_method;
> >      uint64_t l1_table_offset;
> > -} QCowHeader;
> > +} QEMU_PACKED QCowHeader;
> 
> Is it worth a compile-time assertion that the correct size is achieved?
> 
> [I don't know if glib provides such a macro, but gnulib has a verify()
> macro that could be used as:
> 
> verify(sizeof(QCowHeader) == NNN)
> 
> which expands to _Static_assert(sizeof(QCowHeader) == NNN) in new enough
> C compilers, and to something like
> 
> extern int (*dummy1(void)) [sizeof (struct dummy2 {
>   int dummy3: (sizeof(QCowHeader) == NNN) ? 1 : -1; })]
> 
> on older compilers for reliable compile-time detection]
> 
> But not a show-stopper to this patch as-is.

QEMU_BUILD_BUG_ON() is what you're looking for.

Do you think that would be a useful addition? With packed structs there
should be little that could make it go wrong. But if we want to add
this, I'd do it in a separate patch and for all image formats.

Kevin

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2014-05-16 10:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-15 14:21 [Qemu-devel] [PATCH v2 0/5] qcow1: Input validation fixes Kevin Wolf
2014-05-15 14:21 ` [Qemu-devel] [PATCH v2 1/5] qcow1: Make padding in the header explicit Kevin Wolf
2014-05-15 15:49   ` Eric Blake
2014-05-16 10:41     ` Kevin Wolf [this message]
2014-05-16 12:42       ` Eric Blake
2014-05-15 14:21 ` [Qemu-devel] [PATCH v2 2/5] qcow1: Check maximum cluster size Kevin Wolf
2014-05-15 16:34   ` Benoît Canet
2014-05-15 14:21 ` [Qemu-devel] [PATCH v2 3/5] qcow1: Validate L2 table size (CVE-2014-0222) Kevin Wolf
2014-05-15 16:34   ` Benoît Canet
2014-05-15 14:21 ` [Qemu-devel] [PATCH v2 4/5] qcow1: Validate image size (CVE-2014-0223) Kevin Wolf
2014-05-15 16:35   ` Benoît Canet
2014-05-16 10:47     ` Kevin Wolf
2014-05-16 11:22       ` Benoît Canet
2014-05-15 14:21 ` [Qemu-devel] [PATCH v2 5/5] qcow1: Stricter backing file length check Kevin Wolf

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=20140516104111.GD4508@noname.redhat.com \
    --to=kwolf@redhat.com \
    --cc=benoit.canet@irqsave.net \
    --cc=eblake@redhat.com \
    --cc=ppandit@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=stefanha@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;
as well as URLs for NNTP newsgroup(s).