Skip to content

logger: convert: refuse ldc format text that does not match its params - #11331

Open
Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:logger-format-spec-check
Open

Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:logger-format-spec-check

Conversation

@Shrusti-pk

@Shrusti-pk Shrusti-pk commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

sof-logger hands the log text from the .ldc file to fprintf() as the format string, and process_params() only logs when that text does not fit the params:

  • more conversion specifiers than params_num: "Too many % conversion specifiers" is printed, then fprintf() runs with the full format anyway and each extra %s/%x reads a variadic argument that was never passed
  • anything besides bare %s, %%, %pU and %pQ is forwarded as is, so "%5s" dereferences the 32-bit trace word as a char pointer (ASan SEGV on 0x41414141 in print_entry_params), and '*' and %n get through as well
  • a crafted .ldc entry name %5s with params_num = 1, or val %u then %s with params_num = 1, run with sof-logger -l t.ldc -i t.trace -n reproduces both under ASan

process_params() now returns -EINVAL in those cases and the entry text is printed as a plain string. "%%" is skipped before the param count check. Output for %d %u %x %08x %zu %lx %llu %f %pU %pQ %s %% is unchanged.

@sofci

sofci commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

reply test this please to run this test once

@intel-sofci

intel-sofci commented Oct 22, 2026 •

Copy link
Copy Markdown

PR 11331: test results

Run date: 2026-10-23 09:10 UTC

Tested commit: e301d06078a22abbf3e5a9eadb5149b1bbf73772

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

@lgirdwood
lgirdwood requested a balanced review from Copilot October 22, 2026 12:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Updates sof-logger’s minimal printf-like formatting to reject unsafe/mismatched .ldc format strings (preventing out-of-bounds variadic reads and dangerous specifiers), and fall back to printing the entry text safely when validation fails.

Changes:

  • Change process_params() to return a status code and reject invalid/unsafe format strings with -EINVAL.
  • Skip "%%" before parameter-count validation and refuse unsupported/dangerous conversion patterns (e.g., *, %n, %s with modifiers).
  • On validation failure, print the entry text without using it as a printf() format string.
File Description
tools/​logger/​convert.c Adds format-string validation and error propagation to prevent unsafe fprintf() usage with .ldc-provided format text.

Review effort: Lite

Comment thread tools/logger/convert.c
Comment thread tools/logger/convert.c
Comment thread tools/logger/convert.c Outdated
print_entry_params() hands the log text from the .ldc dictionary to
fprintf() as the format string, with params_num trace words as the
arguments. process_params() checks the text but only logs on a
mismatch: with more conversion specifiers than params_num it prints
"Too many % conversion specifiers" and fprintf() still runs with the
full format, so every extra %s or %x reads a variadic argument that
was never passed.

The generic branch also forwards any specifier other than bare %s,
%%, %pU and %pQ unchanged, so "%5s" or "%ls" dereferences the raw
32-bit trace word as a string pointer, a '*' width or precision
consumes an extra argument and %n writes through a trace value.

Return -EINVAL from process_params() for too many specifiers, a
trailing '%', and '*', 'n' or modified 's' conversions, and print the
entry text as a plain string in that case. Skip "%%" before the
parameter count check since it does not consume a parameter. Output
for valid formats is unchanged.

Signed-off-by: Shrushti P K <shrusthi@labs.digiscrypt.com>
@Shrusti-pk
Shrusti-pk force-pushed the logger-format-spec-check branch from 2c7cf8b to e301d06 Compare October 23, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants