From d282b64a8f4e0298089f2f73b68391b7e9cf1b80 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Thu, 18 Jun 2026 17:05:11 +0300 Subject: [PATCH] audio: drc: register IPC-time blob validator Hook a drc blob validator into the model handler so a corrupted run-time configuration update is rejected before it can replace the working blob. Playback or capture then continues with the previously set parameters instead of being interrupted by a bad IPC. The DRC configuration is a fixed-size struct sof_drc_config, so the validator requires the IPC payload size to match exactly and the self-declared config->size to agree with it. The same size check is also reused at prepare time when the initial blob is fetched. Signed-off-by: Seppo Ingalsuo --- src/audio/drc/drc.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/audio/drc/drc.c b/src/audio/drc/drc.c index 7fe86ce01c56..ff072e8d3da9 100644 --- a/src/audio/drc/drc.c +++ b/src/audio/drc/drc.c @@ -139,6 +139,20 @@ static int drc_setup(struct processing_module *mod, uint16_t channels, uint32_t return drc_set_pre_delay_time(&cd->state, cd->config->params.pre_delay_time, rate); } +static int drc_validator(struct comp_dev *dev, void *new_data, uint32_t new_data_size) +{ + struct sof_drc_config *config = new_data; + + if (new_data_size != sizeof(struct sof_drc_config) || + new_data_size != config->size) { + comp_err(dev, "invalid configuration blob, size %u, expected %zu", + new_data_size, sizeof(struct sof_drc_config)); + return -EINVAL; + } + + return 0; +} + /* * End of DRC setup code. Next the standard component methods. */ @@ -353,10 +367,14 @@ static int drc_prepare(struct processing_module *mod, /* Initialize DRC */ comp_info(dev, "source_format=%d", cd->source_format); cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL); - /* the blob is dereferenced as a struct sof_drc_config below and in - * drc_setup(), so require it to be at least that large + /* The blob is dereferenced as a struct sof_drc_config below and in + * drc_setup(), so size-check it before use. Discard a malformed blob + * so the runtime path (drc_process()) cannot dereference it. */ - if (cd->config && data_size >= sizeof(struct sof_drc_config)) { + if (cd->config && drc_validator(dev, cd->config, data_size) != 0) + cd->config = NULL; + + if (cd->config) { ret = drc_setup(mod, channels, rate); if (ret < 0) { comp_err(dev, "error: drc_setup failed."); @@ -382,6 +400,11 @@ static int drc_prepare(struct processing_module *mod, cd->drc_func = drc_default_pass; } + /* Reject malformed blobs at IPC time so a bad run-time update cannot + * replace the working configuration. + */ + comp_data_blob_set_validator(cd->model_handler, drc_validator); + comp_info(dev, "DRC is configured."); return 0; } @@ -390,6 +413,8 @@ static int drc_reset(struct processing_module *mod) { struct drc_comp_data *cd = module_get_private_data(mod); + comp_data_blob_set_validator(cd->model_handler, NULL); + drc_reset_state(mod, &cd->state); return 0;