* [PATCH] bpf: drop refcount if bpf_map_new_fd() fails in map_create()
@ 2019-02-27 14:36 zerons
2019-02-27 16:52 ` Martin Lau
0 siblings, 1 reply; 3+ messages in thread
From: zerons @ 2019-02-27 14:36 UTC (permalink / raw)
To: ast, daniel; +Cc: netdev, linux-kernel, Peng Sun
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.
Signed-off-by: Peng Sun <sironhide0null@gmail.com>
---
kernel/bpf/syscall.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index cf5040f..1c4f1c4 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] bpf: drop refcount if bpf_map_new_fd() fails in map_create()
2019-02-27 14:36 [PATCH] bpf: drop refcount if bpf_map_new_fd() fails in map_create() zerons
@ 2019-02-27 16:52 ` Martin Lau
2019-02-28 1:15 ` Alexei Starovoitov
0 siblings, 1 reply; 3+ messages in thread
From: Martin Lau @ 2019-02-27 16:52 UTC (permalink / raw)
To: zerons
Cc: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
On Wed, Feb 27, 2019 at 10:36:25PM +0800, zerons wrote:
> 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")
Acked-by: Martin KaFai Lau <kafai@fb.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] bpf: drop refcount if bpf_map_new_fd() fails in map_create()
2019-02-27 16:52 ` Martin Lau
@ 2019-02-28 1:15 ` Alexei Starovoitov
0 siblings, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2019-02-28 1:15 UTC (permalink / raw)
To: Martin Lau
Cc: zerons, ast@kernel.org, daniel@iogearbox.net,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
On Wed, Feb 27, 2019 at 04:52:16PM +0000, Martin Lau wrote:
> On Wed, Feb 27, 2019 at 10:36:25PM +0800, zerons wrote:
> > 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")
> Acked-by: Martin KaFai Lau <kafai@fb.com>
Applied, Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-02-28 1:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-27 14:36 [PATCH] bpf: drop refcount if bpf_map_new_fd() fails in map_create() zerons
2019-02-27 16:52 ` Martin Lau
2019-02-28 1:15 ` Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox