BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Anton Protopopov <aspsk@isovalent.com>, Song Liu <song@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf] bpf: fix a memory leak in the LRU and LRU_PERCPU hash maps
Date: Mon, 22 May 2023 10:33:54 -0700	[thread overview]
Message-ID: <d3865088-45df-ab48-3631-c48c84baa727@linux.dev> (raw)
In-Reply-To: <ZGuUii1nfyvXzX4g@zh-lab-node-5>

On 5/22/23 9:12 AM, Anton Protopopov wrote:
> On Mon, May 22, 2023 at 03:45:58PM +0000, Anton Protopopov wrote:
>> The LRU and LRU_PERCPU maps allocate a new element on update before locking the
>> target hash table bucket. Right after that the maps try to lock the bucket.
>> If this fails, then maps return -EBUSY to the caller without releasing the
>> allocated element. This makes the element untracked: it doesn't belong to
>> either of free lists, and it doesn't belong to the hash table, so can't be
>> re-used; this eventually leads to the permanent -ENOMEM on LRU map updates,
>> which is unexpected.

Ouch. This is very bad. :(

Excellent catch. Applied.

I am thinking if a test could be written but it does not seem like anything 
after htab_lock_bucket() is traceable. Not sure if Song may have good idea?

>> Fix this by returning the element to the local free list if bucket locking fails.
> Fixes: 20b6cc34ea74 ("bpf: Avoid hashtab deadlock with map_locked")
> 


      reply	other threads:[~2023-05-22 17:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22 15:45 [PATCH bpf] bpf: fix a memory leak in the LRU and LRU_PERCPU hash maps Anton Protopopov
2023-05-22 16:12 ` Anton Protopopov
2023-05-22 17:33   ` Martin KaFai Lau [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=d3865088-45df-ab48-3631-c48c84baa727@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=aspsk@isovalent.com \
    --cc=bpf@vger.kernel.org \
    --cc=song@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