All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Levin" <sashal@kernel.org>
Cc: linux-modules@vger.kernel.org
Subject: Re: [PATCH v9 2/4] kallsyms: extend lineinfo to loadable modules
Date: Thu, 17 Sep 2026 13:46:30 +0000	[thread overview]
Message-ID: <20260917134630.8D25B1F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260917133727.428546-3-sashal@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] scripts: gen_lineinfo: integer overflow in relocation bounds check allows OOB access
--

commit 39f395f93fb90faf7a6d102ff862dc9fb6013c84
Author: Sasha Levin <sashal@kernel.org>

kallsyms: extend lineinfo to loadable modules

This commit adds CONFIG_KALLSYMS_LINEINFO_MODULES to extend the lineinfo
feature to loadable kernel modules. It post-processes each .ko file at
build time to embed binary tables containing section-relative offsets,
file IDs, line numbers, and filenames.

> diff --git a/scripts/gen_lineinfo.c b/scripts/gen_lineinfo.c
> --- a/scripts/gen_lineinfo.c
> +++ b/scripts/gen_lineinfo.c
[ ... ]
> +static void apply_one_debug_reloc(Elf_Data *dl_data, Elf_Data *sym_data,
> +				  bool target_le, const GElf_Ehdr *ehdr,
> +				  unsigned int abs32_type,
> +				  unsigned int abs64_type, GElf_Xword r_info,
> +				  GElf_Addr r_offset, GElf_Sxword addend,
> +				  bool has_addend, bool bias)
> +{
[ ... ]
> +	if (arith_width) {
> +		uint64_t cur;
> +
> +		if (r_offset + arith_width > dl_data->d_size)
> +			return;

[Severity: Medium]
Could an integer overflow occur here? If a malformed ELF relocation
has an r_offset near UINT64_MAX, r_offset + arith_width could wrap around
to a small value and incorrectly pass this bounds check.

Since the tool subsequently does pointer arithmetic using r_offset:
(unsigned char *)dl_data->d_buf + r_offset

Would this allow an out-of-bounds read and write on the section buffer?

> +		/*
> +		 * A delta, not an address: the section bias would appear in
> +		 * the ADD and cancel in the matching SUB, so leave it out.
> +		 */
> +		cur = elf_read_uint((unsigned char *)dl_data->d_buf + r_offset,
> +				    arith_width, target_le);
> +		value = (uint64_t)(sym.st_value + addend);
> +		cur = is_sub ? cur - value : cur + value;
> +		elf_write_uint((unsigned char *)dl_data->d_buf + r_offset,
> +			       cur, arith_width, target_le);
> +		return;
> +	}
> +
> +	width = is_abs64 ? 8 : 4;
> +
> +	if (r_offset + width > dl_data->d_size)
> +		return;

[Severity: Medium]
Similarly, can r_offset + width overflow here? A crafted .ko or .o file
might bypass this validation due to wrapping, leading to the same
out-of-bounds access on the dl_data->d_buf buffer further down.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260917133727.428546-1-sashal@kernel.org?part=2

  reply	other threads:[~2026-09-17 13:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 13:37 [PATCH v9 0/4] kallsyms: embed source file:line info in kernel stack traces Sasha Levin
2026-09-17 13:37 ` [PATCH v9 1/4] " Sasha Levin
2026-09-17 13:48   ` sashiko-bot
2026-09-17 13:37 ` [PATCH v9 2/4] kallsyms: extend lineinfo to loadable modules Sasha Levin
2026-09-17 13:46   ` sashiko-bot [this message]
2026-09-17 13:37 ` [PATCH v9 3/4] kallsyms: delta-compress lineinfo tables for ~2.7x size reduction Sasha Levin
2026-09-17 13:37 ` [PATCH v9 4/4] kallsyms: add KUnit tests for lineinfo feature Sasha Levin

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=20260917134630.8D25B1F00899@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=sashal@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.