* [PATCH net-next] ipv6: Always allocate pcpu memory in a fib6_nh
@ 2019-06-04 1:37 David Ahern
2019-06-04 21:55 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: David Ahern @ 2019-06-04 1:37 UTC (permalink / raw)
To: davem; +Cc: netdev, David Ahern
From: David Ahern <dsahern@gmail.com>
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: f40b6ae2b612 ("ipv6: Move pcpu cached routes to fib6_nh")
Signed-off-by: David Ahern <dsahern@gmail.com>
---
net/ipv6/route.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 29c2f5086116..d5777e92609d 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -3400,7 +3400,7 @@ int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
goto out;
}
}
- goto set_dev;
+ goto pcpu_alloc;
}
if (cfg->fc_flags & RTF_GATEWAY) {
@@ -3432,17 +3432,18 @@ int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
!netif_carrier_ok(dev))
fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN;
+ err = fib_nh_common_init(&fib6_nh->nh_common, cfg->fc_encap,
+ cfg->fc_encap_type, cfg, gfp_flags, extack);
+ if (err)
+ goto out;
+
+pcpu_alloc:
fib6_nh->rt6i_pcpu = alloc_percpu_gfp(struct rt6_info *, gfp_flags);
if (!fib6_nh->rt6i_pcpu) {
err = -ENOMEM;
goto out;
}
- err = fib_nh_common_init(&fib6_nh->nh_common, cfg->fc_encap,
- cfg->fc_encap_type, cfg, gfp_flags, extack);
- if (err)
- goto out;
-set_dev:
fib6_nh->fib_nh_dev = dev;
fib6_nh->fib_nh_oif = dev->ifindex;
err = 0;
--
2.11.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] ipv6: Always allocate pcpu memory in a fib6_nh
2019-06-04 1:37 [PATCH net-next] ipv6: Always allocate pcpu memory in a fib6_nh David Ahern
@ 2019-06-04 21:55 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-06-04 21:55 UTC (permalink / raw)
To: dsahern; +Cc: netdev, dsahern
From: David Ahern <dsahern@kernel.org>
Date: Mon, 3 Jun 2019 18:37:03 -0700
> From: David Ahern <dsahern@gmail.com>
>
> 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: f40b6ae2b612 ("ipv6: Move pcpu cached routes to fib6_nh")
> Signed-off-by: David Ahern <dsahern@gmail.com>
Applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-06-04 21:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-04 1:37 [PATCH net-next] ipv6: Always allocate pcpu memory in a fib6_nh David Ahern
2019-06-04 21:55 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).