diff options
author | Erik Hugne <erik.hugne@gmail.com> | 2019-03-17 18:46:42 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-04-03 06:26:18 +0200 |
commit | 24d1a6259706f03aa2057359685ef8ea77f69e38 (patch) | |
tree | 4ff415a9525aa0571236db8c66fb43768ffaaf81 /net/tipc | |
parent | 7115df614b09ea5baa9883b4f629a27a02237de3 (diff) | |
download | linux-stable-24d1a6259706f03aa2057359685ef8ea77f69e38.tar.gz linux-stable-24d1a6259706f03aa2057359685ef8ea77f69e38.tar.bz2 linux-stable-24d1a6259706f03aa2057359685ef8ea77f69e38.zip |
tipc: allow service ranges to be connect()'ed on RDM/DGRAM
[ Upstream commit ea239314fe42ace880bdd834256834679346c80e ]
We move the check that prevents connecting service ranges to after
the RDM/DGRAM check, and move address sanity control to a separate
function that also validates the service range.
Fixes: 23998835be98 ("tipc: improve address sanity check in tipc_connect()")
Signed-off-by: Erik Hugne <erik.hugne@gmail.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net/tipc')
-rw-r--r-- | net/tipc/socket.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 88c307ef1318..67a7b312a499 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -2310,6 +2310,16 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) return 0; } +static bool tipc_sockaddr_is_sane(struct sockaddr_tipc *addr) +{ + if (addr->family != AF_TIPC) + return false; + if (addr->addrtype == TIPC_SERVICE_RANGE) + return (addr->addr.nameseq.lower <= addr->addr.nameseq.upper); + return (addr->addrtype == TIPC_SERVICE_ADDR || + addr->addrtype == TIPC_SOCKET_ADDR); +} + /** * tipc_connect - establish a connection to another TIPC port * @sock: socket structure @@ -2345,18 +2355,18 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest, if (!tipc_sk_type_connectionless(sk)) res = -EINVAL; goto exit; - } else if (dst->family != AF_TIPC) { - res = -EINVAL; } - if (dst->addrtype != TIPC_ADDR_ID && dst->addrtype != TIPC_ADDR_NAME) + if (!tipc_sockaddr_is_sane(dst)) { res = -EINVAL; - if (res) goto exit; - + } /* DGRAM/RDM connect(), just save the destaddr */ if (tipc_sk_type_connectionless(sk)) { memcpy(&tsk->peer, dest, destlen); goto exit; + } else if (dst->addrtype == TIPC_SERVICE_RANGE) { + res = -EINVAL; + goto exit; } previous = sk->sk_state; |