Skip to content

telemetry: performance_monitor: cap extended perf data reply - #11477

Open
Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:telemetry-ext-perf-bound
Open

Shrusti-pk wants to merge 1 commit into
thesofproject:mainfrom
Shrusti-pk:telemetry-ext-perf-bound

Conversation

@Shrusti-pk

Copy link
Copy Markdown
Contributor

get_extended_performance_data() fills the IPC4_EXTENDED_GLOBAL_PERF_DATA reply without knowing the size of the buffer it writes to:

  • the buffer is ipc->comp_data (4096 bytes) and every enabled core and occupied perf slot adds a 48-byte item, so 85 fit; a slot is taken for each component the host creates, kept after the component is freed while measurements are started, and there are 88 slots by default (170 without SOF_TELEMETRY_MODULE_RESOURCES)
  • trigger: 85 components on a single core, then a BaseFW LARGE_CONFIG_GET for IPC4_EXTENDED_GLOBAL_PERF_DATA. The 86th item lands past comp_data, up to 372 bytes past with 5 cores, about 4 KiB with 170 slots. The MAILBOX_DSPBOX_SIZE check in ipc4_get_large_config_module_instance() only runs after the write
  • reproduced by running the verbatim function under ASan against a 4096-byte heap block: heap-buffer-overflow WRITE of size 8 for 85 components. With the patch the report stops at 85 items, and reports that fit are byte-identical

The size comes from base_fw because only the caller knows the buffer. The global and I/O reports use 16-byte items and fit. I could not build the Zephyr image locally, so the change is compile- and run-tested only through that standalone harness.

get_extended_performance_data() writes one 48-byte ext_perf_data_item
for every enabled core and every occupied performance slot, and never
looks at the size of the buffer it writes to. The IPC4 BaseFW
LARGE_CONFIG_GET for IPC4_EXTENDED_GLOBAL_PERF_DATA hands it
ipc->comp_data, a SOF_IPC_MSG_MAX_SIZE (4096 byte) heap block, which
holds 85 items after the count word.

A slot is taken for every component the host creates, and while
measurements are started it stays taken after the component is freed.
CONFIG_SOF_TELEMETRY_MAX_COMP_ENTRIES defaults to 88 (170 without
SOF_TELEMETRY_MODULE_RESOURCES), so 85 components on one core are
enough for the report to run past the end of comp_data: up to 372
bytes with 5 cores and 88 slots, about 4 KiB with 170 slots. The
reply size check in ipc4_get_large_config_module_instance() runs only
after the getter has written.

Pass the buffer size to get_extended_performance_data() and report
only the items that fit, with a warning. Reports that fit are
unchanged. The 16-byte global and I/O perf reports cannot exceed the
buffer with the configured slot counts.
@sofci

sofci commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

reply test this please to run this test once

@lgirdwood
lgirdwood requested a balanced review from Copilot November 17, 2026 16:06
@lgirdwood

Copy link
Copy Markdown
Member

test this please

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.

🟡 Changes recommended

Vendor-config GETs can still overrun the buffer, and capped reports silently omit records without a way to retrieve them.

2 open issues
What changed in this PR

Adds size-aware generation of IPC4 extended performance telemetry replies to prevent oversized reports from overflowing the reply buffer.

Changes:

  • Validate destination capacity and cap the number of core and component records written.
  • Pass the IPC message-size limit from BaseFW and update the API declaration, disabled stub, and documentation.
File Description
src/​kernel/​debug/​telemetry/​performance_monitor.c Adds capacity validation and limits emitted performance records.
src/​kernel/​audio/​base_fw.c Supplies the IPC message-size limit to the telemetry function.
src/​include/​sof/​debug/​telemetry/​performance_monitor.h Updates the function signature, stub, and buffer-size documentation.

Review effort: Balanced

struct extended_global_perf_data *perf_data = (struct extended_global_perf_data *)data;

ret = get_extended_performance_data(perf_data);
ret = get_extended_performance_data(perf_data, SOF_IPC_MSG_MAX_SIZE);
Comment on lines +447 to +450
if (slots_count > max_slots) {
tr_warn(&ipc_tr, "%zu perf items do not fit, reporting %zu", slots_count,
max_slots);
slots_count = max_slots;
@lgirdwood

Copy link
Copy Markdown
Member

@Shrusti-pk can you respond/respin to teh review comments. Thanks !

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.

4 participants