* [PATCH bpf v1 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset
@ 2024-10-09 22:06 Tyrone Wu
2024-10-09 22:06 ` [PATCH bpf v1 2/2] selftests/bpf: assert link info uprobe_multi count & path_size if unset Tyrone Wu
0 siblings, 1 reply; 6+ messages in thread
From: Tyrone Wu @ 2024-10-09 22:06 UTC (permalink / raw)
To: bpf, wudevelops
Cc: kpsingh, mattbobrowski, song, jolsa, ast, daniel, andrii,
martin.lau, eddyz87, yonghong.song, john.fastabend, sdf, haoluo,
rostedt, mhiramat, mathieu.desnoyers, mykolal, shuah,
linux-kernel, linux-trace-kernel, linux-kselftest,
kernel-patches-bot
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: e56fdbfb06e2 ("bpf: Add link_info support for uprobe multi link")
Signed-off-by: Tyrone Wu <wudevelops@gmail.com>
---
kernel/trace/bpf_trace.c | 35 +++++++++++++++++------------------
1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index a582cd25ca87..ba34e4f3fa8f 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3133,7 +3133,8 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link,
struct bpf_uprobe_multi_link *umulti_link;
u32 ucount = info->uprobe_multi.count;
int err = 0, i;
- long left;
+ char *p, *buf;
+ long left = 0;
if (!upath ^ !upath_size)
return -EINVAL;
@@ -3147,26 +3148,24 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link,
info->uprobe_multi.pid = umulti_link->task ?
task_pid_nr_ns(umulti_link->task, task_active_pid_ns(current)) : 0;
- if (upath) {
- char *p, *buf;
-
- upath_size = min_t(u32, upath_size, PATH_MAX);
+ upath_size = upath_size ? min_t(u32, upath_size, PATH_MAX) : PATH_MAX;
+ buf = kmalloc(upath_size, GFP_KERNEL);
+ 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;
- buf = kmalloc(upath_size, GFP_KERNEL);
- 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;
+ if (upath) {
left = copy_to_user(upath, p, upath_size);
- kfree(buf);
- if (left)
- return -EFAULT;
- info->uprobe_multi.path_size = upath_size;
}
+ kfree(buf);
+ if (left)
+ return -EFAULT;
+ info->uprobe_multi.path_size = upath_size;
if (!uoffsets && !ucookies && !uref_ctr_offsets)
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH bpf v1 2/2] selftests/bpf: assert link info uprobe_multi count & path_size if unset
2024-10-09 22:06 [PATCH bpf v1 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset Tyrone Wu
@ 2024-10-09 22:06 ` Tyrone Wu
2024-10-10 22:01 ` Andrii Nakryiko
0 siblings, 1 reply; 6+ messages in thread
From: Tyrone Wu @ 2024-10-09 22:06 UTC (permalink / raw)
To: bpf, wudevelops
Cc: kpsingh, mattbobrowski, song, jolsa, ast, daniel, andrii,
martin.lau, eddyz87, yonghong.song, john.fastabend, sdf, haoluo,
rostedt, mhiramat, mathieu.desnoyers, mykolal, shuah,
linux-kernel, linux-trace-kernel, linux-kselftest,
kernel-patches-bot
Add assertions in `bpf_link_info.uprobe_multi` test to verify that
`count` and `path_size` fields are correctly populated when the fields
are unset.
This tests a previous bug where the `path_size` field was not populated
when `path` and `path_size` were unset.
Signed-off-by: Tyrone Wu <wudevelops@gmail.com>
---
tools/testing/selftests/bpf/prog_tests/fill_link_info.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
index f3932941bbaa..a38cf2a999fe 100644
--- a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
+++ b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
@@ -417,6 +417,13 @@ verify_umulti_link_info(int fd, bool retprobe, __u64 *offsets,
if (!ASSERT_NEQ(err, -1, "readlink"))
return -1;
+ memset(&info, 0, sizeof(info));
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+
+ ASSERT_EQ(info.uprobe_multi.count, 3, "info.uprobe_multi.count");
+ ASSERT_EQ(info.uprobe_multi.path_size, strlen(path) + 1,
+ "info.uprobe_multi.path_size");
+
for (bit = 0; bit < 8; bit++) {
memset(&info, 0, sizeof(info));
info.uprobe_multi.path = ptr_to_u64(path_buf);
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH bpf v1 2/2] selftests/bpf: assert link info uprobe_multi count & path_size if unset
2024-10-09 22:06 ` [PATCH bpf v1 2/2] selftests/bpf: assert link info uprobe_multi count & path_size if unset Tyrone Wu
@ 2024-10-10 22:01 ` Andrii Nakryiko
2024-10-11 0:08 ` [PATCH bpf v2 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset Tyrone Wu
0 siblings, 1 reply; 6+ messages in thread
From: Andrii Nakryiko @ 2024-10-10 22:01 UTC (permalink / raw)
To: Tyrone Wu
Cc: bpf, kpsingh, mattbobrowski, song, jolsa, ast, daniel, andrii,
martin.lau, eddyz87, yonghong.song, john.fastabend, sdf, haoluo,
rostedt, mhiramat, mathieu.desnoyers, mykolal, shuah,
linux-kernel, linux-trace-kernel, linux-kselftest,
kernel-patches-bot
On Wed, Oct 9, 2024 at 3:07 PM Tyrone Wu <wudevelops@gmail.com> wrote:
>
> Add assertions in `bpf_link_info.uprobe_multi` test to verify that
> `count` and `path_size` fields are correctly populated when the fields
> are unset.
>
> This tests a previous bug where the `path_size` field was not populated
> when `path` and `path_size` were unset.
>
> Signed-off-by: Tyrone Wu <wudevelops@gmail.com>
> ---
> tools/testing/selftests/bpf/prog_tests/fill_link_info.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
> index f3932941bbaa..a38cf2a999fe 100644
> --- a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
> +++ b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
> @@ -417,6 +417,13 @@ verify_umulti_link_info(int fd, bool retprobe, __u64 *offsets,
> if (!ASSERT_NEQ(err, -1, "readlink"))
> return -1;
>
> + memset(&info, 0, sizeof(info));
> + err = bpf_link_get_info_by_fd(fd, &info, &len);
if (!ASSERT_OK(err, "link_get_info"))
return -1;
?
Other than this, LGTM.
pw-bot: cr
> +
> + ASSERT_EQ(info.uprobe_multi.count, 3, "info.uprobe_multi.count");
> + ASSERT_EQ(info.uprobe_multi.path_size, strlen(path) + 1,
> + "info.uprobe_multi.path_size");
> +
> for (bit = 0; bit < 8; bit++) {
> memset(&info, 0, sizeof(info));
> info.uprobe_multi.path = ptr_to_u64(path_buf);
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH bpf v2 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset
2024-10-10 22:01 ` Andrii Nakryiko
@ 2024-10-11 0:08 ` Tyrone Wu
2024-10-11 0:08 ` [PATCH bpf v2 2/2] selftests/bpf: assert link info uprobe_multi count & path_size if unset Tyrone Wu
2024-10-11 2:20 ` [PATCH bpf v2 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset patchwork-bot+netdevbpf
0 siblings, 2 replies; 6+ messages in thread
From: Tyrone Wu @ 2024-10-11 0:08 UTC (permalink / raw)
To: andrii.nakryiko
Cc: andrii, ast, bpf, daniel, eddyz87, haoluo, john.fastabend, jolsa,
kernel-patches-bot, kpsingh, linux-kernel, linux-kselftest,
linux-trace-kernel, martin.lau, mathieu.desnoyers, mattbobrowski,
mhiramat, mykolal, rostedt, sdf, shuah, song, wudevelops,
yonghong.song
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: e56fdbfb06e2 ("bpf: Add link_info support for uprobe multi link")
Signed-off-by: Tyrone Wu <wudevelops@gmail.com>
---
V1 -> V2: no change
kernel/trace/bpf_trace.c | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index a582cd25ca87..3bd402fa62a4 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3133,7 +3133,8 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link,
struct bpf_uprobe_multi_link *umulti_link;
u32 ucount = info->uprobe_multi.count;
int err = 0, i;
- long left;
+ char *p, *buf;
+ long left = 0;
if (!upath ^ !upath_size)
return -EINVAL;
@@ -3147,26 +3148,23 @@ static int bpf_uprobe_multi_link_fill_link_info(const struct bpf_link *link,
info->uprobe_multi.pid = umulti_link->task ?
task_pid_nr_ns(umulti_link->task, task_active_pid_ns(current)) : 0;
- if (upath) {
- char *p, *buf;
-
- upath_size = min_t(u32, upath_size, PATH_MAX);
-
- buf = kmalloc(upath_size, GFP_KERNEL);
- 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);
+ upath_size = upath_size ? min_t(u32, upath_size, PATH_MAX) : PATH_MAX;
+ buf = kmalloc(upath_size, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+ p = d_path(&umulti_link->path, buf, upath_size);
+ if (IS_ERR(p)) {
kfree(buf);
- if (left)
- return -EFAULT;
- info->uprobe_multi.path_size = upath_size;
+ return PTR_ERR(p);
}
+ 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)
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH bpf v2 2/2] selftests/bpf: assert link info uprobe_multi count & path_size if unset
2024-10-11 0:08 ` [PATCH bpf v2 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset Tyrone Wu
@ 2024-10-11 0:08 ` Tyrone Wu
2024-10-11 2:20 ` [PATCH bpf v2 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset patchwork-bot+netdevbpf
1 sibling, 0 replies; 6+ messages in thread
From: Tyrone Wu @ 2024-10-11 0:08 UTC (permalink / raw)
To: andrii.nakryiko
Cc: andrii, ast, bpf, daniel, eddyz87, haoluo, john.fastabend, jolsa,
kernel-patches-bot, kpsingh, linux-kernel, linux-kselftest,
linux-trace-kernel, martin.lau, mathieu.desnoyers, mattbobrowski,
mhiramat, mykolal, rostedt, sdf, shuah, song, wudevelops,
yonghong.song
Add assertions in `bpf_link_info.uprobe_multi` test to verify that
`count` and `path_size` fields are correctly populated when the fields
are unset.
This tests a previous bug where the `path_size` field was not populated
when `path` and `path_size` were unset.
Signed-off-by: Tyrone Wu <wudevelops@gmail.com>
---
V1 -> V2:
- Verify bpf_link_get_info_by_fd was successful before continuing with test
tools/testing/selftests/bpf/prog_tests/fill_link_info.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
index 745c5ada4c4b..d50cbd8040d4 100644
--- a/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
+++ b/tools/testing/selftests/bpf/prog_tests/fill_link_info.c
@@ -420,6 +420,15 @@ verify_umulti_link_info(int fd, bool retprobe, __u64 *offsets,
if (!ASSERT_NEQ(err, -1, "readlink"))
return -1;
+ memset(&info, 0, sizeof(info));
+ err = bpf_link_get_info_by_fd(fd, &info, &len);
+ if (!ASSERT_OK(err, "bpf_link_get_info_by_fd"))
+ return -1;
+
+ ASSERT_EQ(info.uprobe_multi.count, 3, "info.uprobe_multi.count");
+ ASSERT_EQ(info.uprobe_multi.path_size, strlen(path) + 1,
+ "info.uprobe_multi.path_size");
+
for (bit = 0; bit < 8; bit++) {
memset(&info, 0, sizeof(info));
info.uprobe_multi.path = ptr_to_u64(path_buf);
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH bpf v2 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset
2024-10-11 0:08 ` [PATCH bpf v2 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset Tyrone Wu
2024-10-11 0:08 ` [PATCH bpf v2 2/2] selftests/bpf: assert link info uprobe_multi count & path_size if unset Tyrone Wu
@ 2024-10-11 2:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-10-11 2:20 UTC (permalink / raw)
To: Tyrone Wu
Cc: andrii.nakryiko, andrii, ast, bpf, daniel, eddyz87, haoluo,
john.fastabend, jolsa, kernel-patches-bot, kpsingh, linux-kernel,
linux-kselftest, linux-trace-kernel, martin.lau,
mathieu.desnoyers, mattbobrowski, mhiramat, mykolal, rostedt, sdf,
shuah, song, yonghong.song
Hello:
This series was applied to bpf/bpf.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Fri, 11 Oct 2024 00:08:02 +0000 you wrote:
> 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)
>
> [...]
Here is the summary with links:
- [bpf,v2,1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset
https://git.kernel.org/bpf/bpf/c/ad6b5b6ea9b7
- [bpf,v2,2/2] selftests/bpf: assert link info uprobe_multi count & path_size if unset
https://git.kernel.org/bpf/bpf/c/b836cbdf3b81
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-10-11 2:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-09 22:06 [PATCH bpf v1 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset Tyrone Wu
2024-10-09 22:06 ` [PATCH bpf v1 2/2] selftests/bpf: assert link info uprobe_multi count & path_size if unset Tyrone Wu
2024-10-10 22:01 ` Andrii Nakryiko
2024-10-11 0:08 ` [PATCH bpf v2 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset Tyrone Wu
2024-10-11 0:08 ` [PATCH bpf v2 2/2] selftests/bpf: assert link info uprobe_multi count & path_size if unset Tyrone Wu
2024-10-11 2:20 ` [PATCH bpf v2 1/2] bpf: fix unpopulated path_size when uprobe_multi fields unset patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).