From: Jiri Olsa <olsajiri@gmail.com>
To: tyrone-wu <wudevelops@gmail.com>
Cc: olsajiri@gmail.com, laoar.shao@gmail.com,
andrii.nakryiko@gmail.com, bpf@vger.kernel.org, ast@kernel.org,
daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com,
song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org,
sdf@fomichev.me, haoluo@google.com, mykolal@fb.com,
shuah@kernel.org, kernel-patches-bot@fb.com,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf] bpf: fix unpopulated name_len field in perf_event link info
Date: Wed, 2 Oct 2024 13:37:59 +0200 [thread overview]
Message-ID: <Zv0wl-S13WJnIkb_@krava> (raw)
In-Reply-To: <20240930235920.125417-1-wudevelops@gmail.com>
On Mon, Sep 30, 2024 at 11:59:20PM +0000, tyrone-wu wrote:
> Previously when retrieving `bpf_link_info.perf_event` for
> kprobe/uprobe/tracepoint, the `name_len` field was not populated by the
> kernel, leaving it to reflect the value initially set by the user. This
> behavior was inconsistent with how other input/output string buffer
> fields function (e.g. `raw_tracepoint.tp_name_len`).
>
> This patch fills `name_len` with the actual size of the string name. The
> relevant selftests have also been updated to assert that `name_len`
> contains the correct size rather than 0.
>
> Link: https://lore.kernel.org/bpf/CABVU1kXwQXhqQGe0RTrr7eegtM6SVW_KayZBy16-yb0Snztmtg@mail.gmail.com/
> Fixes: 1b715e1b0ec5 ("bpf: Support ->fill_link_info for perf_event")
> Signed-off-by: tyrone-wu <wudevelops@gmail.com>
> ---
> kernel/bpf/syscall.c | 25 +++++++++++++------
> .../selftests/bpf/prog_tests/fill_link_info.c | 6 ++---
> 2 files changed, 20 insertions(+), 11 deletions(-)
>
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index a8f1808a1ca5..90b6add4d0c9 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -3565,7 +3565,7 @@ static void bpf_perf_link_dealloc(struct bpf_link *link)
> }
>
> static int bpf_perf_link_fill_common(const struct perf_event *event,
> - char __user *uname, u32 ulen,
> + char __user *uname, u32 *ulen,
> u64 *probe_offset, u64 *probe_addr,
> u32 *fd_type, unsigned long *missed)
> {
> @@ -3574,18 +3574,20 @@ static int bpf_perf_link_fill_common(const struct perf_event *event,
> size_t len;
> int err;
>
> - if (!ulen ^ !uname)
> + if (!(*ulen) ^ !uname)
> return -EINVAL;
>
> err = bpf_get_perf_event_info(event, &prog_id, fd_type, &buf,
> probe_offset, probe_addr, missed);
> if (err)
> return err;
> +
> + len = strlen(buf);
> + *ulen = len + 1;
I think before you overwrite *ulen with actual name lenth you should
store its value and use it in bpf_copy_to_user, otherwise we could
overwrite user space memory that we are not supposed to
jirka
> if (!uname)
> return 0;
> if (buf) {
> - len = strlen(buf);
> - err = bpf_copy_to_user(uname, buf, ulen, len);
> + err = bpf_copy_to_user(uname, buf, *ulen, len);
> if (err)
> return err;
> } else {
> @@ -3609,7 +3611,7 @@ static int bpf_perf_link_fill_kprobe(const struct perf_event *event,
>
> uname = u64_to_user_ptr(info->perf_event.kprobe.func_name);
> ulen = info->perf_event.kprobe.name_len;
> - err = bpf_perf_link_fill_common(event, uname, ulen, &offset, &addr,
> + err = bpf_perf_link_fill_common(event, uname, &ulen, &offset, &addr,
> &type, &missed);
> if (err)
> return err;
SNIP
next prev parent reply other threads:[~2024-10-02 11:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <ZvqLanKfaO9dLlf4@krava>
2024-09-30 23:59 ` [PATCH bpf] bpf: fix unpopulated name_len field in perf_event link info tyrone-wu
2024-10-02 11:37 ` Jiri Olsa [this message]
2024-10-02 21:38 ` [PATCH bpf v2] " tyrone-wu
2024-10-03 19:10 ` Jiri Olsa
2024-10-03 20:23 ` [PATCH bpf v3] " tyrone-wu
2024-10-04 11:19 ` Jiri Olsa
2024-10-04 15:40 ` [PATCH bpf v4 1/2] " tyrone-wu
2024-10-04 15:40 ` [PATCH bpf v4 2/2] selftests/bpf: fix perf_event link info name_len assertion tyrone-wu
2024-10-06 6:00 ` [PATCH bpf v4 1/2] bpf: fix unpopulated name_len field in perf_event link info Yafang Shao
2024-10-06 19:51 ` [PATCH bpf v5 " tyrone-wu
2024-10-06 19:51 ` [PATCH bpf v5 2/2] selftests/bpf: fix perf_event link info name_len assertion tyrone-wu
2024-10-07 2:09 ` Yafang Shao
2024-10-07 2:09 ` [PATCH bpf v5 1/2] bpf: fix unpopulated name_len field in perf_event link info Yafang Shao
2024-10-07 8:07 ` Jiri Olsa
2024-10-07 18:29 ` [PATCH bpf v6 " Tyrone Wu
2024-10-07 18:29 ` [PATCH bpf v6 2/2] selftests/bpf: fix perf_event link info name_len assertion Tyrone Wu
2024-10-08 4:04 ` [PATCH bpf v6 1/2] bpf: fix unpopulated name_len field in perf_event link info Andrii Nakryiko
2024-10-08 16:43 ` [PATCH bpf v7 " Tyrone Wu
2024-10-08 16:43 ` [PATCH bpf v7 2/2] selftests/bpf: fix perf_event link info name_len assertion Tyrone Wu
2024-10-10 1:20 ` [PATCH bpf v7 1/2] bpf: fix unpopulated name_len field in perf_event link info patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zv0wl-S13WJnIkb_@krava \
--to=olsajiri@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kernel-patches-bot@fb.com \
--cc=kpsingh@kernel.org \
--cc=laoar.shao@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=wudevelops@gmail.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox