Skip to content

Commit 7dd7316

Browse files
dsaherndavem330
authored andcommitted
ipv6: Always allocate pcpu memory in a fib6_nh
A recent commit had an unintended side effect with reject routes: rt6i_pcpu is expected to always be initialized for all fib6_info except the null entry. The commit mentioned below skips it for reject routes and ends up leaking references to the loopback device. For example, ip netns add foo ip -netns foo li set lo up ip -netns foo -6 ro add blackhole 2001:db8:1::1 ip netns exec foo ping6 2001:db8:1::1 ip netns del foo ends up spewing: unregister_netdevice: waiting for lo to become free. Usage count = 3 The fib_nh_common_init is not needed for reject routes (no ipv4 caching or encaps), so move the alloc_percpu_gfp after it and adjust the goto label. Fixes: f40b6ae ("ipv6: Move pcpu cached routes to fib6_nh") Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1e00718 commit 7dd7316

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

net/ipv6/route.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,7 +3113,7 @@ int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
31133113
goto out;
31143114
}
31153115
}
3116-
goto set_dev;
3116+
goto pcpu_alloc;
31173117
}
31183118

31193119
if (cfg->fc_flags & RTF_GATEWAY) {
@@ -3145,17 +3145,18 @@ int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
31453145
!netif_carrier_ok(dev))
31463146
fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN;
31473147

3148+
err = fib_nh_common_init(&fib6_nh->nh_common, cfg->fc_encap,
3149+
cfg->fc_encap_type, cfg, gfp_flags, extack);
3150+
if (err)
3151+
goto out;
3152+
3153+
pcpu_alloc:
31483154
fib6_nh->rt6i_pcpu = alloc_percpu_gfp(struct rt6_info *, gfp_flags);
31493155
if (!fib6_nh->rt6i_pcpu) {
31503156
err = -ENOMEM;
31513157
goto out;
31523158
}
31533159

3154-
err = fib_nh_common_init(&fib6_nh->nh_common, cfg->fc_encap,
3155-
cfg->fc_encap_type, cfg, gfp_flags, extack);
3156-
if (err)
3157-
goto out;
3158-
set_dev:
31593160
fib6_nh->fib_nh_dev = dev;
31603161
fib6_nh->fib_nh_oif = dev->ifindex;
31613162
err = 0;

0 commit comments

Comments
 (0)