aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/socket.c
diff options
context:
space:
mode:
authorJon Maloy <jon.maloy@ericsson.com>2017-10-13 05:04:18 -0400
committerDavid S. Miller <davem@davemloft.net>2017-10-13 11:46:00 -0400
commit23998835be98a6842e5698fa1824f404c7de850d (patch)
tree8007516156e1d53a479d6604aa6d963df62969a7 /net/tipc/socket.c
parent14c04493cb77bc38404dbcb39d5ccbb667831ad7 (diff)
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>
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r--net/tipc/socket.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 9a7e7b5cf23f..7659e792ecdb 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -1911,28 +1911,27 @@ static int tipc_connect(struct socket *sock, struct sockaddr *dest,
1911 int previous; 1911 int previous;
1912 int res = 0; 1912 int res = 0;
1913 1913
1914 if (destlen != sizeof(struct sockaddr_tipc))
1915 return -EINVAL;
1916
1914 lock_sock(sk); 1917 lock_sock(sk);
1915 1918
1916 /* DGRAM/RDM connect(), just save the destaddr */ 1919 if (dst->family == AF_UNSPEC) {
1917 if (tipc_sk_type_connectionless(sk)) { 1920 memset(&tsk->peer, 0, sizeof(struct sockaddr_tipc));
1918 if (dst->family == AF_UNSPEC) { 1921 if (!tipc_sk_type_connectionless(sk))
1919 memset(&tsk->peer, 0, sizeof(struct sockaddr_tipc));
1920 } else if (destlen != sizeof(struct sockaddr_tipc)) {
1921 res = -EINVAL; 1922 res = -EINVAL;
1922 } else {
1923 memcpy(&tsk->peer, dest, destlen);
1924 }
1925 goto exit; 1923 goto exit;
1924 } else if (dst->family != AF_TIPC) {
1925 res = -EINVAL;
1926 } 1926 }
1927 1927 if (dst->addrtype != TIPC_ADDR_ID && dst->addrtype != TIPC_ADDR_NAME)
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) {
1935 res = -EINVAL; 1928 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);
1936 goto exit; 1935 goto exit;
1937 } 1936 }
1938 1937