From: Jon M. <jon...@er...> - 2019-03-15 20:11:13
|
From: Erik Hugne <eri...@gm...> We move the check that prevents connecting service ranges to after the RDM/DGRAM check, and separate 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 <eri...@gm...> Signed-off-by: Jon Maloy <jon...@er...> --- net/tipc/socket.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 3274ef6..1950781 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -2349,6 +2349,16 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) return 0; } +static int tipc_sockaddr_is_sane(struct sockaddr_tipc *addr) +{ + if (addr->family != AF_TIPC) + return 0; + 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 @@ -2384,18 +2394,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; -- 2.1.4 |
From: <eri...@gm...> - 2019-03-11 20:46:33
|
From: Erik Hugne <eri...@gm...> We move the check that prevents connecting service service ranges to after the RDM/DGRAM check, and split out address sanitizing to a separate function that also validates the service range. Signed-off-by: Erik Hugne <eri...@gm...> --- I was pondering to move all sanitize stuff (including length check) to one function and just call that before socket is locked, but the AF_UNSPEC stuff made it complicated, so this just solves the problem i had with connect()'ing a multicast address to an RDM socket. net/tipc/socket.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 3274ef625dba..195078128c0d 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -2349,6 +2349,16 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) return 0; } +static int tipc_sockaddr_is_sane(struct sockaddr_tipc *addr) +{ + if (addr->family != AF_TIPC) + return 0; + 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 @@ -2384,18 +2394,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; -- 2.14.1 |
From: Erik H. <eri...@gm...> - 2019-03-15 18:52:51
|
No love for this? :( RDM connect is pretty handicapped right now |
From: Jon M. <jon...@er...> - 2019-03-15 19:13:53
|
Don’t worry. I was just too bugged down with other issues the last days. I’ll send it in today. BR ///jon From: Erik Hugne <eri...@gm...> Sent: 15-Mar-19 14:53 To: tip...@li...; Jon Maloy <jon...@er...>; Xue, Ying <yin...@wi...> Subject: Re: [PATCH v2] tipc: allow service ranges to be connect()'ed on RDM/DGRAM No love for this? :( RDM connect is pretty handicapped right now |
From: David M. <da...@da...> - 2019-03-16 19:19:13
|
From: Jon Maloy <jon...@er...> Date: Fri, 15 Mar 2019 21:11:00 +0100 > @@ -2349,6 +2349,16 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) > return 0; > } > > +static int tipc_sockaddr_is_sane(struct sockaddr_tipc *addr) > +{ > + if (addr->family != AF_TIPC) > + return 0; I think bool and true/false are most appropriate for this function. |
From: <eri...@gm...> - 2019-03-17 09:51:17
|
From: Erik Hugne <eri...@gm...> We move the check that prevents connecting service service ranges to after the RDM/DGRAM check, and split out address sanitizing 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 <eri...@gm...> --- v3: address check function returns bool as suggested by davem net/tipc/socket.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 3274ef625dba..0f678e92fd30 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -2349,6 +2349,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 @@ -2384,18 +2394,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; -- 2.14.1 |
From: Jon M. <jon...@er...> - 2019-03-17 17:46:52
|
From: Erik Hugne <eri...@gm...> 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 <eri...@gm...> Signed-off-by: Jon Maloy <jon...@er...> --- v2: address check function returns bool as suggested by davem --- net/tipc/socket.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index d6b2686..b542f14 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -2349,6 +2349,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 @@ -2384,18 +2394,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; -- 2.1.4 |
From: David M. <da...@da...> - 2019-03-18 04:33:06
|
From: Jon Maloy <jon...@er...> Date: Sun, 17 Mar 2019 18:46:42 +0100 > From: Erik Hugne <eri...@gm...> > > 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 <eri...@gm...> > Signed-off-by: Jon Maloy <jon...@er...> > --- > v2: address check function returns bool as suggested by davem Applied and queued up for -stable, thanks Jon. |