]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net:socket: set msg_namelen to 0 if msg_name is passed as NULL in msghdr struct from...
authorAni Sinha <ani@arista.com>
Mon, 8 Sep 2014 21:49:59 +0000 (14:49 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 10 Sep 2014 00:35:46 +0000 (17:35 -0700)
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@arista.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/socket.c

index 2e2586e2dee19184e07e01c528563c7000cf912e..4cdbc107606f037c6404f9947beb80174b961e80 100644 (file)
@@ -1996,6 +1996,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;