Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tipc: allow service ranges to be connect()'ed on RDM/DGRAM

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>

authored by

Erik Hugne and committed by
David S. Miller
ea239314 65e9a6d2

+15 -5
+15 -5
net/tipc/socket.c
··· 2349 2349 return 0; 2350 2350 } 2351 2351 2352 + static bool tipc_sockaddr_is_sane(struct sockaddr_tipc *addr) 2353 + { 2354 + if (addr->family != AF_TIPC) 2355 + return false; 2356 + if (addr->addrtype == TIPC_SERVICE_RANGE) 2357 + return (addr->addr.nameseq.lower <= addr->addr.nameseq.upper); 2358 + return (addr->addrtype == TIPC_SERVICE_ADDR || 2359 + addr->addrtype == TIPC_SOCKET_ADDR); 2360 + } 2361 + 2352 2362 /** 2353 2363 * tipc_connect - establish a connection to another TIPC port 2354 2364 * @sock: socket structure ··· 2394 2384 if (!tipc_sk_type_connectionless(sk)) 2395 2385 res = -EINVAL; 2396 2386 goto exit; 2397 - } else if (dst->family != AF_TIPC) { 2398 - res = -EINVAL; 2399 2387 } 2400 - if (dst->addrtype != TIPC_ADDR_ID && dst->addrtype != TIPC_ADDR_NAME) 2388 + if (!tipc_sockaddr_is_sane(dst)) { 2401 2389 res = -EINVAL; 2402 - if (res) 2403 2390 goto exit; 2404 - 2391 + } 2405 2392 /* DGRAM/RDM connect(), just save the destaddr */ 2406 2393 if (tipc_sk_type_connectionless(sk)) { 2407 2394 memcpy(&tsk->peer, dest, destlen); 2395 + goto exit; 2396 + } else if (dst->addrtype == TIPC_SERVICE_RANGE) { 2397 + res = -EINVAL; 2408 2398 goto exit; 2409 2399 } 2410 2400