bpf: decrease usercnt if bpf_map_new_fd() fails in bpf_map_get_fd_by_id()
authorPeng Sun <sironhide0null@gmail.com>
Tue, 26 Feb 2019 14:15:37 +0000 (22:15 +0800)
committerCosmin Tanislav <demonsingur@gmail.com>
Thu, 16 May 2024 07:58:22 +0000 (10:58 +0300)
commit929ce038556398617480aca256c6cc92f87d859e
treef302b91ab083454cbe38c525cb6b1be6a565b0af
parent7e248259dfba1e08ff593f7c4c36e62e2be9169b
bpf: decrease usercnt if bpf_map_new_fd() fails in bpf_map_get_fd_by_id()

[ Upstream commit 781e62823cb81b972dc8652c1827205cda2ac9ac ]

In bpf/syscall.c, bpf_map_get_fd_by_id() use bpf_map_inc_not_zero()
to increase the refcount, both map->refcnt and map->usercnt. Then, if
bpf_map_new_fd() fails, should handle map->usercnt too.

Fixes: bd5f5f4ecb78 ("bpf: Add BPF_MAP_GET_FD_BY_ID")
Signed-off-by: Peng Sun <sironhide0null@gmail.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/bpf/syscall.c