Linux Modules
 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 v8 1/4] kallsyms: embed source file:line info in kernel stack traces
Date: Sat, 01 Aug 2026 14:45:53 +0000	[thread overview]
Message-ID: <20260801144554.3755B1F00ACA@smtp.kernel.org> (raw)
In-Reply-To: <20260801143219.3975824-2-sashal@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Use of `snprintf` violates `sprint_symbol` API contract and causes trace buffer inflation.
--

--- Patch [1]: [PATCH v8 1/4] kallsyms: embed source file:line info in kernel stack traces ---
commit 8a14a0edefef69e5b032ac47662777d287f71164
Author: Sasha Levin <sashal@kernel.org>

kallsyms: embed source file:line info in kernel stack traces

Add CONFIG_KALLSYMS_LINEINFO, which embeds a compact address-to-line
lookup table in the kernel image so stack traces directly print source
file and line number information.

> diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
> --- a/kernel/kallsyms.c
> +++ b/kernel/kallsyms.c

[ ... ]

> @@ -497,6 +567,23 @@ static int __sprint_symbol(char *buffer, unsigned long address,
>  		len += sprintf(buffer + len, "]");
>  	}
>  
> +	/*
> +	 * Append "(file:line)" only for stack-backtrace consumers.  Plain
> +	 * sprint_symbol() backs %ps, and many existing format strings tack
> +	 * literal "()" after %ps to indicate a function call ("foo()
> +	 * replaced with bar()"); appending lineinfo there would produce a
> +	 * confusing "foo (file:line)()".
> +	 */
> +	if (add_lineinfo && IS_ENABLED(CONFIG_KALLSYMS_LINEINFO) && !modname) {
> +		const char *li_file;
> +		unsigned int li_line;
> +
> +		if (kallsyms_lookup_lineinfo(address, sym_start,
> +					     &li_file, &li_line))
> +			len += snprintf(buffer + len, KSYM_SYMBOL_LEN - len,
> +					" (%s:%u)", li_file, li_line);

[Severity: Medium]
Is it safe to use snprintf() here instead of scnprintf()?

The API contract for sprint_symbol() specifies it returns the number of bytes
stored. If the source file path is very long and truncation occurs, snprintf()
will return the un-truncated length.

This can cause caller logic errors. For example, if a kprobe triggers on a
symbol with a long source path, fetch_store_symstrlen() will allocate buffer
space based on this inflated return value. When fetch_store_symstring() writes
the truncated string, the tail of the allocated ring buffer remains
uninitialized. Future callers attempting pointer advancement via
buf += sprint_symbol(...) could also be exposed to out-of-bounds writes.

Could this be changed to use scnprintf() to ensure it returns the actual
number of bytes written?

> +	}
> +
>  	return len;
>  }

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

  reply	other threads:[~2026-08-01 14:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-01 14:32 [PATCH v8 0/4] kallsyms: embed source file:line info in kernel stack traces Sasha Levin
2026-08-01 14:32 ` [PATCH v8 1/4] " Sasha Levin
2026-08-01 14:45   ` sashiko-bot [this message]
2026-08-01 14:32 ` [PATCH v8 2/4] kallsyms: extend lineinfo to loadable modules Sasha Levin
2026-08-01 14:42   ` sashiko-bot
2026-08-01 14:32 ` [PATCH v8 3/4] kallsyms: delta-compress lineinfo tables for ~2.7x size reduction Sasha Levin
2026-08-01 14:39   ` sashiko-bot
2026-08-01 14:32 ` [PATCH v8 4/4] kallsyms: add KUnit tests for lineinfo feature Sasha Levin
2026-08-01 14:45   ` sashiko-bot

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=20260801144554.3755B1F00ACA@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox