Skip to content

Commit df18b50

Browse files
qsndavem330
authored andcommitted
net/ipv6: fix metrics leak
Since commit d4ead6b ("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: d4ead6b ("net/ipv6: move metrics from dst to rt6_info") Signed-off-by: Sabrina Dubroca <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 822fb18 commit df18b50

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

net/ipv6/ip6_fib.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,22 @@ struct fib6_info *fib6_info_alloc(gfp_t gfp_flags)
167167
return f6i;
168168
}
169169

170+
static void fib6_metrics_release(struct fib6_info *f6i)
171+
{
172+
struct dst_metrics *m;
173+
174+
if (!f6i)
175+
return;
176+
177+
m = f6i->fib6_metrics;
178+
if (m != &dst_default_metrics && refcount_dec_and_test(&m->refcnt))
179+
kfree(m);
180+
}
181+
170182
void fib6_info_destroy_rcu(struct rcu_head *head)
171183
{
172184
struct fib6_info *f6i = container_of(head, struct fib6_info, rcu);
173185
struct rt6_exception_bucket *bucket;
174-
struct dst_metrics *m;
175186

176187
WARN_ON(f6i->fib6_node);
177188

@@ -201,9 +212,7 @@ void fib6_info_destroy_rcu(struct rcu_head *head)
201212
if (f6i->fib6_nh.nh_dev)
202213
dev_put(f6i->fib6_nh.nh_dev);
203214

204-
m = f6i->fib6_metrics;
205-
if (m != &dst_default_metrics && refcount_dec_and_test(&m->refcnt))
206-
kfree(m);
215+
fib6_metrics_release(f6i);
207216

208217
kfree(f6i);
209218
}
@@ -887,6 +896,7 @@ static void fib6_drop_pcpu_from(struct fib6_info *f6i,
887896

888897
from = rcu_dereference_protected(pcpu_rt->from,
889898
lockdep_is_held(&table->tb6_lock));
899+
fib6_metrics_release(from);
890900
rcu_assign_pointer(pcpu_rt->from, NULL);
891901
fib6_info_release(from);
892902
}

0 commit comments

Comments
 (0)