From: Jiri Olsa <olsajiri@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCHv4 bpf-next 3/3] bpftool: Add tracing_multi link info output
Date: Wed, 1 Jul 2026 13:31:08 +0200 [thread overview]
Message-ID: <akT6fHCSdJGFXmcK@krava> (raw)
In-Reply-To: <20260629213330.0ACD41F000E9@smtp.kernel.org>
On Mon, Jun 29, 2026 at 09:33:29PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> - [Medium] bpftool uses a non-existent `tracing_multi` union member in `struct bpf_link_info`.
> - [Medium] The kernel-side `bpf_tracing_multi_link_lops` is missing the `.fill_link_info` callback.
> - [Low] Memory allocated for `ids`, `addrs`, and `cookies` is leaked on the error path of the `bpf_link_get_info_by_fd` syscall.
> --
>
> commit 3c4bad76286f49adf87a7b01dc7042ac6368c5ce
> Author: Jiri Olsa <jolsa@kernel.org>
>
> bpftool: Add tracing_multi link info output
>
> Adding bpftool support to show tracing_multi link details. The new output will
> display attach types, counts, BTF IDs, addresses, cookies, and functions.
>
> > diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
> > index bdcd717b0348f..088d1d206065f 100644
> > --- a/tools/bpf/bpftool/link.c
> > +++ b/tools/bpf/bpftool/link.c
>
> [ ... ]
>
> > @@ -403,6 +422,52 @@ show_uprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
> > jsonw_end_array(json_wtr);
> > }
> >
> > +static void
> > +show_tracing_multi_json(struct bpf_link_info *info, json_writer_t *wtr)
> > +{
> > + bool is_ibt_enabled = is_x86_ibt_enabled(), show_symbol;
> > + __u64 *addrs, *cookies;
> > + __u32 i, *ids;
> > +
> > + if (!dd.sym_count)
> > + kernel_syms_load(&dd);
> > + show_symbol = !!dd.sym_count;
> > +
> > + show_link_attach_type_json(info->tracing_multi.attach_type, wtr);
>
> [Severity: Medium]
> Does `struct bpf_link_info` in `include/uapi/linux/bpf.h` include a
> `tracing_multi` member?
>
> It looks like the `tracing_multi` struct is missing from `struct bpf_link_info`
> in the UAPI, which causes a compile error here when trying to access
> `info->tracing_multi.attach_type`.
>
> Additionally, the kernel-side implementation in `kernel/trace/bpf_trace.c`
> appears to be missing the `.fill_link_info` callback in
> `bpf_tracing_multi_link_lops`.
>
> Without it, will the kernel silently return unpopulated link details when
> queried via `bpf_obj_get_info_by_fd()`?
>
> [ ... ]
>
> > @@ -1114,6 +1226,26 @@ static int do_show_link(int fd)
> > goto again;
> > }
> > }
> > + if (info.type == BPF_LINK_TYPE_TRACING_MULTI && !info.tracing_multi.ids) {
> > + count = info.tracing_multi.count;
> > + if (count) {
> > + ids = calloc(count, sizeof(__u32));
> > + addrs = calloc(count, sizeof(__u64));
> > + cookies = calloc(count, sizeof(__u64));
> > + if (!ids || !addrs || !cookies) {
> > + p_err("mem alloc failed");
> > + close(fd);
> > + free(cookies);
> > + free(addrs);
> > + free(ids);
> > + return -ENOMEM;
> > + }
> > + info.tracing_multi.ids = ptr_to_u64(ids);
> > + info.tracing_multi.addrs = ptr_to_u64(addrs);
> > + info.tracing_multi.cookies = ptr_to_u64(cookies);
> > + goto again;
>
> [Severity: Low]
> Do we leak the memory allocated for `ids`, `addrs`, and `cookies` if the
> subsequent `bpf_link_get_info_by_fd()` syscall fails?
>
> When jumping to `again:`, if `bpf_link_get_info_by_fd()` returns an error, the
> function returns early without freeing these arrays:
>
> tools/bpf/bpftool/link.c:do_show_link() {
> ...
> again:
> err = bpf_link_get_info_by_fd(fd, &info, &len);
> if (err) {
> p_err("can't get link info: %s",
> strerror(errno));
> close(fd);
> return err;
> }
> ...
> }
>
> Should the error path free these arrays before returning?
right, that's pre-existing issue, I think we could do something like
below.. will send a separate fix
jirka
---
diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index 088d1d206065..3f5b3b12a404 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -1156,8 +1156,7 @@ static int do_show_link(int fd)
if (err) {
p_err("can't get link info: %s",
strerror(errno));
- close(fd);
- return err;
+ goto out;
}
if (info.type == BPF_LINK_TYPE_RAW_TRACEPOINT &&
!info.raw_tracepoint.tp_name) {
@@ -1281,13 +1280,14 @@ static int do_show_link(int fd)
else
show_link_close_plain(fd, &info);
+out:
free(ref_ctr_offsets);
free(cookies);
free(offsets);
free(addrs);
free(ids);
close(fd);
- return 0;
+ return err;
}
static int do_show(int argc, char **argv)
next prev parent reply other threads:[~2026-07-01 11:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 21:22 [PATCHv4 bpf-next 0/3] bpf: tracing_multi link info support Jiri Olsa
2026-06-29 21:22 ` [PATCHv4 bpf-next 1/3] bpf: Add " Jiri Olsa
2026-06-29 21:22 ` [PATCHv4 bpf-next 2/3] selftests/bpf: Add tracing_multi link info tests Jiri Olsa
2026-06-29 21:34 ` sashiko-bot
2026-07-01 11:31 ` Jiri Olsa
2026-06-29 21:22 ` [PATCHv4 bpf-next 3/3] bpftool: Add tracing_multi link info output Jiri Olsa
2026-06-29 21:33 ` sashiko-bot
2026-07-01 11:31 ` Jiri Olsa [this message]
2026-07-01 19:43 ` Andrii Nakryiko
2026-07-01 19:50 ` [PATCHv4 bpf-next 0/3] bpf: tracing_multi link info support 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=akT6fHCSdJGFXmcK@krava \
--to=olsajiri@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.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