Blob Blame History Raw
From: Peng Sun <sironhide0null@gmail.com>
Date: Tue, 26 Feb 2019 22:15:37 +0800
Subject: bpf: decrease usercnt if bpf_map_new_fd() fails in
 bpf_map_get_fd_by_id()
Patch-mainline: v5.0
Git-commit: 781e62823cb81b972dc8652c1827205cda2ac9ac
References: bsc#1056787 bsc#1083647

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>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
 kernel/bpf/syscall.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1802,7 +1802,7 @@ static int bpf_map_get_fd_by_id(const un
 
 	fd = bpf_map_new_fd(map, f_flags);
 	if (fd < 0)
-		bpf_map_put(map);
+		bpf_map_put_with_uref(map);
 
 	return fd;
 }