Skip to contentSkip to conversation

bpf: reject override_return programs on uprobe_multi links

PATCH In review Sechang Lim 2 participants 2 messages Nov 19 – Nov 24

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: reject override_return programs on uprobe_multi links

bpf_override_return() changes pt_regs->ip to the kernel's just_return_func for kprobe error injection. Perf uprobes reject programs using this helper, but uprobe_multi links accept them even though their pt_regs belong to a user task. When the probe runs, the task returns to user mode with a kernel address as its instruction pointer, faults, and exposes that address in its signal frame.

Reject programs marked kprobe_override when creating an uprobe_multi link. This covers both entry and return probes and matches the perf uprobe restriction.

Fixes 89ae89f53d20 ("bpf: Add multi uprobe link")
---
 kernel/trace/bpf_trace.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/trace/bpf_trace.c +3 -0
index d22e78e7f28d..45ff81dbca96 100644
@@ -3297,6 +3297,9 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	if (!is_uprobe_multi(prog))
 		return -EINVAL;
 
+	if (prog->kprobe_override)
+		return -EINVAL;
+
 	flags = attr->link_create.uprobe_multi.flags;
 	if (flags & ~(BPF_F_UPROBE_MULTI_RETURN | BPF_F_UPROBE_MULTI_PATH_FD))
 		return -EINVAL;
Signature · 1 line
2.56.1
#1 lore raw
Quoted 6 lines · Sechang Lim

bpf_override_return() changes pt_regs->ip to the kernel's just_return_func for kprobe error injection. Perf uprobes reject programs using this helper, but uprobe_multi links accept them even though their pt_regs belong to a user task. When the probe runs, the task returns to user mode with a kernel address as its instruction pointer, faults, and exposes that address in its signal frame.

That's not a bug. The prog needs CAP_BPF + CAP_PERFMON.

pw-bot: cr