From: Kris Van Hees <kris.van.hees@oracle.com>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: Kris Van Hees <kris.van.hees@oracle.com>,
netdev@vger.kernel.org, ast@kernel.org
Subject: Re: Potential memory leak in htab_map_update_elem?
Date: Fri, 11 Jan 2019 10:20:58 -0500 [thread overview]
Message-ID: <20190111152058.GC11821@oracle.com> (raw)
In-Reply-To: <bf54c86b-eca9-2dd0-a16b-c8dae86c906e@iogearbox.net>
On Fri, Jan 11, 2019 at 09:12:57AM +0100, Daniel Borkmann wrote:
> Hi Kris,
>
> On 01/11/2019 06:08 AM, Kris Van Hees wrote:
> > Maybe I am missing something trivial here, but it looks to me that there is
> > a leak of htab elements in htab_map_update_elem when you are updating an
> > existing element. After the new element is linked into the bucket list, the
> > following code snippet is found:
> >
> > if (l_old) {
> > hlist_nulls_del_rcu(&l_old->hash_node);
> > if (!htab_is_prealloc(htab))
> > free_htab_elem(htab, l_old);
> > }
> >
> > Nothing is done with l_old in the remainder of the function, and to me this
> > looks like that element is be leaked if the htab is preallocated because we
> > never add it to the free list. In fact, free_htab_elem() contains the very
> > conditional that handles the two cases (preallocated vs non-preallocated.
>
> In this case in alloc_htab_elem() we are swapping out the per-cpu extra element
> with the existing one to avoid freelist_pop/push combination in order to have
> a fast replace, meaning we cannot call free_htab_elem() on it like in plain
> htab_map_delete_elem() case.
Aha, and since it is a per-cpu extra element, you never run into a problem
with two updates using this trick because only one update can ever be ongoing
per cpu. Nifty!
Thanks for explaining!
Kris
prev parent reply other threads:[~2019-01-11 15:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-11 5:08 Potential memory leak in htab_map_update_elem? Kris Van Hees
2019-01-11 8:12 ` Daniel Borkmann
2019-01-11 15:20 ` Kris Van Hees [this message]
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=20190111152058.GC11821@oracle.com \
--to=kris.van.hees@oracle.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=netdev@vger.kernel.org \
/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).