From ccaf68b0d824f47fb620bf48820d0e592c9dc512 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 20 Sep 2024 18:58:16 +0300 Subject: [PATCH] Audio: Module adapter: Fix in IPC4 invalid blob pass to init() The cfg->size is the size of ipc4_base_module_cfg. The cfg->data is NULL but when such is encountered the comp_init_data_blob() allocates a zero bytes of size. Such blob is illegal and e.g. IIR will fail if not another blob is received by prepare(). DC block operates, but applies a rather high cut-off frequency that results to silent audio for e.g. lower voice frequencies. What happens with such illegal blob is component specific. The expected operation for most components is pass-through when a configuration blob is not set. This change should ensure that the component is not initialized with incorrect bytes control data if such is not passed with topology. IPC4 SRC utilizes in init() an ipc4_base_module_cfg variant that adds an uint32_t after it for sink rate. To pass the check for cfg->size the size subtract done in module adapter need to be taken into account. TODO: There is similar size check in selector, need to make similar change there. Signed-off-by: Seppo Ingalsuo --- src/audio/module_adapter/module_adapter_ipc4.c | 2 +- src/audio/src/src_ipc4.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/audio/module_adapter/module_adapter_ipc4.c b/src/audio/module_adapter/module_adapter_ipc4.c index 060cef446f73..1fa4267750c2 100644 --- a/src/audio/module_adapter/module_adapter_ipc4.c +++ b/src/audio/module_adapter/module_adapter_ipc4.c @@ -48,7 +48,7 @@ int module_adapter_init_data(struct comp_dev *dev, return -EINVAL; dst->base_cfg = cfg->base_cfg; - dst->size = cfgsz; + dst->size = cfgsz - sizeof(cfg->base_cfg); if (cfgsz >= sizeof(*cfg)) { int n_in = cfg->base_cfg_ext.nb_input_pins; diff --git a/src/audio/src/src_ipc4.c b/src/audio/src/src_ipc4.c index c337f34b404c..70d0a2437549 100644 --- a/src/audio/src/src_ipc4.c +++ b/src/audio/src/src_ipc4.c @@ -186,10 +186,12 @@ int src_init(struct processing_module *mod) struct module_config *cfg = &md->cfg; struct comp_dev *dev = mod->dev; struct comp_data *cd = NULL; + const size_t cfg_size_expect = sizeof(cd->ipc_config) - + sizeof(struct ipc4_base_module_cfg); comp_dbg(dev, "src_init()"); - if (!cfg->init_data || cfg->size != sizeof(cd->ipc_config)) { + if (!cfg->init_data || cfg->size != cfg_size_expect) { comp_err(dev, "src_init(): Missing or bad size (%u) init data", cfg->size); return -EINVAL;