* [net 1/1] tipc: allow service ranges to be connect()'ed on RDM/DGRAM
@ 2019-03-15 20:11 Jon Maloy
2019-03-16 19:19 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Jon Maloy @ 2019-03-15 20:11 UTC (permalink / raw)
To: davem, netdev
Cc: gordan.mihaljevic, tung.q.nguyen, hoang.h.le, jon.maloy,
canh.d.luu, ying.xue, tipc-discussion
From: Erik Hugne <erik.hugne@gmail.com>
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 <erik.hugne@gmail.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [net 1/1] tipc: allow service ranges to be connect()'ed on RDM/DGRAM
2019-03-15 20:11 [net 1/1] tipc: allow service ranges to be connect()'ed on RDM/DGRAM Jon Maloy
@ 2019-03-16 19:19 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-03-16 19:19 UTC (permalink / raw)
To: jon.maloy
Cc: netdev, gordan.mihaljevic, tung.q.nguyen, hoang.h.le, canh.d.luu,
ying.xue, tipc-discussion
From: Jon Maloy <jon.maloy@ericsson.com>
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-03-16 19:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-15 20:11 [net 1/1] tipc: allow service ranges to be connect()'ed on RDM/DGRAM Jon Maloy
2019-03-16 19:19 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).