Skip to content

Commit ce7ea4a

Browse files
tracywwnjdavem330
authored andcommitted
ipv6: fix memory leak on dst->_metrics
When dst->_metrics and f6i->fib6_metrics share the same memory, both take reference count on the dst_metrics structure. However, when dst is destroyed, ip6_dst_destroy() only invokes dst_destroy_metrics_generic() which does not take care of READONLY metrics and does not release refcnt. This causes memory leak. Similar to ipv4 logic, the fix is to properly release refcnt and free the memory space pointed by dst->_metrics if refcnt becomes 0. Fixes: 93531c6 ("net/ipv6: separate handling of FIB entries from dst based routes") Reported-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: Wei Wang <weiwan@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8675860 commit ce7ea4a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

net/ipv6/route.c

Lines changed: 4 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;

0 commit comments

Comments
 (0)