Skip to content

Commit 69ba423

Browse files
committed
Merge branch 'ipv6-fix-issues-on-accessing-fib6_metrics'
Wei Wang says: ==================== ipv6: fix issues on accessing fib6_metrics The latest fix on the memory leak of fib6_metrics still causes use-after-free. This patch series first revert the previous fix and propose a new fix that is more inline with ipv4 logic and is tested to fix the use-after-free issue reported. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 126d684 + ce7ea4a commit 69ba423

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

net/ipv6/route.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,14 @@ EXPORT_SYMBOL(ip6_dst_alloc);
364364

365365
static void ip6_dst_destroy(struct dst_entry *dst)
366366
{
367+
struct dst_metrics *p = (struct dst_metrics *)DST_METRICS_PTR(dst);
367368
struct rt6_info *rt = (struct rt6_info *)dst;
368369
struct fib6_info *from;
369370
struct inet6_dev *idev;
370371

371-
dst_destroy_metrics_generic(dst);
372+
if (p != &dst_default_metrics && refcount_dec_and_test(&p->refcnt))
373+
kfree(p);
374+
372375
rt6_uncached_list_del(rt);
373376

374377
idev = rt->rt6i_idev;
@@ -976,6 +979,10 @@ static void rt6_set_from(struct rt6_info *rt, struct fib6_info *from)
976979
rt->rt6i_flags &= ~RTF_EXPIRES;
977980
rcu_assign_pointer(rt->from, from);
978981
dst_init_metrics(&rt->dst, from->fib6_metrics->metrics, true);
982+
if (from->fib6_metrics != &dst_default_metrics) {
983+
rt->dst._metrics |= DST_METRICS_REFCOUNTED;
984+
refcount_inc(&from->fib6_metrics->refcnt);
985+
}
979986
}
980987

981988
/* Caller must already hold reference to @ort */

0 commit comments

Comments
 (0)