Skip to content

Commit f17ce06

Browse files
kv2019ilgirdwood
authored andcommitted
module: bound the sink count in module_get_deadline()
module_get_deadline() runs for DP modules, whose struct processing_module the DP thread can write. Read the sink count once, limit it to the size of the sink array and skip unset sinks, so a forged count cannot make the caller read past the array. The sink operations it calls are still taken from DP-writable memory. With CONFIG_SOF_USERSPACE_LL this now happens in the LL user thread; isolating it from DP threads is a separate issue. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 95ef722 commit f17ce06

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/audio/module_adapter/module/generic.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,8 +1030,12 @@ __cold int module_unbind(struct processing_module *mod, const struct bind_info *
10301030

10311031
uint32_t module_get_deadline(struct processing_module *mod)
10321032
{
1033+
/* a DP module can write mod: read the count once and bound it */
1034+
size_t num_of_sinks = mod->num_of_sinks;
10331035
uint32_t deadline;
10341036

1037+
num_of_sinks = MIN(num_of_sinks, ARRAY_SIZE(mod->sinks));
1038+
10351039
/* LL modules have no deadline - it is always "now" */
10361040
if (mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_LL)
10371041
return 0;
@@ -1042,9 +1046,14 @@ uint32_t module_get_deadline(struct processing_module *mod)
10421046

10431047
deadline = UINT32_MAX;
10441048
/* calculate the shortest LFT for all sinks */
1045-
for (size_t i = 0; i < mod->num_of_sinks; i++) {
1046-
uint32_t sink_lft = sink_get_last_feeding_time(mod->sinks[i]);
1049+
for (size_t i = 0; i < num_of_sinks; i++) {
1050+
struct sof_sink *sink = mod->sinks[i];
1051+
uint32_t sink_lft;
1052+
1053+
if (!sink)
1054+
continue;
10471055

1056+
sink_lft = sink_get_last_feeding_time(sink);
10481057
deadline = MIN(deadline, sink_lft);
10491058
}
10501059

0 commit comments

Comments
 (0)