Skip to content

Commit 4a31a6b

Browse files
rantaladavem330
authored andcommitted
sctp: fix dst refcnt leak in sctp_v4_get_dst
Fix dst reference count leak in sctp_v4_get_dst() introduced in commit 410f038 ("sctp: add routing output fallback"): When walking the address_list, successive ip_route_output_key() calls may return the same rt->dst with the reference incremented on each call. The code would not decrement the dst refcount when the dst pointer was identical from the previous iteration, causing the dst refcnt leak. Testcase: ip netns add TEST ip netns exec TEST ip link set lo up ip link add dummy0 type dummy ip link add dummy1 type dummy ip link add dummy2 type dummy ip link set dev dummy0 netns TEST ip link set dev dummy1 netns TEST ip link set dev dummy2 netns TEST ip netns exec TEST ip addr add 192.168.1.1/24 dev dummy0 ip netns exec TEST ip link set dummy0 up ip netns exec TEST ip addr add 192.168.1.2/24 dev dummy1 ip netns exec TEST ip link set dummy1 up ip netns exec TEST ip addr add 192.168.1.3/24 dev dummy2 ip netns exec TEST ip link set dummy2 up ip netns exec TEST sctp_test -H 192.168.1.2 -P 20002 -h 192.168.1.1 -p 20000 -s -B 192.168.1.3 ip netns del TEST In 4.4 and 4.9 kernels this results to: [ 354.179591] unregister_netdevice: waiting for lo to become free. Usage count = 1 [ 364.419674] unregister_netdevice: waiting for lo to become free. Usage count = 1 [ 374.663664] unregister_netdevice: waiting for lo to become free. Usage count = 1 [ 384.903717] unregister_netdevice: waiting for lo to become free. Usage count = 1 [ 395.143724] unregister_netdevice: waiting for lo to become free. Usage count = 1 [ 405.383645] unregister_netdevice: waiting for lo to become free. Usage count = 1 ... Fixes: 410f038 ("sctp: add routing output fallback") Fixes: 0ca50d1 ("sctp: fix src address selection if using secondary addresses") Signed-off-by: Tommi Rantala <[email protected]> Acked-by: Marcelo Ricardo Leitner <[email protected]> Acked-by: Neil Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 957d761 commit 4a31a6b

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

net/sctp/protocol.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,22 +514,20 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
514514
if (IS_ERR(rt))
515515
continue;
516516

517-
if (!dst)
518-
dst = &rt->dst;
519-
520517
/* Ensure the src address belongs to the output
521518
* interface.
522519
*/
523520
odev = __ip_dev_find(sock_net(sk), laddr->a.v4.sin_addr.s_addr,
524521
false);
525522
if (!odev || odev->ifindex != fl4->flowi4_oif) {
526-
if (&rt->dst != dst)
523+
if (!dst)
524+
dst = &rt->dst;
525+
else
527526
dst_release(&rt->dst);
528527
continue;
529528
}
530529

531-
if (dst != &rt->dst)
532-
dst_release(dst);
530+
dst_release(dst);
533531
dst = &rt->dst;
534532
break;
535533
}

0 commit comments

Comments
 (0)