From: sashiko-bot@kernel.org
To: "Jiri Olsa" <jolsa@kernel.org>
Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH RFC bpf-next 21/31] bpftool: Display inlined functions for kprobe multi link
Date: Wed, 02 Dec 2026 13:00:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-245833@kernel.org> (raw)
In-Reply-To: <20261202123035.10335-22-jolsa@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] bpftool: broken binary search in find_kernel_sym_by_range()
due to 32-bit sort
- [Low] bpftool: memory leak in do_show_link() when second link info
query fails
--
commit 40ced4c64011e2e50d8f3a0de0d6ac7287df545e
Author: Jiri Olsa <jolsa@kernel.org>
bpftool: Display inlined functions for kprobe multi link
This commit updates bpftool to display inline flags and attached inlined
function instances for kprobe_multi links in both plain and JSON output.
> diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
> index 5cffa2d283b47..19daac789a4ca 100644
> --- a/tools/bpf/bpftool/link.c
> +++ b/tools/bpf/bpftool/link.c
[ ... ]
> @@ -322,33 +361,156 @@ symbol_matches_target(__u64 sym_addr, __u64 target_addr, bool is_ibt_enabled)
> return false;
> }
>
> +/* Inlined instances are placed inside functions, find the one covering @addr. */
> +static struct kernel_sym *find_kernel_sym_by_range(__u64 addr)
> +{
> + __u32 lo = 0, hi = dd.sym_count, mid;
> +
> + if (!addr)
> + return NULL;
> +
> + while (lo < hi) {
> + mid = lo + (hi - lo) / 2;
> + if (dd.sym_mapping[mid].address <= addr)
> + lo = mid + 1;
> + else
> + hi = mid;
> + }
> + return lo ? &dd.sym_mapping[lo - 1] : NULL;
> +}
[Severity: Medium]
Can find_kernel_sym_by_range() return a per-cpu symbol instead of the
enclosing function because dd.sym_mapping is not sorted in 64-bit unsigned
order?
kernel_syms_load() sorts dd.sym_mapping with kernel_syms_cmp(), which
truncates the 64-bit unsigned long address difference to a 32-bit signed
int:
tools/bpf/bpftool/xlated_dumper.c:kernel_syms_cmp() {
return ((struct kernel_sym *)sym_a)->address -
((struct kernel_sym *)sym_b)->address;
}
On 64-bit SMP systems such as x86_64, per-cpu symbols in /proc/kallsyms
have small positive offsets (e.g. 0x1000), while kernel and module text
symbols sit at 0xffffffff80000000 and above, where bit 31 is set. Because
truncating (per_cpu_addr - text_addr) to int yields a positive value,
qsort() places the per-cpu symbols at the tail of dd.sym_mapping after
text symbols. When find_kernel_sym_by_range() binary-searches
dd.sym_mapping with 64-bit unsigned comparisons for an inlined address in
a module or in the upper half of the table, mid probes into those trailing
per-cpu entries, sees dd.sym_mapping[mid].address <= addr, and advances lo
to the end of the array, reporting a bogus caller, offset, module, and
inline BTF lookup.
[ ... ]
> @@ -1172,24 +1414,36 @@ static int do_show_link(int fd)
> goto again;
> }
> if (info.type == BPF_LINK_TYPE_KPROBE_MULTI &&
> - !info.kprobe_multi.addrs) {
> + !info.kprobe_multi.addrs && !info.kprobe_multi.inline_addrs) {
> + __u32 inline_count = info.kprobe_multi.inline_count;
> +
> count = info.kprobe_multi.count;
> if (count) {
> addrs = calloc(count, sizeof(__u64));
> - if (!addrs) {
> - p_err("mem alloc failed");
> - close(fd);
> - return -ENOMEM;
> - }
> - info.kprobe_multi.addrs = ptr_to_u64(addrs);
> cookies = calloc(count, sizeof(__u64));
> - if (!cookies) {
> - p_err("mem alloc failed");
> - free(addrs);
> - close(fd);
> - return -ENOMEM;
> - }
> + }
> + if (inline_count) {
> + inline_addrs = calloc(inline_count, sizeof(__u64));
> + inline_cookies = calloc(inline_count, sizeof(__u64));
> + inline_ids = calloc(inline_count, sizeof(__u32));
> + }
> + if ((count && (!addrs || !cookies)) ||
> + (inline_count && (!inline_addrs || !inline_cookies || !inline_ids))) {
> + p_err("mem alloc failed");
> + free(inline_ids);
> + free(inline_cookies);
> + free(inline_addrs);
> + free(cookies);
> + free(addrs);
> + close(fd);
> + return -ENOMEM;
> + }
> + if (count || inline_count) {
> + info.kprobe_multi.addrs = ptr_to_u64(addrs);
> info.kprobe_multi.cookies = ptr_to_u64(cookies);
> + info.kprobe_multi.inline_addrs = ptr_to_u64(inline_addrs);
> + info.kprobe_multi.inline_cookies = ptr_to_u64(inline_cookies);
> + info.kprobe_multi.inline_ids = ptr_to_u64(inline_ids);
> goto again;
> }
> }
[Severity: Low]
If the second bpf_link_get_info_by_fd() call after "goto again" fails,
does do_show_link() return early without freeing inline_addrs,
inline_cookies, inline_ids, addrs, and cookies?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202123035.10335-1-jolsa@kernel.org?part=21
next prev parent reply other threads:[~2026-12-02 13:00 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 01/31] x86/ptrace: Add regs_get_dwarf_register function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 02/31] kprobes: Make the kprobe hash table size configurable Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 03/31] kprobes: Add enable_kprobes to enable multiple kprobes at once Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 04/31] module: Add module_sect_addr function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 05/31] bpf: Add bpf_get_btf_vmlinux_inline function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 06/31] bpf: Use goto labels for error path in bpf_kprobe_multi_link_attach Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 07/31] bpf: Add support to attach inlined functions with kprobe multi link Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 08/31] bpf: Add cookie support for kprobe multi inlined functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 09/31] bpf: Add link info " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 10/31] bpf: Add fdinfo " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 11/31] bpf: Add btf_for_each_module_inline function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 12/31] bpf: Change get_modules_for_addrs to use struct modules_array Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 13/31] tbpf: Add support to attach inlined functions in modules with kprobe multi link Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 14/31] bpf: Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 15/31] bpf: Add get_func_arg[_cnt] support for kprobe multi functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 16/31] bpf: Add get_func_arg[_cnt] support for kprobe multi inlined functions Jiri Olsa
2026-12-02 12:55 ` sashiko-bot
2026-12-02 12:30 ` [PATCH RFC bpf-next 17/31] bpf: Add log messages for kprobe multi inline attach Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 18/31] bpf: Add inlined functions for kprobe multi inline tests Jiri Olsa
2026-12-02 12:51 ` sashiko-bot
2026-12-02 12:30 ` [PATCH RFC bpf-next 19/31] libbpf: Add inline options to bpf_kprobe_multi_opts Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 20/31] libbpf: Print kernel log for failed kprobe multi attach Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 21/31] bpftool: Display inlined functions for kprobe multi link Jiri Olsa
2026-12-02 13:00 ` sashiko-bot [this message]
2026-12-02 12:30 ` [PATCH RFC bpf-next 22/31] selftests/bpf: Add inlined functions to bpf_testmod Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 23/31] selftests/bpf: Add kprobe multi inline attach test Jiri Olsa
2026-12-02 12:50 ` sashiko-bot
2026-12-02 12:30 ` [PATCH RFC bpf-next 24/31] selftests/bpf: Add kprobe multi inline mixed test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 25/31] selftests/bpf: Add kprobe multi inline skip test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 26/31] selftests/bpf: Add kprobe multi inline fails test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 27/31] selftests/bpf: Add kprobe multi inline module test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 28/31] selftests/bpf: Add kprobe multi inline strict test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 29/31] selftests/bpf: Add kprobe multi inline args test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 30/31] selftests/bpf: Add kprobe multi inline bench attach test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 31/31] selftests/bpf: Add kprobe multi inline link info test Jiri Olsa
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=sashiko-outbox-245833@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jolsa@kernel.org \
--cc=linux-trace-kernel@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 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.