]> git.itanic.dy.fi Git - linux-stable/commit
bpf: fix a memory leak in the LRU and LRU_PERCPU hash maps
authorAnton Protopopov <aspsk@isovalent.com>
Mon, 22 May 2023 15:45:58 +0000 (15:45 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 30 May 2023 13:17:25 +0000 (14:17 +0100)
commit965e9cccbe6b9c7b379908cebcb5e3a47f20dd5e
tree311b148b6fd2dffbe042a435be4ee2e52aa0c51b
parent5ed48306af3afdc971d5f6383257430f8e811569
bpf: fix a memory leak in the LRU and LRU_PERCPU hash maps

commit b34ffb0c6d23583830f9327864b9c1f486003305 upstream.

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. Fix this by returning the element to the local free list
if bucket locking fails.

Fixes: 20b6cc34ea74 ("bpf: Avoid hashtab deadlock with map_locked")
Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
Link: https://lore.kernel.org/r/20230522154558.2166815-1-aspsk@isovalent.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/bpf/hashtab.c