On Thu, Mar 20, 2025 at 4:43 AM Jiri Olsa <jo...@kernel.org> wrote: > > Adding new uprobe syscall that calls uprobe handlers for given > 'breakpoint' address. > > The idea is that the 'breakpoint' address calls the user space > trampoline which executes the uprobe syscall. > > The syscall handler reads the return address of the initial call > to retrieve the original 'breakpoint' address. With this address > we find the related uprobe object and call its consumers. > > Adding the arch_uprobe_trampoline_mapping function that provides > uprobe trampoline mapping. This mapping is backed with one global > page initialized at __init time and shared by the all the mapping > instances. > > We do not allow to execute uprobe syscall if the caller is not > from uprobe trampoline mapping. > > The uprobe syscall ensures the consumer (bpf program) sees registers > values in the state before the trampoline was called. > > Signed-off-by: Jiri Olsa <jo...@kernel.org> > --- > arch/x86/entry/syscalls/syscall_64.tbl | 1 + > arch/x86/kernel/uprobes.c | 134 +++++++++++++++++++++++++ > include/linux/syscalls.h | 2 + > include/linux/uprobes.h | 1 + > kernel/events/uprobes.c | 22 ++++ > kernel/sys_ni.c | 1 + > 6 files changed, 161 insertions(+) >
[...] > +void handle_syscall_uprobe(struct pt_regs *regs, unsigned long bp_vaddr) > +{ > + struct uprobe *uprobe; > + int is_swbp; > + > + rcu_read_lock_trace(); > + uprobe = find_active_uprobe_rcu(bp_vaddr, &is_swbp); > + if (!uprobe) > + goto unlock; > + > + if (!get_utask()) > + goto unlock; > + > + if (arch_uprobe_ignore(&uprobe->arch, regs)) > + goto unlock; > + > + handler_chain(uprobe, regs); > + > + unlock: > + rcu_read_unlock_trace(); we now have `guard(rcu_tasks_trace)();`, let's use that in this function, seems like a good fit? > +} > + > /* > * Perform required fix-ups and disable singlestep. > * Allow pending signals to take effect. > diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c > index c00a86931f8c..bf5d05c635ff 100644 > --- a/kernel/sys_ni.c > +++ b/kernel/sys_ni.c > @@ -392,3 +392,4 @@ COND_SYSCALL(setuid16); > COND_SYSCALL(rseq); > > COND_SYSCALL(uretprobe); > +COND_SYSCALL(uprobe); > -- > 2.49.0 >