Skip to content

Commit

Permalink
sctp: fix dst refcnt leak in sctp_v6_get_dst()
Browse files Browse the repository at this point in the history
When going through the bind address list in sctp_v6_get_dst() and
the previously found address is better ('matchlen > bmatchlen'),
the code continues to the next iteration without releasing currently
held destination.

Fix it by releasing 'bdst' before continue to the next iteration, and
instead of introducing one more '!IS_ERR(bdst)' check for dst_release(),
move the already existed one right after ip6_dst_lookup_flow(), i.e. we
shouldn't proceed further if we get an error for the route lookup.

Fixes: dbc2b5e ("sctp: fix src address selection if using secondary addresses for ipv6")
Signed-off-by: Alexey Kodanev <[email protected]>
Acked-by: Neil Horman <[email protected]>
Acked-by: Marcelo Ricardo Leitner <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
akodanev authored and davem330 committed Feb 6, 2018
1 parent 23ddd26 commit 957d761
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions net/sctp/ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,10 @@ static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
final_p = fl6_update_dst(fl6, rcu_dereference(np->opt), &final);
bdst = ip6_dst_lookup_flow(sk, fl6, final_p);

if (!IS_ERR(bdst) &&
ipv6_chk_addr(dev_net(bdst->dev),
if (IS_ERR(bdst))
continue;

if (ipv6_chk_addr(dev_net(bdst->dev),
&laddr->a.v6.sin6_addr, bdst->dev, 1)) {
if (!IS_ERR_OR_NULL(dst))
dst_release(dst);
Expand All @@ -336,8 +338,10 @@ static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
}

bmatchlen = sctp_v6_addr_match_len(daddr, &laddr->a);
if (matchlen > bmatchlen)
if (matchlen > bmatchlen) {
dst_release(bdst);
continue;
}

if (!IS_ERR_OR_NULL(dst))
dst_release(dst);
Expand Down

0 comments on commit 957d761

Please sign in to comment.