tipc: validate length of sockaddr in connect() for dgram/rdm
authorSasha Levin <sasha.levin@oracle.com>
Mon, 23 Mar 2015 19:30:00 +0000 (15:30 -0400)
committerDavid S. Miller <davem@davemloft.net>
Tue, 24 Mar 2015 16:50:39 +0000 (12:50 -0400)
Commit f2f8036 ("tipc: add support for connect() on dgram/rdm sockets")
hasn't validated user input length for the sockaddr structure which allows
a user to overwrite kernel memory with arbitrary input.

Fixes: f2f8036 ("tipc: add support for connect() on dgram/rdm sockets")
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/tipc/socket.c

index 6dd5bd95236a0de436abd1914d2c2293fd3a2986..09471051947768eed472f3049e3da54229aadb91 100644 (file)
@@ -1851,6 +1851,8 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
                if (dst->family == AF_UNSPEC) {
                        memset(&tsk->remote, 0, sizeof(struct sockaddr_tipc));
                        tsk->connected = 0;
+               } else if (destlen != sizeof(struct sockaddr_tipc)) {
+                       res = -EINVAL;
                } else {
                        memcpy(&tsk->remote, dest, destlen);
                        tsk->connected = 1;