From: Sean Young <sean@mess.org>
To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexei Starovoitov <ast@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
netdev@vger.kernel.org, Matthias Reichl <hias@horus.com>,
Devin Heitmueller <dheitmueller@kernellabs.com>,
Y Song <ys114321@gmail.com>,
Quentin Monnet <quentin.monnet@netronome.com>
Subject: [PATCH v5 1/3] bpf: bpf_prog_array_copy() should return -ENOENT if exclude_prog not found
Date: Sun, 27 May 2018 12:24:08 +0100 [thread overview]
Message-ID: <d44044258b35a965d71db5e8ee26289d0fc75ec2.1527419762.git.sean@mess.org> (raw)
In-Reply-To: <cover.1527419762.git.sean@mess.org>
In-Reply-To: <cover.1527419762.git.sean@mess.org>
This makes is it possible for bpf prog detach to return -ENOENT.
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Sean Young <sean@mess.org>
---
kernel/bpf/core.c | 11 +++++++++--
kernel/trace/bpf_trace.c | 2 ++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index b574dddc05b8..527587de8a67 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1616,6 +1616,7 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
int new_prog_cnt, carry_prog_cnt = 0;
struct bpf_prog **existing_prog;
struct bpf_prog_array *array;
+ bool found_exclude = false;
int new_prog_idx = 0;
/* Figure out how many existing progs we need to carry over to
@@ -1624,14 +1625,20 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
if (old_array) {
existing_prog = old_array->progs;
for (; *existing_prog; existing_prog++) {
- if (*existing_prog != exclude_prog &&
- *existing_prog != &dummy_bpf_prog.prog)
+ if (*existing_prog == exclude_prog) {
+ found_exclude = true;
+ continue;
+ }
+ if (*existing_prog != &dummy_bpf_prog.prog)
carry_prog_cnt++;
if (*existing_prog == include_prog)
return -EEXIST;
}
}
+ if (exclude_prog && !found_exclude)
+ return -ENOENT;
+
/* How many progs (not NULL) will be in the new array? */
new_prog_cnt = carry_prog_cnt;
if (include_prog)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 81fdf2fc94ac..af1486d9a0ed 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1006,6 +1006,8 @@ void perf_event_detach_bpf_prog(struct perf_event *event)
old_array = event->tp_event->prog_array;
ret = bpf_prog_array_copy(old_array, event->prog, NULL, &new_array);
+ if (ret == -ENOENT)
+ goto unlock;
if (ret < 0) {
bpf_prog_array_delete_safe(old_array, event->prog);
} else {
--
2.17.0
next prev parent reply other threads:[~2018-05-27 11:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-27 11:24 [PATCH v5 0/3] IR decoding using BPF Sean Young
2018-05-27 11:24 ` Sean Young [this message]
2018-05-27 11:24 ` [PATCH v5 2/3] media: rc: introduce BPF_PROG_LIRC_MODE2 Sean Young
2018-06-04 17:47 ` Matthias Reichl
2018-06-05 10:16 ` Sean Young
2018-06-05 10:33 ` Daniel Borkmann
2018-06-06 21:09 ` [PATCH] bpf: attach type BPF_LIRC_MODE2 should not depend on CONFIG_BPF_CGROUP Sean Young
2018-06-07 18:12 ` Simon Horman
2018-06-07 18:14 ` Y Song
2018-06-07 22:40 ` Daniel Borkmann
2018-06-14 18:42 ` [PATCH] bpf: attach type BPF_LIRC_MODE2 should not depend on CONFIG_CGROUP_BPF Sean Young
2018-06-15 14:03 ` Daniel Borkmann
2018-06-18 17:12 ` [PATCH v3] " Sean Young
2018-06-18 18:46 ` kbuild test robot
2018-06-18 22:56 ` Sean Young
2018-06-18 23:04 ` [PATCH v4] " Sean Young
2018-06-26 10:03 ` Daniel Borkmann
2018-05-27 11:24 ` [PATCH v5 3/3] bpf: add selftest for lirc_mode2 type program Sean Young
2018-05-30 10:57 ` [PATCH v5 0/3] IR decoding using BPF Daniel Borkmann
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=d44044258b35a965d71db5e8ee26289d0fc75ec2.1527419762.git.sean@mess.org \
--to=sean@mess.org \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=dheitmueller@kernellabs.com \
--cc=hias@horus.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=quentin.monnet@netronome.com \
--cc=ys114321@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).