[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <35be28742fbc44af9d77b30d5686de06@AcuMS.aculab.com>
Date: Fri, 26 Apr 2019 15:14:36 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Willem de Bruijn' <willemdebruijn.kernel@...il.com>
CC: "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"davem@...emloft.net" <davem@...emloft.net>,
"idosch@...sch.org" <idosch@...sch.org>,
"Willem de Bruijn" <willemb@...gle.com>
Subject: RE: [PATCH net] packet: validate address length if non-zero
From: Willem de Bruijn
> Sent: 26 April 2019 16:11
> On Thu, Apr 25, 2019 at 11:42 AM Willem de Bruijn
> <willemdebruijn.kernel@...il.com> wrote:
> >
> > On Thu, Apr 25, 2019 at 10:35 AM David Laight <David.Laight@...lab.com> wrote:
> > >
> > > From: Willem de Bruijn
> > > > Sent: 25 April 2019 14:57
> > > ...
> > > > > I've just done a bit of software archaeology.
> > > > >
> > > > > Prior to 2.6.14-rc3 the send code ignored sll_halen, it was only set by the receive code.
> > > > > So it is not surprising that old application code leaves it as zero.
> > > > >
> > > > > The old receive code also always set msg_namelen = sizeof (struct sockaddr_ll).
> > > > > The receive code now sets:
> > > > > msg_namelen = offsetof(struct sockaddr_ll, sll_addr) + saddr->sll_halen;
> > > > > For ethernet this changes the msg_namelen from 20 to 18.
> > > > > A side effect (no one has noticed for years) is that you can't send a reply
> > > > > by passing back the received address buffer.
> > > >
> > > > Great find, thanks. I hadn't thought of going back that far, but
> > > > clearly should in these legacy caller questions..
> > >
> > > Fortunately I didn't have to find the pre-git sources :-)
> > >
> > > > > Looking at it all again how about:
> > > > > char *addr = NULL;
> > > > > ...
> > > > > err = -EINVAL;
> > > > > if (msg->msg_namelen < offsetof(struct sockaddr_ll, sll_addr))
> > > > > goto out;
> > > > > proto = saddr->sll_protocol;
> > > > > dev = dev_get_by_index(sock_net(sk), saddr->sll_ifindex);
> > > > > if (dev && sock->type == SOCK_DGRAM) {
> > > > > if (msg->msg_namelen < dev->addr_len + offsetof(struct
> sockaddr_ll, sll_addr))
> > > > > goto out_unlock;
> > > > > addr = saddr->sll_addr;
> > > > > }
> > > >
> > > > Yes, given the above, this looks great to me.
>
> Coming back to this. Both the above and two separate send/recv fixes
> seem fine to me. Do you have a preference either way? And do you want
> to send the fix(es) or should I?
I'll let you do it - save me working out how to get valid patches off
my Linux systems and into outlook :-)
If you are going to do the recv fix the send one can keep the check
against the full struct sockaddr_ll.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists