Skip to content

Commit 706ec91

Browse files
sherllydavem330
authored andcommitted
ipv6: Fix nexthop refcnt leak when creating ipv6 route info
ip6_route_info_create() invokes nexthop_get(), which increases the refcount of the "nh". When ip6_route_info_create() returns, local variable "nh" becomes invalid, so the refcount should be decreased to keep refcount balanced. The reference counting issue happens in one exception handling path of ip6_route_info_create(). When nexthops can not be used with source routing, the function forgets to decrease the refcnt increased by nexthop_get(), causing a refcnt leak. Fix this issue by pulling up the error source routing handling when nexthops can not be used with source routing. Fixes: f88d8ea ("ipv6: Plumb support for nexthop object in a fib6_info") Signed-off-by: Xiyu Yang <[email protected]> Signed-off-by: Xin Tan <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fa662d7 commit 706ec91

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/ipv6/route.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,14 +3685,14 @@ static struct fib6_info *ip6_route_info_create(struct fib6_config *cfg,
36853685
rt->fib6_src.plen = cfg->fc_src_len;
36863686
#endif
36873687
if (nh) {
3688-
if (!nexthop_get(nh)) {
3689-
NL_SET_ERR_MSG(extack, "Nexthop has been deleted");
3690-
goto out;
3691-
}
36923688
if (rt->fib6_src.plen) {
36933689
NL_SET_ERR_MSG(extack, "Nexthops can not be used with source routing");
36943690
goto out;
36953691
}
3692+
if (!nexthop_get(nh)) {
3693+
NL_SET_ERR_MSG(extack, "Nexthop has been deleted");
3694+
goto out;
3695+
}
36963696
rt->nh = nh;
36973697
fib6_nh = nexthop_fib6_nh(rt->nh);
36983698
} else {

0 commit comments

Comments
 (0)