Skip to content

Commit 2399883

Browse files
Jon Maloydavem330
authored andcommitted
tipc: improve address sanity check in tipc_connect()
The address given to tipc_connect() is not completely sanity checked, under the assumption that this will be done later in the function __tipc_sendmsg() when the address is used there. However, the latter functon will in the next commits serve as caller to several other send functions, so we want to move the corresponding sanity check there to the beginning of that function, before we possibly need to grab the address stored by tipc_connect(). We must therefore be able to trust that this address already has been thoroughly checked. We do this in this commit. Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Acked-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 14c0449 commit 2399883

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

‎net/tipc/socket.c‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,28 +1911,27 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
19111911
int previous;
19121912
int res = 0;
19131913

1914+
if (destlen != sizeof(struct sockaddr_tipc))
1915+
return -EINVAL;
1916+
19141917
lock_sock(sk);
19151918

1916-
/* DGRAM/RDM connect(), just save the destaddr */
1917-
if (tipc_sk_type_connectionless(sk)) {
1918-
if (dst->family == AF_UNSPEC) {
1919-
memset(&tsk->peer, 0, sizeof(struct sockaddr_tipc));
1920-
} else if (destlen != sizeof(struct sockaddr_tipc)) {
1919+
if (dst->family == AF_UNSPEC) {
1920+
memset(&tsk->peer, 0, sizeof(struct sockaddr_tipc));
1921+
if (!tipc_sk_type_connectionless(sk))
19211922
res = -EINVAL;
1922-
} else {
1923-
memcpy(&tsk->peer, dest, destlen);
1924-
}
19251923
goto exit;
1924+
} else if (dst->family != AF_TIPC) {
1925+
res = -EINVAL;
19261926
}
1927-
1928-
/*
1929-
* Reject connection attempt using multicast address
1930-
*
1931-
* Note: send_msg() validates the rest of the address fields,
1932-
* so there's no need to do it here
1933-
*/
1934-
if (dst->addrtype == TIPC_ADDR_MCAST) {
1927+
if (dst->addrtype != TIPC_ADDR_ID && dst->addrtype != TIPC_ADDR_NAME)
19351928
res = -EINVAL;
1929+
if (res)
1930+
goto exit;
1931+
1932+
/* DGRAM/RDM connect(), just save the destaddr */
1933+
if (tipc_sk_type_connectionless(sk)) {
1934+
memcpy(&tsk->peer, dest, destlen);
19361935
goto exit;
19371936
}
19381937

0 commit comments

Comments
 (0)