Skip to contentSkip to conversation

ipv6: fix double refcount of fib6_metrics

PATCH Applied Cong Wang 3 participants 4 messages Aug 3, 2018 – Aug 13, 2018

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 ipv6: fix double refcount of fib6_metrics

All the callers of ip6_rt_copy_init()/rt6_set_from() hold refcnt of the "from" fib6_info, so there is no need to hold fib6_metrics refcnt again, because fib6_metrics refcnt is only released when fib6_info is gone, that is, they have the same life time, so the whole fib6_metrics refcnt can be removed actually.

This fixes a kmemleak warning reported by Sabrina.

Fixes 93531c674315 ("net/ipv6: separate handling of FIB entries from dst based routes")
Cc Sabrina Dubroca <[email protected]>
Cc David Ahern <[email protected]>
---
 net/ipv6/route.c | 4 ----
 1 file changed, 4 deletions(-)
net/ipv6/route.c +0 -4
index ec18b3ce8b6d..7208c16302f6 100644
@@ -978,10 +978,6 @@ static void rt6_set_from(struct rt6_info *rt, struct fib6_info *from)
 	rt->rt6i_flags &= ~RTF_EXPIRES;
 	rcu_assign_pointer(rt->from, from);
 	dst_init_metrics(&rt->dst, from->fib6_metrics->metrics, true);
-	if (from->fib6_metrics != &dst_default_metrics) {
-		rt->dst._metrics |= DST_METRICS_REFCOUNTED;
-		refcount_inc(&from->fib6_metrics->refcnt);
-	}
 }
 
 /* Caller must already hold reference to @ort */
Signature · 1 line
2.14.4
maintainer
#1 lore raw

From: Cong Wang <[email protected]>
Date: Thu, 2 Aug 2018 23:20:38 -0700

Quoted 6 lines

All the callers of ip6_rt_copy_init()/rt6_set_from() hold refcnt of the "from" fib6_info, so there is no need to hold fib6_metrics refcnt again, because fib6_metrics refcnt is only released when fib6_info is gone, that is, they have the same life time, so the whole fib6_metrics refcnt can be removed actually.

Quoted 7 lines

This fixes a kmemleak warning reported by Sabrina.

Fixes 93531c674315 ("net/ipv6: separate handling of FIB entries from dst based routes")
Cc Sabrina Dubroca <[email protected]>
Cc David Ahern <[email protected]>

Sabrina, please review!

maintainer Applied
#2 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Thu, 2 Aug 2018 23:20:38 -0700

Quoted 6 lines

All the callers of ip6_rt_copy_init()/rt6_set_from() hold refcnt of the "from" fib6_info, so there is no need to hold fib6_metrics refcnt again, because fib6_metrics refcnt is only released when fib6_info is gone, that is, they have the same life time, so the whole fib6_metrics refcnt can be removed actually.

Quoted 7 lines

This fixes a kmemleak warning reported by Sabrina.

Fixes 93531c674315 ("net/ipv6: separate handling of FIB entries from dst based routes")
Cc Sabrina Dubroca <[email protected]>
Cc David Ahern <[email protected]>

Applied, thanks Cong.

#3 lore raw
In reply to Cong Wang
Quoted 23 lines · Cong Wang

All the callers of ip6_rt_copy_init()/rt6_set_from() hold refcnt of the "from" fib6_info, so there is no need to hold fib6_metrics refcnt again, because fib6_metrics refcnt is only released when fib6_info is gone, that is, they have the same life time, so the whole fib6_metrics refcnt can be removed actually.

This fixes a kmemleak warning reported by Sabrina.

Fixes 93531c674315 ("net/ipv6: separate handling of FIB entries from dst based routes")
Cc Sabrina Dubroca <[email protected]>
Cc David Ahern <[email protected]>
---
 net/ipv6/route.c | 4 ----
 1 file changed, 4 deletions(-)
net/ipv6/route.c +0 -0
index ec18b3ce8b6d..7208c16302f6 100644

net/ipv6/route.c static void rt6_set_from(struct rt6_info *rt, struct fib6_info *from) · line 983

Quoted 10 lines
net/ipv6/route.c +0 -4
@@ -978,10 +978,6 @@ static void rt6_set_from(struct rt6_info *rt, struct fib6_info *from)
 	rt->rt6i_flags &= ~RTF_EXPIRES;
 	rcu_assign_pointer(rt->from, from);
 	dst_init_metrics(&rt->dst, from->fib6_metrics->metrics, true);
-	if (from->fib6_metrics != &dst_default_metrics) {
-		rt->dst._metrics |= DST_METRICS_REFCOUNTED;
-		refcount_inc(&from->fib6_metrics->refcnt);
-	}
 }
 
 /* Caller must already hold reference to @ort */

This seems like a reasonable fix. Thanks for the patch.