mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
bpf: Fix unpopulated path_size when uprobe_multi fields unset
[ Upstream commitad6b5b6ea9] 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:e56fdbfb06("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 Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
35f3ba73c0
commit
2634bfdbdb
@@ -3222,7 +3222,8 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link,
|
|||||||
struct bpf_uprobe_multi_link *umulti_link;
|
struct bpf_uprobe_multi_link *umulti_link;
|
||||||
u32 ucount = info->uprobe_multi.count;
|
u32 ucount = info->uprobe_multi.count;
|
||||||
int err = 0, i;
|
int err = 0, i;
|
||||||
long left;
|
char *p, *buf;
|
||||||
|
long left = 0;
|
||||||
|
|
||||||
if (!upath ^ !upath_size)
|
if (!upath ^ !upath_size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -3236,26 +3237,23 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link,
|
|||||||
info->uprobe_multi.pid = umulti_link->task ?
|
info->uprobe_multi.pid = umulti_link->task ?
|
||||||
task_pid_nr_ns(umulti_link->task, task_active_pid_ns(current)) : 0;
|
task_pid_nr_ns(umulti_link->task, task_active_pid_ns(current)) : 0;
|
||||||
|
|
||||||
if (upath) {
|
upath_size = upath_size ? min_t(u32, upath_size, PATH_MAX) : PATH_MAX;
|
||||||
char *p, *buf;
|
buf = kmalloc(upath_size, GFP_KERNEL);
|
||||||
|
if (!buf)
|
||||||
upath_size = min_t(u32, upath_size, PATH_MAX);
|
return -ENOMEM;
|
||||||
|
p = d_path(&umulti_link->path, buf, upath_size);
|
||||||
buf = kmalloc(upath_size, GFP_KERNEL);
|
if (IS_ERR(p)) {
|
||||||
if (!buf)
|
|
||||||
return -ENOMEM;
|
|
||||||
p = d_path(&umulti_link->path, buf, upath_size);
|
|
||||||
if (IS_ERR(p)) {
|
|
||||||
kfree(buf);
|
|
||||||
return PTR_ERR(p);
|
|
||||||
}
|
|
||||||
upath_size = buf + upath_size - p;
|
|
||||||
left = copy_to_user(upath, p, upath_size);
|
|
||||||
kfree(buf);
|
kfree(buf);
|
||||||
if (left)
|
return PTR_ERR(p);
|
||||||
return -EFAULT;
|
|
||||||
info->uprobe_multi.path_size = upath_size;
|
|
||||||
}
|
}
|
||||||
|
upath_size = buf + upath_size - p;
|
||||||
|
|
||||||
|
if (upath)
|
||||||
|
left = copy_to_user(upath, p, upath_size);
|
||||||
|
kfree(buf);
|
||||||
|
if (left)
|
||||||
|
return -EFAULT;
|
||||||
|
info->uprobe_multi.path_size = upath_size;
|
||||||
|
|
||||||
if (!uoffsets && !ucookies && !uref_ctr_offsets)
|
if (!uoffsets && !ucookies && !uref_ctr_offsets)
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user