All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiri Olsa" <jolsa@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCHv4 bpf-next 3/3] bpftool: Add tracing_multi link info output
Date: Mon, 29 Jun 2026 21:33:29 +0000	[thread overview]
Message-ID: <20260629213330.0ACD41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260629212208.895962-4-jolsa@kernel.org>

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?

> +		}
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260629212208.895962-4-jolsa@kernel.org?part=1

  reply	other threads:[~2026-06-29 21:33 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 [this message]
2026-07-01 11:31     ` Jiri Olsa
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=20260629213330.0ACD41F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jolsa@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.