Skip to content

Commit 352d20d

Browse files
snorezborkmann
authored andcommitted
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: bd5f5f4 ("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>
1 parent 781e628 commit 352d20d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/bpf/syscall.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,12 @@ static int map_create(union bpf_attr *attr)
559559
err = bpf_map_new_fd(map, f_flags);
560560
if (err < 0) {
561561
/* failed to allocate fd.
562-
* bpf_map_put() is needed because the above
562+
* bpf_map_put_with_uref() is needed because the above
563563
* bpf_map_alloc_id() has published the map
564564
* to the userspace and the userspace may
565565
* have refcnt-ed it through BPF_MAP_GET_FD_BY_ID.
566566
*/
567-
bpf_map_put(map);
567+
bpf_map_put_with_uref(map);
568568
return err;
569569
}
570570

0 commit comments

Comments
 (0)