* [PATCH net] net/ipv6: fix metrics leak
@ 2018-07-30 14:23 Sabrina Dubroca
2018-07-30 16:46 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Sabrina Dubroca @ 2018-07-30 14:23 UTC (permalink / raw)
To: netdev; +Cc: Sabrina Dubroca, David Ahern
Since commit d4ead6b34b67 ("net/ipv6: move metrics from dst to
rt6_info"), ipv6 metrics are shared and refcounted. rt6_set_from()
assigns the rt->from pointer and increases the refcount on from's
metrics. This reference is never released.
Introduce the fib6_metrics_release() helper and use it to release the
metrics.
Fixes: d4ead6b34b67 ("net/ipv6: move metrics from dst to rt6_info")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
net/ipv6/ip6_fib.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index d212738e9d10..211a2d437b56 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -167,11 +167,22 @@ struct fib6_info *fib6_info_alloc(gfp_t gfp_flags)
return f6i;
}
+static void fib6_metrics_release(struct fib6_info *f6i)
+{
+ struct dst_metrics *m;
+
+ if (!f6i)
+ return;
+
+ m = f6i->fib6_metrics;
+ if (m != &dst_default_metrics && refcount_dec_and_test(&m->refcnt))
+ kfree(m);
+}
+
void fib6_info_destroy_rcu(struct rcu_head *head)
{
struct fib6_info *f6i = container_of(head, struct fib6_info, rcu);
struct rt6_exception_bucket *bucket;
- struct dst_metrics *m;
WARN_ON(f6i->fib6_node);
@@ -201,9 +212,7 @@ void fib6_info_destroy_rcu(struct rcu_head *head)
if (f6i->fib6_nh.nh_dev)
dev_put(f6i->fib6_nh.nh_dev);
- m = f6i->fib6_metrics;
- if (m != &dst_default_metrics && refcount_dec_and_test(&m->refcnt))
- kfree(m);
+ fib6_metrics_release(f6i);
kfree(f6i);
}
@@ -887,6 +896,7 @@ static void fib6_drop_pcpu_from(struct fib6_info *f6i,
from = rcu_dereference_protected(pcpu_rt->from,
lockdep_is_held(&table->tb6_lock));
+ fib6_metrics_release(from);
rcu_assign_pointer(pcpu_rt->from, NULL);
fib6_info_release(from);
}
--
2.18.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net/ipv6: fix metrics leak
2018-07-30 14:23 [PATCH net] net/ipv6: fix metrics leak Sabrina Dubroca
@ 2018-07-30 16:46 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-07-30 16:46 UTC (permalink / raw)
To: sd; +Cc: netdev, dsahern
From: Sabrina Dubroca <sd@queasysnail.net>
Date: Mon, 30 Jul 2018 16:23:10 +0200
> Since commit d4ead6b34b67 ("net/ipv6: move metrics from dst to
> rt6_info"), ipv6 metrics are shared and refcounted. rt6_set_from()
> assigns the rt->from pointer and increases the refcount on from's
> metrics. This reference is never released.
>
> Introduce the fib6_metrics_release() helper and use it to release the
> metrics.
>
> Fixes: d4ead6b34b67 ("net/ipv6: move metrics from dst to rt6_info")
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Looks good, applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-30 18:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-30 14:23 [PATCH net] net/ipv6: fix metrics leak Sabrina Dubroca
2018-07-30 16:46 ` 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).