net: clamp ->msg_namelen instead of returning an error
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 27 Nov 2013 12:40:21 +0000 (15:40 +0300)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 3 Jan 2014 04:33:33 +0000 (04:33 +0000)
commit26fe7ef27e2db83b33ac7fb1cb3bca829cbcb8e2
treed0ed37e1fcd37c706dcbe20e9659d1444fa6352e
parentb38ecb9bbbb42b71833ff4439283f51120a35c1a
net: clamp ->msg_namelen instead of returning an error

[ Upstream commit db31c55a6fb245fdbb752a2ca4aefec89afabb06 ]

If kmsg->msg_namelen > sizeof(struct sockaddr_storage) then in the
original code that would lead to memory corruption in the kernel if you
had audit configured.  If you didn't have audit configured it was
harmless.

There are some programs such as beta versions of Ruby which use too
large of a buffer and returning an error code breaks them.  We should
clamp the ->msg_namelen value instead.

Fixes: 1661bf364ae9 ("net: heap overflow in __audit_sockaddr()")
Reported-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Tested-by: Eric Wong <normalperson@yhbt.net>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
net/compat.c
net/socket.c