From a1fbcd713a19f18cc9539935f6639e4f9e4205a7 Mon Sep 17 00:00:00 2001 From: Shrushti P K Date: Mon, 23 Nov 2026 12:22:13 +0530 Subject: [PATCH 1/2] ipc4: handler-user: leave room for the TLV header in vendor config get ipc4_get_vendor_config_module_instance() checks that produced_data plus the host max_length fits in MAILBOX_DSPBOX_SIZE, but the sof_tlv header is written at produced_data and the getter's output starts after it. A getter that honours max_length can therefore end 8 bytes past the DSPBOX, and the header write itself goes past it when produced_data is within 8 bytes of the end. For the first block of a multi-block get max_length is passed on unbounded while the output also starts after the header. Count the header in the multi-TLV bound and clamp the first block max_length to what is left after the header, so the in/out size a getter sees is the room it really has. Signed-off-by: Shrushti P K --- src/ipc/ipc4/handler-user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ipc/ipc4/handler-user.c b/src/ipc/ipc4/handler-user.c index 232e81800201..3e409149f3f7 100644 --- a/src/ipc/ipc4/handler-user.c +++ b/src/ipc/ipc4/handler-user.c @@ -723,7 +723,11 @@ __cold int ipc4_get_vendor_config_module_instance(struct comp_dev *dev, uint32_t data_off_size_local; struct sof_tlv *output_tlv = (struct sof_tlv *)(data_out + produced_data); - if (produced_data + input_tl[i].max_length > MAILBOX_DSPBOX_SIZE) { + /* the TLV header is written in front of the value, so it + * must fit in the DSPBOX together with max_length + */ + if (produced_data + sizeof(*output_tlv) + input_tl[i].max_length > + MAILBOX_DSPBOX_SIZE) { tr_err(&ipc_tr, "error: response payload bigger than DSPBOX size"); return IPC4_FAILURE; } @@ -758,7 +762,9 @@ __cold int ipc4_get_vendor_config_module_instance(struct comp_dev *dev, struct sof_tlv *tl_header; if (init_block) { - *data_off_size = input_tl->max_length; + /* the first block carries the TL header in front of the value */ + *data_off_size = MIN(input_tl->max_length, + MAILBOX_DSPBOX_SIZE - sizeof(*tl_header)); output_buffer = data_out + sizeof(*tl_header); } else { output_buffer = data_out; From 91e7dffb951f6e16fcfa414f346515ded77c1e3d Mon Sep 17 00:00:00 2001 From: Shrushti P K Date: Mon, 23 Nov 2026 12:22:13 +0530 Subject: [PATCH 2/2] telemetry: performance_monitor: bound extended perf data reply 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. Through a VENDOR_CONFIG_PARAM get the same getter is reached with data pointing after earlier TLV replies inside comp_data, so the whole buffer size is not a safe bound there. Pass the buffer size to get_extended_performance_data() and refuse the request with -ENOBUFS, reported as IPC4_OUT_OF_MEMORY, when the items do not all fit, instead of returning a report the host cannot tell apart from a complete one. The size is the in/out data_off_size, the host max reply length that the vendor config path narrows to the room left after its TLV header, capped at SOF_IPC_MSG_MAX_SIZE. Reports that fit are unchanged. The 16-byte global and I/O perf reports cannot exceed the buffer with the configured slot counts. Signed-off-by: Shrushti P K --- .../sof/debug/telemetry/performance_monitor.h | 10 +++++++--- src/kernel/audio/base_fw.c | 11 ++++++++++- .../debug/telemetry/performance_monitor.c | 17 ++++++++++++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/include/sof/debug/telemetry/performance_monitor.h b/src/include/sof/debug/telemetry/performance_monitor.h index fe081c8bd4ef..4fab81d18642 100644 --- a/src/include/sof/debug/telemetry/performance_monitor.h +++ b/src/include/sof/debug/telemetry/performance_monitor.h @@ -121,9 +121,12 @@ int get_performance_data(struct global_perf_data * const global_perf_data); * \brief Retrieve extended global performance telemetry data with per-core breakdown. * \ingroup telemetry_perf_api * @param[out] ext_global_perf_data Destination structure to populate. - * @return 0 on success, or negative error code on failure. + * @param[in] size Size of the destination buffer in bytes. + * @return 0 on success, -ENOBUFS when the report does not fit in size bytes, or another + * negative error code on failure. */ -int get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data); +int get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data, + uint32_t size); /** * \brief Reset all performance measurement counters across all components. @@ -176,7 +179,8 @@ static inline int get_performance_data(struct global_perf_data * const global_pe } static inline -int get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data) +int get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data, + uint32_t size) { return 0; } diff --git a/src/kernel/audio/base_fw.c b/src/kernel/audio/base_fw.c index 880306a4a03b..d5a40f6a7bb6 100644 --- a/src/kernel/audio/base_fw.c +++ b/src/kernel/audio/base_fw.c @@ -3,6 +3,7 @@ // Copyright(c) 2024 Intel Corporation. // +#include #include #include @@ -19,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -696,8 +698,15 @@ __cold static int extended_global_perf_data_get(uint32_t *data_off_size, char *d #ifdef CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS int ret; struct extended_global_perf_data *perf_data = (struct extended_global_perf_data *)data; + /* data_off_size is in/out: the host max reply length comes in, the + * vendor config path sets it to what is left of the reply buffer, and + * neither may exceed the IPC buffer data points into. + */ + uint32_t size = MIN(*data_off_size, SOF_IPC_MSG_MAX_SIZE); - ret = get_extended_performance_data(perf_data); + ret = get_extended_performance_data(perf_data, size); + if (ret == -ENOBUFS) + return IPC4_OUT_OF_MEMORY; if (ret < 0) return IPC4_ERROR_INVALID_PARAM; *data_off_size = sizeof(*perf_data) diff --git a/src/kernel/debug/telemetry/performance_monitor.c b/src/kernel/debug/telemetry/performance_monitor.c index 65adaba88bdb..18e92f3bc7cc 100644 --- a/src/kernel/debug/telemetry/performance_monitor.c +++ b/src/kernel/debug/telemetry/performance_monitor.c @@ -400,7 +400,8 @@ __cold int get_performance_data(struct global_perf_data * const global_perf_data } __cold int -get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data) +get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data, + uint32_t size) { assert_can_be_cold(); @@ -413,6 +414,20 @@ get_extended_performance_data(struct extended_global_perf_data * const ext_globa size_t slot_idx = 0; uint64_t total_dsp_cycles[CONFIG_MAX_CORE_COUNT]; + /* One item per enabled core plus one per occupied perf slot. Refuse the + * request when they do not all fit rather than return a report with + * items silently dropped, the host cannot tell a short report apart + * from a complete one. + */ + slots_count = popcount(cpu_enabled_cores()) + + perf_bitmap_get_occupied(&performance_data_bitmap); + if (size < sizeof(*ext_global_perf_data) || + slots_count > (size - sizeof(*ext_global_perf_data)) / + sizeof(struct ext_perf_data_item)) { + tr_err(&ipc_tr, "%zu perf items do not fit in %u bytes", slots_count, size); + return -ENOBUFS; + } + /* TODO * Setting temporary values here. * Replace this with actual total dsp cycles info once it is available.