Skip to content

Commit

Permalink
net:socket: set msg_namelen to 0 if msg_name is passed as NULL in msg…
Browse files Browse the repository at this point in the history
…hdr 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@arista.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ani Sinha authored and David S. Miller committed Sep 10, 2014
1 parent 4748997 commit 6a2a2b3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 6a2a2b3

Please sign in to comment.