]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
bpf: fix htab map destruction when extra reserve is in use
authorDaniel Borkmann <daniel@iogearbox.net>
Thu, 3 Nov 2016 23:01:19 +0000 (00:01 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 21 Nov 2016 09:11:35 +0000 (10:11 +0100)
commit09ee09498bcae967b6bde03940c8ba45dcd19875
tree79a0956451c06fad2fbd32a35c2462b50887cbb1
parentde289ad2e5754953716f8d835846c804137a3a08
bpf: fix htab map destruction when extra reserve is in use

[ Upstream commit 483bed2b0ddd12ec33fc9407e0c6e1088e77a97c ]

Commit a6ed3ea65d98 ("bpf: restore behavior of bpf_map_update_elem")
added an extra per-cpu reserve to the hash table map to restore old
behaviour from pre prealloc times. When non-prealloc is in use for a
map, then problem is that once a hash table extra element has been
linked into the hash-table, and the hash table is destroyed due to
refcount dropping to zero, then htab_map_free() -> delete_all_elements()
will walk the whole hash table and drop all elements via htab_elem_free().
The problem is that the element from the extra reserve is first fed
to the wrong backend allocator and eventually freed twice.

Fixes: a6ed3ea65d98 ("bpf: restore behavior of bpf_map_update_elem")
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/bpf/hashtab.c