aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/syscall.c
diff options
context:
space:
mode:
authorPeng Sun <sironhide0null@gmail.com>2019-02-27 09:36:25 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2019-03-01 10:04:29 -0500
commit352d20d611414715353ee65fc206ee57ab1a6984 (patch)
treec856f1153a8c8551c974aa908088bdd1fe6499ac /kernel/bpf/syscall.c
parent781e62823cb81b972dc8652c1827205cda2ac9ac (diff)
bpf: drop refcount if bpf_map_new_fd() fails in map_create()
In bpf/syscall.c, map_create() first set map->usercnt to 1, a file descriptor is supposed to return to userspace. When bpf_map_new_fd() fails, drop the refcount. 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: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r--kernel/bpf/syscall.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index f98328abe8fa..84470d1480aa 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -559,12 +559,12 @@ static int map_create(union bpf_attr *attr)
559 err = bpf_map_new_fd(map, f_flags); 559 err = bpf_map_new_fd(map, f_flags);
560 if (err < 0) { 560 if (err < 0) {
561 /* failed to allocate fd. 561 /* failed to allocate fd.
562 * bpf_map_put() is needed because the above 562 * bpf_map_put_with_uref() is needed because the above
563 * bpf_map_alloc_id() has published the map 563 * bpf_map_alloc_id() has published the map
564 * to the userspace and the userspace may 564 * to the userspace and the userspace may
565 * have refcnt-ed it through BPF_MAP_GET_FD_BY_ID. 565 * have refcnt-ed it through BPF_MAP_GET_FD_BY_ID.
566 */ 566 */
567 bpf_map_put(map); 567 bpf_map_put_with_uref(map);
568 return err; 568 return err;
569 } 569 }
570 570