bpf: decrease usercnt if bpf_map_new_fd() fails in bpf_map_get_fd_by_id()
authorPeng Sun <[email protected]>
Tue, 26 Feb 2019 14:15:37 +0000 (22:15 +0800)
committerDaniel Borkmann <[email protected]>
Tue, 26 Feb 2019 18:08:30 +0000 (19:08 +0100)
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 <[email protected]>
Acked-by: Martin KaFai Lau <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
kernel/bpf/syscall.c

index 8577bb7f8be6739f143667af19f916b04de01126..f98328abe8fabea3ff34bb34d499278fc878e972 100644 (file)
@@ -1986,7 +1986,7 @@ static int bpf_map_get_fd_by_id(const union bpf_attr *attr)
 
        fd = bpf_map_new_fd(map, f_flags);
        if (fd < 0)
-               bpf_map_put(map);
+               bpf_map_put_with_uref(map);
 
        return fd;
 }