From: Wei Wang <tracywwnj@gmail.com>
To: dsahern@gmail.com
Cc: Wei Wang <weiwan@google.com>,
"David S . Miller" <davem@davemloft.net>,
Linux Kernel Network Developers <netdev@vger.kernel.org>,
Eric Dumazet <edumazet@google.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
sd@queasysnail.net
Subject: Re: [PATCH net 2/2] ipv6: fix memory leak on dst->_metrics
Date: Tue, 18 Sep 2018 18:02:35 -0700 [thread overview]
Message-ID: <CAC15z3jUJ8HTPSkHj4R+=a_UJXevr96vDLBFt9D+0zodjCeMcA@mail.gmail.com> (raw)
In-Reply-To: <15a5dad7-544e-37d7-1a04-fb3e2fad599f@gmail.com>
On Tue, Sep 18, 2018 at 4:25 PM David Ahern <dsahern@gmail.com> wrote:
>
> On 9/18/18 1:45 PM, Wei Wang wrote:
> > From: Wei Wang <weiwan@google.com>
> >
> > 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: 93531c674315 ("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>
> > ---
> > net/ipv6/route.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> > index b5d3e6b294ab..826b14de7dbb 100644
> > --- a/net/ipv6/route.c
> > +++ b/net/ipv6/route.c
> > @@ -364,11 +364,14 @@ EXPORT_SYMBOL(ip6_dst_alloc);
> >
> > static void ip6_dst_destroy(struct dst_entry *dst)
> > {
> > + struct dst_metrics *p = (struct dst_metrics *)DST_METRICS_PTR(dst);
> > struct rt6_info *rt = (struct rt6_info *)dst;
> > struct fib6_info *from;
> > struct inet6_dev *idev;
> >
> > - dst_destroy_metrics_generic(dst);
> > + if (p != &dst_default_metrics && refcount_dec_and_test(&p->refcnt))
> > + kfree(p);
> > +
> > rt6_uncached_list_del(rt);
> >
> > idev = rt->rt6i_idev;
> >
>
> Reviewed-by: David Ahern <dsahern@gmail.com>
>
> With the revert in patch 1 we are back to my original code after
> 93531c67431 ("net/ipv6: separate handling of FIB entries from dst based
> routes").
>
> My intention with that series was to make IPv6 handling of metrics as
> identical to IPv4 as possible (v6 does have differences for example due
> to autoconf and changing metrics after installing a route). The change
> in this patch is what I missed back in April.
>
> Comparing IPv4 and IPv6 code for memory allocation and freeing for FIB
> entries, transferring metrics to dst_entry and cleanup of dst_entry all
> look nearly identical - to the point that net-next could have common
> helpers to manage the refcnt'ing. I can submit those after this change
> hits net-next.
Yes. Agree. Since both v4 and v6 use the same logic on handling
metrics, helpers can be useful.
>
> Thanks for your time getting to the bottom of the leak.
next prev parent reply other threads:[~2018-09-19 6:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-18 20:44 [PATCH net 0/2] ipv6: fix issues on accessing fib6_metrics Wei Wang
2018-09-18 20:44 ` [PATCH net 1/2] Revert "ipv6: fix double refcount of fib6_metrics" Wei Wang
2018-09-18 20:45 ` [PATCH net 2/2] ipv6: fix memory leak on dst->_metrics Wei Wang
2018-09-18 23:23 ` David Ahern
2018-09-19 1:02 ` Wei Wang [this message]
2018-09-18 23:17 ` [PATCH net 1/2] Revert "ipv6: fix double refcount of fib6_metrics" David Ahern
2018-09-19 3:17 ` [PATCH net 0/2] ipv6: fix issues on accessing fib6_metrics David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAC15z3jUJ8HTPSkHj4R+=a_UJXevr96vDLBFt9D+0zodjCeMcA@mail.gmail.com' \
--to=tracywwnj@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=edumazet@google.com \
--cc=netdev@vger.kernel.org \
--cc=sd@queasysnail.net \
--cc=weiwan@google.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).