Skip to content

Commit 3983c00

Browse files
olsajirianakryiko
authored andcommitted
bpf: Fail uprobe multi link with negative offset
Currently the __uprobe_register will return 0 (success) when called with negative offset. The reason is that the call to register_for_each_vma and then build_map_info won't return error for negative offset. They just won't do anything - no matching vma is found so there's no registered breakpoint for the uprobe. I don't think we can change the behaviour of __uprobe_register and fail for negative uprobe offset, because apps might depend on that already. But I think we can still make the change and check for it on bpf multi link syscall level. Also moving the __get_user call and check for the offsets to the top of loop, to fail early without extra __get_user calls for ref_ctr_offset and cookie arrays. Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent e58aac1 commit 3983c00

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

kernel/trace/bpf_trace.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,15 +3391,19 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
33913391
goto error_free;
33923392

33933393
for (i = 0; i < cnt; i++) {
3394-
if (ucookies && __get_user(uprobes[i].cookie, ucookies + i)) {
3394+
if (__get_user(uprobes[i].offset, uoffsets + i)) {
33953395
err = -EFAULT;
33963396
goto error_free;
33973397
}
3398+
if (uprobes[i].offset < 0) {
3399+
err = -EINVAL;
3400+
goto error_free;
3401+
}
33983402
if (uref_ctr_offsets && __get_user(uprobes[i].ref_ctr_offset, uref_ctr_offsets + i)) {
33993403
err = -EFAULT;
34003404
goto error_free;
34013405
}
3402-
if (__get_user(uprobes[i].offset, uoffsets + i)) {
3406+
if (ucookies && __get_user(uprobes[i].cookie, ucookies + i)) {
34033407
err = -EFAULT;
34043408
goto error_free;
34053409
}

0 commit comments

Comments
 (0)