Skip to content

Commit ad6b5b6

Browse files
ver-nyananakryiko
authored andcommitted
bpf: Fix unpopulated path_size when uprobe_multi fields unset
Previously when retrieving `bpf_link_info.uprobe_multi` with `path` and `path_size` fields unset, the `path_size` field is not populated (remains 0). This behavior was inconsistent with how other input/output string buffer fields work, as the field should be populated in cases when: - both buffer and length are set (currently works as expected) - both buffer and length are unset (not working as expected) This patch now fills the `path_size` field when `path` and `path_size` are unset. Fixes: e56fdbf ("bpf: Add link_info support for uprobe multi link") Signed-off-by: Tyrone Wu <wudevelops@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20241011000803.681190-1-wudevelops@gmail.com
1 parent fd526e1 commit ad6b5b6

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

kernel/trace/bpf_trace.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,7 +3133,8 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link,
31333133
struct bpf_uprobe_multi_link *umulti_link;
31343134
u32 ucount = info->uprobe_multi.count;
31353135
int err = 0, i;
3136-
long left;
3136+
char *p, *buf;
3137+
long left = 0;
31373138

31383139
if (!upath ^ !upath_size)
31393140
return -EINVAL;
@@ -3147,26 +3148,23 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link,
31473148
info->uprobe_multi.pid = umulti_link->task ?
31483149
task_pid_nr_ns(umulti_link->task, task_active_pid_ns(current)) : 0;
31493150

3150-
if (upath) {
3151-
char *p, *buf;
3152-
3153-
upath_size = min_t(u32, upath_size, PATH_MAX);
3154-
3155-
buf = kmalloc(upath_size, GFP_KERNEL);
3156-
if (!buf)
3157-
return -ENOMEM;
3158-
p = d_path(&umulti_link->path, buf, upath_size);
3159-
if (IS_ERR(p)) {
3160-
kfree(buf);
3161-
return PTR_ERR(p);
3162-
}
3163-
upath_size = buf + upath_size - p;
3164-
left = copy_to_user(upath, p, upath_size);
3151+
upath_size = upath_size ? min_t(u32, upath_size, PATH_MAX) : PATH_MAX;
3152+
buf = kmalloc(upath_size, GFP_KERNEL);
3153+
if (!buf)
3154+
return -ENOMEM;
3155+
p = d_path(&umulti_link->path, buf, upath_size);
3156+
if (IS_ERR(p)) {
31653157
kfree(buf);
3166-
if (left)
3167-
return -EFAULT;
3168-
info->uprobe_multi.path_size = upath_size;
3158+
return PTR_ERR(p);
31693159
}
3160+
upath_size = buf + upath_size - p;
3161+
3162+
if (upath)
3163+
left = copy_to_user(upath, p, upath_size);
3164+
kfree(buf);
3165+
if (left)
3166+
return -EFAULT;
3167+
info->uprobe_multi.path_size = upath_size;
31703168

31713169
if (!uoffsets && !ucookies && !uref_ctr_offsets)
31723170
return 0;

0 commit comments

Comments
 (0)