提交 03056113 编写于 作者: P Peng Sun 提交者: Xie XiuQi

bpf: drop refcount if bpf_map_new_fd() fails in map_create()

mainline inclusion
from mainline-5.0
commit 352d20d611414715353ee65fc206ee57ab1a6984
category: bugfix
bugzilla: 11102
CVE: NA

-------------------------------------------------
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: bd5f5f4e ("bpf: Add BPF_MAP_GET_FD_BY_ID")
Signed-off-by: NPeng Sun <sironhide0null@gmail.com>
Acked-by: NMartin KaFai Lau <kafai@fb.com>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
(cherry picked from commit 352d20d611414715353ee65fc206ee57ab1a6984)
Signed-off-by: NZhen Lei <thunder.leizhen@huawei.com>
Reviewed-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 eda04c10
...@@ -559,12 +559,12 @@ static int map_create(union bpf_attr *attr) ...@@ -559,12 +559,12 @@ static int map_create(union bpf_attr *attr)
err = bpf_map_new_fd(map, f_flags); err = bpf_map_new_fd(map, f_flags);
if (err < 0) { if (err < 0) {
/* failed to allocate fd. /* failed to allocate fd.
* bpf_map_put() is needed because the above * bpf_map_put_with_uref() is needed because the above
* bpf_map_alloc_id() has published the map * bpf_map_alloc_id() has published the map
* to the userspace and the userspace may * to the userspace and the userspace may
* have refcnt-ed it through BPF_MAP_GET_FD_BY_ID. * have refcnt-ed it through BPF_MAP_GET_FD_BY_ID.
*/ */
bpf_map_put(map); bpf_map_put_with_uref(map);
return err; return err;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册