Message ID | CAOxq_8Nvox3ABUoZFzmvMyb4XwAHx1YdTPfx9rpKAofM7crq=w@mail.gmail.com |
---|---|
State | Changes Requested, archived |
Delegated to: | David Miller |
Headers | show |
I just resent this patch again with git send-email so that it can be directly applied without any whitespace damage. Subject: [PATCH 1/1] net:socket: set msg_namelen to 0 if msg_name is passed as NULL in msghdr struct from userland. thanks, ani On Fri, Sep 5, 2014 at 2:44 PM, Ani Sinha <ani@arista.com> wrote: > On Fri, Sep 5, 2014 at 2:26 PM, Hannes Frederic Sowa >> If you set msg_namelen = 0 if msg_name == NULL prior to the < 0 check it >> should not trigger the return -EINVAL and also we don't run into the >> unsafe implicit conversion case when comparing msg_namelen with the >> result of the sizeof(). Do you see any problems with that? > > yes, sorry I misunderstood you. Here's the updated patch : > > From ea39174d4475d7def61410210613ab24a4ce0e81 Mon Sep 17 00:00:00 2001 > From: Ani Sinha <ani@aristanetworks.com> > Date: Fri, 5 Sep 2014 14:33:20 -0700 > Subject: [PATCH] net:socket: set msg_namelen to 0 if msg_name is > passed as NULL in msghdr struct from userland. > > Linux manpage for recvmsg and sendmsg calls does not explicitly > mention setting msg_namelen to 0 when > msg_name passed set as NULL. When developers don't set msg_namelen > member in msghdr, it might contain garbage > value which will fail the validation check and sendmsg and recvmsg > calls from kernel will return EINVAL. This will > break old binaries and any code for which there is no access to source code. > To fix this, we set msg_namelen to 0 when msg_name is passed as NULL > from userland. > > Signed-off-by: Ani Sinha <ani@aristanetworks.com> > --- > net/socket.c | 3 +++ > 1 files changed, 3 insertions(+), 0 deletions(-) > > diff --git a/net/socket.c b/net/socket.c > index 95ee7d8..457be6a 100644 > --- a/net/socket.c > +++ b/net/socket.c > @@ -1997,6 +1997,9 @@ static int copy_msghdr_from_user(struct msghdr *kmsg, > if (copy_from_user(kmsg, umsg, sizeof(struct msghdr))) > return -EFAULT; > > + if (kmsg->msg_name == NULL) > + kmsg->msg_namelen = 0; > + > if (kmsg->msg_namelen < 0) > return -EINVAL; > > -- > 1.7.4.4 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/net/socket.c b/net/socket.c index 95ee7d8..457be6a 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1997,6 +1997,9 @@ static int copy_msghdr_from_user(struct msghdr *kmsg, if (copy_from_user(kmsg, umsg, sizeof(struct msghdr))) return -EFAULT; + if (kmsg->msg_name == NULL) + kmsg->msg_namelen = 0; + if (kmsg->msg_namelen < 0) return -EINVAL;