aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAni Sinha <ani@arista.com>2014-09-08 14:49:59 -0700
committerWilly Tarreau <w@1wt.eu>2015-05-24 10:10:45 +0200
commit964a590975bdef771dfa1da6b3dfd500d34990e3 (patch)
tree5831d1ceaa377b3acd51883ebd181b56ffeb16a3
parent0c5d422155951f9b2ac3285a1264eb63683e0794 (diff)
net:socket: set msg_namelen to 0 if msg_name is passed as NULL in msghdr struct from userland.
commit 6a2a2b3ae0759843b22c929881cc184b00cc63ff upstream. 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> Signed-off-by: Ben Hutchings <ben@decadent.org.uk> (cherry picked from commit d29f1f53e5299e0bbb3e33ef8d35ed657fa633b6) Signed-off-by: Willy Tarreau <w@1wt.eu>
-rw-r--r--net/socket.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/net/socket.c b/net/socket.c
index 19671d8e20f6..a838a67dd77d 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1872,6 +1872,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;