bpf: sockmap, map_release does not hold refcnt for pinned maps
authorJohn Fastabend <john.fastabend@gmail.com>
Mon, 23 Apr 2018 22:39:23 +0000 (15:39 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 4 Nov 2018 13:52:44 +0000 (14:52 +0100)
commit3c0cff34e91e4ea1fdf74df65db98ee455190dfa
treebfe38a503ea726ae9ac5963c9663a0bb0d52beb9
parentdb9d15988afb923b6e559c8aa3ef56d596f74524
bpf: sockmap, map_release does not hold refcnt for pinned maps

[ Upstream commit ba6b8de423f8d0dee48d6030288ed81c03ddf9f0 ]

Relying on map_release hook to decrement the reference counts when a
map is removed only works if the map is not being pinned. In the
pinned case the ref is decremented immediately and the BPF programs
released. After this BPF programs may not be in-use which is not
what the user would expect.

This patch moves the release logic into bpf_map_put_uref() and brings
sockmap in-line with how a similar case is handled in prog array maps.

Fixes: 3d9e952697de ("bpf: sockmap, fix leaking maps with attached but not detached progs")
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/bpf.h
kernel/bpf/arraymap.c
kernel/bpf/sockmap.c
kernel/bpf/syscall.c