Skip to content

Commit c8c088b

Browse files
yonghong-songborkmann
authored andcommitted
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: e87c6bc ("bpf: permit multiple bpf attachments for a single perf event") Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 2b27941 commit c8c088b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

kernel/bpf/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,8 @@ int bpf_prog_array_length(struct bpf_prog_array __rcu *progs)
14471447
rcu_read_lock();
14481448
prog = rcu_dereference(progs)->progs;
14491449
for (; *prog; prog++)
1450-
cnt++;
1450+
if (*prog != &dummy_bpf_prog.prog)
1451+
cnt++;
14511452
rcu_read_unlock();
14521453
return cnt;
14531454
}

kernel/trace/bpf_trace.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,8 @@ const struct bpf_prog_ops perf_event_prog_ops = {
759759

760760
static DEFINE_MUTEX(bpf_event_mutex);
761761

762+
#define BPF_TRACE_MAX_PROGS 64
763+
762764
int perf_event_attach_bpf_prog(struct perf_event *event,
763765
struct bpf_prog *prog)
764766
{
@@ -772,6 +774,12 @@ int perf_event_attach_bpf_prog(struct perf_event *event,
772774
goto unlock;
773775

774776
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+
775783
ret = bpf_prog_array_copy(old_array, NULL, prog, &new_array);
776784
if (ret < 0)
777785
goto unlock;

0 commit comments

Comments
 (0)