netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Graf <tgraf@suug.ch>
To: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Cc: jamal <hadi@cyberus.ca>, Kay Sievers <kay.sievers@vrfy.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	jmorris@redhat.com, ijc@hellion.org.uk,
	guillaume.thouvenin@bull.net, greg@kroah.com,
	linux-kernel@vger.kernel.org, akpm@osdl.org,
	netdev <netdev@oss.sgi.com>
Subject: Re: [Fwd: Re: connector is missing in 2.6.12-rc2-mm1]
Date: Mon, 11 Apr 2005 12:45:50 +0200	[thread overview]
Message-ID: <20050411104550.GK26731@postel.suug.ch> (raw)
In-Reply-To: <20050411092228.A32699@2ka.mipt.ru>

* Evgeniy Polyakov <20050411092228.A32699@2ka.mipt.ru> 2005-04-11 09:22
> On Sun, Apr 10, 2005 at 09:27:27PM +0200, Thomas Graf (tgraf@suug.ch) wrote:
> > +       size = NLMSG_SPACE(sizeof(*msg) + msg->len);
> > +
> > +       skb = alloc_skb(size, GFP_ATOMIC);
> > +       if (!skb) {
> > +               printk(KERN_ERR "Failed to allocate new skb with size=%u.\n", size);
> > +               return;
> > +       }
> > +
> > +       nlh = NLMSG_PUT(skb, 0, msg->seq, NLMSG_DONE, size - sizeof(*nlh));
> > 
> > This is not correct, what happens is:
> > size = NLMSG_SPACE(sizeof(*msg) + msg->len);
> >  --> align(hdr)+align(data)
> > size - sizeof(*nlh)
> >  --> (align(hdr)-hdr)+align(data)
> > NLMSG_PUT pads again to get to the end of the data block (NLMSG_LENGTH)
> >  --> align(hdr)+(align(hdr)-hdr)+align(data)
> > 
> > At the moment align(hdr) == hdr since nlmsghdr is already aligned
> > but this might change and your code will break.
> 
> As far as I remember, header is always supposed to be aligned properly
> "by design", so it even could be nonaligned here.

No, have a look at the macros:

#define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(sizeof(struct nlmsghdr)))
#define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))

NLMSG_LENGTH points to the end of the payload in the message, NLMSG_SPACE
represents the total size aligned properly for a possible next multipart
message.

It is unlikely that nlmsghdr will ever be unaligned but there can be no
reason to introduce code that can break with perfectly legal changes just
because of that.

  reply	other threads:[~2005-04-11 10:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1112942924.28858.234.camel@uganda>
2005-04-10  9:52 ` [Fwd: Re: connector is missing in 2.6.12-rc2-mm1] Herbert Xu
2005-04-10 10:32   ` Evgeniy Polyakov
2005-04-10 11:08     ` Kay Sievers
2005-04-10 11:37       ` Evgeniy Polyakov
2005-04-10 11:54         ` Evgeniy Polyakov
2005-04-10 12:10         ` Thomas Graf
2005-04-10 12:15           ` Evgeniy Polyakov
2005-04-10 14:39             ` jamal
2005-04-10 14:56               ` James Morris
2005-04-10 15:08                 ` jamal
2005-04-10 19:27               ` Thomas Graf
2005-04-11  5:22                 ` Evgeniy Polyakov
2005-04-11 10:45                   ` Thomas Graf [this message]
2005-04-11 11:19                     ` Evgeniy Polyakov

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=20050411104550.GK26731@postel.suug.ch \
    --to=tgraf@suug.ch \
    --cc=akpm@osdl.org \
    --cc=greg@kroah.com \
    --cc=guillaume.thouvenin@bull.net \
    --cc=hadi@cyberus.ca \
    --cc=herbert@gondor.apana.org.au \
    --cc=ijc@hellion.org.uk \
    --cc=jmorris@redhat.com \
    --cc=johnpol@2ka.mipt.ru \
    --cc=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@oss.sgi.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).