Skip to content

Commit eaafb6d

Browse files
Tao Chentheihor
authored andcommitted
bpf: Disable migrate when kprobe_multi attach to access bpf_prog_active
The syscall link_create not protected by bpf_disable_instrumentation, accessing percpu data bpf_prog_active should use cpu local_lock when kprobe_multi program attach. Fixes: 0dcac27 ("bpf: Add multi kprobe link") Signed-off-by: Tao Chen <[email protected]>
1 parent ed19bc9 commit eaafb6d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/trace/bpf_trace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,23 +2728,23 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
27282728
struct pt_regs *regs;
27292729
int err;
27302730

2731+
migrate_disable();
27312732
if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) {
27322733
bpf_prog_inc_misses_counter(link->link.prog);
27332734
err = 1;
27342735
goto out;
27352736
}
27362737

2737-
migrate_disable();
27382738
rcu_read_lock();
27392739
regs = ftrace_partial_regs(fregs, bpf_kprobe_multi_pt_regs_ptr());
27402740
old_run_ctx = bpf_set_run_ctx(&run_ctx.session_ctx.run_ctx);
27412741
err = bpf_prog_run(link->link.prog, regs);
27422742
bpf_reset_run_ctx(old_run_ctx);
27432743
rcu_read_unlock();
2744-
migrate_enable();
27452744

27462745
out:
27472746
__this_cpu_dec(bpf_prog_active);
2747+
migrate_enable();
27482748
return err;
27492749
}
27502750

0 commit comments

Comments
 (0)