Skip to content

Commit 1028ae4

Browse files
fomichevAlexei Starovoitov
authored and
Alexei Starovoitov
committed
bpf: Deref map in BPF_PROG_BIND_MAP when it's already used
We are missing a deref for the case when we are doing BPF_PROG_BIND_MAP on a map that's being already held by the program. There is 'if (ret) bpf_map_put(map)' below which doesn't trigger because we don't consider this an error. Let's add missing bpf_map_put() for this specific condition. Fixes: ef15314 ("bpf: Add BPF_PROG_BIND_MAP syscall") Reported-by: Alexei Starovoitov <[email protected]> Signed-off-by: Stanislav Fomichev <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent fb91db0 commit 1028ae4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/bpf/syscall.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4323,8 +4323,10 @@ static int bpf_prog_bind_map(union bpf_attr *attr)
43234323
used_maps_old = prog->aux->used_maps;
43244324

43254325
for (i = 0; i < prog->aux->used_map_cnt; i++)
4326-
if (used_maps_old[i] == map)
4326+
if (used_maps_old[i] == map) {
4327+
bpf_map_put(map);
43274328
goto out_unlock;
4329+
}
43284330

43294331
used_maps_new = kmalloc_array(prog->aux->used_map_cnt + 1,
43304332
sizeof(used_maps_new[0]),

0 commit comments

Comments
 (0)