diff options
author | Ani Sinha <ani@arista.com> | 2014-09-08 14:49:59 -0700 |
---|---|---|
committer | Zefan Li <lizefan@huawei.com> | 2015-04-14 17:34:03 +0800 |
commit | adc507681d2dba391d97b0e8f65313737be64d65 (patch) | |
tree | 9de2073c6fc1a0b78cc43d9169e1c440285d5c33 /net | |
parent | 590603b71e399e5dbf328eda7b780ee0dca939ce (diff) | |
download | lwn-adc507681d2dba391d97b0e8f65313737be64d65.tar.gz lwn-adc507681d2dba391d97b0e8f65313737be64d65.zip |
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>
Cc: Michal Marek <mmarek@suse.cz>
Signed-off-by: Zefan Li <lizefan@huawei.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/socket.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/net/socket.c b/net/socket.c index cc3fc4d4263e..025f7f4d2d80 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1908,6 +1908,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; |