netdev
[Top] [All Lists]

Re: [Fwd: Re: connector is missing in 2.6.12-rc2-mm1]

To: Thomas Graf <tgraf@xxxxxxx>
Subject: Re: [Fwd: Re: connector is missing in 2.6.12-rc2-mm1]
From: Evgeniy Polyakov <johnpol@xxxxxxxxxxx>
Date: Mon, 11 Apr 2005 15:19:53 +0400
Cc: jamal <hadi@xxxxxxxxxx>, Kay Sievers <kay.sievers@xxxxxxxx>, Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>, jmorris@xxxxxxxxxx, ijc@xxxxxxxxxxxxxx, guillaume.thouvenin@xxxxxxxx, greg@xxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, akpm@xxxxxxxx, netdev <netdev@xxxxxxxxxxx>
In-reply-to: <20050411104550.GK26731@xxxxxxxxxxxxxx>
Organization: MIPT
References: <1112942924.28858.234.camel@uganda> <E1DKZ7e-00070D-00@xxxxxxxxxxxxxxxxxxxxxxxx> <20050410143205.18bff80d@xxxxxxxxxxxxxxxxxxxx> <1113131325.6994.66.camel@xxxxxxxxxxxxxxxxxxxxx> <20050410153757.104fe611@xxxxxxxxxxxxxxxxxxxx> <20050410121005.GF26731@xxxxxxxxxxxxxx> <20050410161549.3abe4778@xxxxxxxxxxxxxxxxxxxx> <1113143959.1089.316.camel@xxxxxxxxxxxxxxxx> <20050410192727.GI26731@xxxxxxxxxxxxxx> <20050411092228.A32699@xxxxxxxxxxx> <20050411104550.GK26731@xxxxxxxxxxxxxx>
Reply-to: johnpol@xxxxxxxxxxx
Sender: netdev-bounce@xxxxxxxxxxx
On Mon, 2005-04-11 at 12:45 +0200, Thomas Graf wrote:
> * Evgeniy Polyakov <20050411092228.A32699@xxxxxxxxxxx> 2005-04-11 09:22
> > On Sun, Apr 10, 2005 at 09:27:27PM +0200, Thomas Graf (tgraf@xxxxxxx) 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.

But NLMSG_ALIGN(sizeof(hdr)) is always equal to sizeof(hdr), that size
was select not accidentally.

I will change it, no problem, it is good from aesthetic point of view.

-- 
        Evgeniy Polyakov

Crash is better than data corruption -- Arthur Grabowski

Attachment: signature.asc
Description: This is a digitally signed message part

<Prev in Thread] Current Thread [Next in Thread>