BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jim Cromie" <jim.cromie@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v2 2/3] kallsyms: Add dynamic lookup index for batch resolution
Date: Tue, 22 Sep 2026 07:31:32 +0000	[thread overview]
Message-ID: <20260922073133.5AC8D1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260922-ksyms-tune-v2-2-a333ee31eac7@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] kallsyms: use-after-free on dyn_kallsyms_offsets in lookup paths
- [Low] kallsyms: undeclared get_symbol_data() causes build failure
--

commit ab1fc0aa56a3930399c450aad78232a641c6e73f
Author: Jim Cromie <jim.cromie@gmail.com>
kallsyms: Add dynamic lookup index for batch resolution

This commit introduces a dynamically allocated lookup index for kallsyms to
accelerate batch symbol resolution. The index is built on-demand in transient
RAM and freed when the batch concludes, falling back to a linear scan
otherwise.

> diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
> index b9e573e9a10b9..862a6b773ac5e 100644
> --- a/kernel/kallsyms.c
> +++ b/kernel/kallsyms.c

[ ... ]

> +static u32 *kallsyms_build_offsets(void)
> +{
> +	const u8 *name = kallsyms_names;
> +	u32 *offsets;
> +	unsigned int i;
> +
> +	offsets = kvmalloc_array(kallsyms_num_syms, sizeof(u32), GFP_KERNEL);
> +	if (!offsets)
> +		return NULL;
> +
> +	for (i = 0; i < kallsyms_num_syms; i++) {
> +		unsigned int len;
> +		const u8 *data;
> +
> +		offsets[i] = name - kallsyms_names;
> +		data = get_symbol_data(offsets[i], &len);

[Severity: Low]
Does this cause a build failure? I noticed that get_symbol_data() does not
seem to be declared or defined in the codebase at this commit. Even if it is
introduced in a later patch in the series, each commit should compile
independently to preserve git bisectability.

> +		name = data + len;
> +	}
> +
> +	return offsets;
> +}

[ ... ]

> +/*
> + * Find the offset on the compressed table given an index in the
> + * kallsyms array.
> + */
> +static inline unsigned int get_symbol_offset(unsigned long pos)
> +{
> +	u32 *offsets = rcu_dereference_raw(dyn_kallsyms_offsets);
> +
> +	if (offsets)
> +		return offsets[pos];

[Severity: High]
Could this lead to a use-after-free when kallsyms_lookup_batch_end() tears
down the batch?

Because rcu_dereference_raw() is used here, static analysis and lockdep 
cannot verify whether rcu_read_lock() is held. Readers like the 
/proc/kallsyms seq_file iterators (e.g., reset_iter()) or exported APIs 
(like lookup_symbol_name() or kallsyms_lookup_buildid()) can call this 
function in preemptible contexts without RCU protection. 

If a reader is preempted after dereferencing the pointer but before
accessing the array element, and another thread completes 
kallsyms_lookup_batch_end(), synchronize_rcu() will not wait for the 
preempted reader, which will then access the freed array.

> +
> +	return get_symbol_offset_marker(pos);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260922-ksyms-tune-v2-0-a333ee31eac7@gmail.com?part=2

  reply	other threads:[~2026-09-22  7:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  7:19 [PATCH v2 0/3] kallsyms: Accelerate symbol name lookups by ~19x Jim Cromie
2026-09-22  7:19 ` [PATCH v2 1/3] kallsyms: Add test_kallsyms_perf module to benchmark lookup latency Jim Cromie
2026-09-22  7:30   ` sashiko-bot
2026-09-22  7:19 ` [PATCH v2 2/3] kallsyms: Add dynamic lookup index for batch resolution Jim Cromie
2026-09-22  7:31   ` sashiko-bot [this message]
2026-09-22  7:19 ` [PATCH v2 3/3] kallsyms: Match compressed tokens on the fly during binary search Jim Cromie
2026-09-22  9:03   ` David Laight
2026-09-22  8:41 ` [PATCH v2 0/3] kallsyms: Accelerate symbol name lookups by ~19x David Laight

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=20260922073133.5AC8D1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jim.cromie@gmail.com \
    --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