diff options
author | Yonghong Song <yhs@fb.com> | 2017-11-30 16:47:54 -0500 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2017-11-30 20:56:10 -0500 |
commit | c8c088ba0edf65044c254b96fc438c91914aaab0 (patch) | |
tree | 26c2ce03951344a5241e1084cbb68d36275cc61a | |
parent | 2b279419567105d63f1e524bb1ac34ae8f918e5d (diff) |
bpf: set maximum number of attached progs to 64 for a single perf tp
cgropu+bpf prog array has a maximum number of 64 programs.
Let us apply the same limit here.
Fixes: e87c6bc3852b ("bpf: permit multiple bpf attachments for a single perf event")
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r-- | kernel/bpf/core.c | 3 | ||||
-rw-r--r-- | kernel/trace/bpf_trace.c | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index b9f8686a84cf..86b50aa26ee8 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c | |||
@@ -1447,7 +1447,8 @@ int bpf_prog_array_length(struct bpf_prog_array __rcu *progs) | |||
1447 | rcu_read_lock(); | 1447 | rcu_read_lock(); |
1448 | prog = rcu_dereference(progs)->progs; | 1448 | prog = rcu_dereference(progs)->progs; |
1449 | for (; *prog; prog++) | 1449 | for (; *prog; prog++) |
1450 | cnt++; | 1450 | if (*prog != &dummy_bpf_prog.prog) |
1451 | cnt++; | ||
1451 | rcu_read_unlock(); | 1452 | rcu_read_unlock(); |
1452 | return cnt; | 1453 | return cnt; |
1453 | } | 1454 | } |
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 27d1f4ffa3de..0ce99c379c30 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c | |||
@@ -759,6 +759,8 @@ const struct bpf_prog_ops perf_event_prog_ops = { | |||
759 | 759 | ||
760 | static DEFINE_MUTEX(bpf_event_mutex); | 760 | static DEFINE_MUTEX(bpf_event_mutex); |
761 | 761 | ||
762 | #define BPF_TRACE_MAX_PROGS 64 | ||
763 | |||
762 | int perf_event_attach_bpf_prog(struct perf_event *event, | 764 | int perf_event_attach_bpf_prog(struct perf_event *event, |
763 | struct bpf_prog *prog) | 765 | struct bpf_prog *prog) |
764 | { | 766 | { |
@@ -772,6 +774,12 @@ int perf_event_attach_bpf_prog(struct perf_event *event, | |||
772 | goto unlock; | 774 | goto unlock; |
773 | 775 | ||
774 | old_array = event->tp_event->prog_array; | 776 | old_array = event->tp_event->prog_array; |
777 | if (old_array && | ||
778 | bpf_prog_array_length(old_array) >= BPF_TRACE_MAX_PROGS) { | ||
779 | ret = -E2BIG; | ||
780 | goto unlock; | ||
781 | } | ||
782 | |||
775 | ret = bpf_prog_array_copy(old_array, NULL, prog, &new_array); | 783 | ret = bpf_prog_array_copy(old_array, NULL, prog, &new_array); |
776 | if (ret < 0) | 784 | if (ret < 0) |
777 | goto unlock; | 785 | goto unlock; |