Skip to contentSkip to conversation

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

PATCH Applied zerons 3 participants 3 messages Feb 27, 2019 – Feb 28, 2019

Subsystems (4)
lore
Share & tools
lore

zerons

author
#0 lore raw

PATCH 1/1 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.

---
 kernel/bpf/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/syscall.c +2 -2
index cf5040f..1c4f1c4 100644
@@ -558,12 +558,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;
 	}
 

--
2.7.4

Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · zerons

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.

Thanks for the patch.

Please add a Fixes tag for bug fix in the future.

Fixes bd5f5f4ecb78 ("bpf: Add BPF_MAP_GET_FD_BY_ID")
#2 lore raw
Quoted 9 lines · Martin Lau
Quoted 2 lines · zerons

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.

Thanks for the patch.

Please add a Fixes tag for bug fix in the future.

Fixes bd5f5f4ecb78 ("bpf: Add BPF_MAP_GET_FD_BY_ID")

Applied, Thanks