public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: zerons <sironhide0null@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peng Sun <sironhide0null@gmail.com>
Subject: [PATCH] bpf: drop refcount if bpf_map_new_fd() fails in map_create()
Date: Wed, 27 Feb 2019 22:36:25 +0800	[thread overview]
Message-ID: <1551278185-5219-1-git-send-email-sironhide0null@gmail.com> (raw)

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


             reply	other threads:[~2019-02-27 14:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27 14:36 zerons [this message]
2019-02-27 16:52 ` [PATCH] bpf: drop refcount if bpf_map_new_fd() fails in map_create() Martin Lau
2019-02-28  1:15   ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1551278185-5219-1-git-send-email-sironhide0null@gmail.com \
    --to=sironhide0null@gmail.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox