]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
bpf: drop refcount if bpf_map_new_fd() fails in map_create()
authorPeng Sun <sironhide0null@gmail.com>
Wed, 27 Feb 2019 14:36:25 +0000 (22:36 +0800)
committerMarcelo Henrique Cerri <marcelo.cerri@canonical.com>
Fri, 17 Jan 2020 17:21:41 +0000 (14:21 -0300)
BugLink: https://bugs.launchpad.net/bugs/1855787
[ Upstream commit 352d20d611414715353ee65fc206ee57ab1a6984 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
kernel/bpf/syscall.c

index e7126adfd90321acb8253a221629ef22b9e9d9cb..6cebfead2383fbbaf9c96aa43ab854d86219bf58 100644 (file)
@@ -439,12 +439,12 @@ static int map_create(union bpf_attr *attr)
        err = bpf_map_new_fd(map, f_flags);
        if (err < 0) {
                /* 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
                 * to the userspace and the userspace may
                 * have refcnt-ed it through BPF_MAP_GET_FD_BY_ID.
                 */
-               bpf_map_put(map);
+               bpf_map_put_with_uref(map);
                return err;
        }