Skip to content

Commit d282b64

Browse files
committed
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 <seppo.ingalsuo@linux.intel.com>
1 parent e87b9af commit d282b64

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

‎src/audio/drc/drc.c‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ static int drc_setup(struct processing_module *mod, uint16_t channels, uint32_t
139139
return drc_set_pre_delay_time(&cd->state, cd->config->params.pre_delay_time, rate);
140140
}
141141

142+
static int drc_validator(struct comp_dev *dev, void *new_data, uint32_t new_data_size)
143+
{
144+
struct sof_drc_config *config = new_data;
145+
146+
if (new_data_size != sizeof(struct sof_drc_config) ||
147+
new_data_size != config->size) {
148+
comp_err(dev, "invalid configuration blob, size %u, expected %zu",
149+
new_data_size, sizeof(struct sof_drc_config));
150+
return -EINVAL;
151+
}
152+
153+
return 0;
154+
}
155+
142156
/*
143157
* End of DRC setup code. Next the standard component methods.
144158
*/
@@ -353,10 +367,14 @@ static int drc_prepare(struct processing_module *mod,
353367
/* Initialize DRC */
354368
comp_info(dev, "source_format=%d", cd->source_format);
355369
cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL);
356-
/* the blob is dereferenced as a struct sof_drc_config below and in
357-
* drc_setup(), so require it to be at least that large
370+
/* The blob is dereferenced as a struct sof_drc_config below and in
371+
* drc_setup(), so size-check it before use. Discard a malformed blob
372+
* so the runtime path (drc_process()) cannot dereference it.
358373
*/
359-
if (cd->config && data_size >= sizeof(struct sof_drc_config)) {
374+
if (cd->config && drc_validator(dev, cd->config, data_size) != 0)
375+
cd->config = NULL;
376+
377+
if (cd->config) {
360378
ret = drc_setup(mod, channels, rate);
361379
if (ret < 0) {
362380
comp_err(dev, "error: drc_setup failed.");
@@ -382,6 +400,11 @@ static int drc_prepare(struct processing_module *mod,
382400
cd->drc_func = drc_default_pass;
383401
}
384402

403+
/* Reject malformed blobs at IPC time so a bad run-time update cannot
404+
* replace the working configuration.
405+
*/
406+
comp_data_blob_set_validator(cd->model_handler, drc_validator);
407+
385408
comp_info(dev, "DRC is configured.");
386409
return 0;
387410
}
@@ -390,6 +413,8 @@ static int drc_reset(struct processing_module *mod)
390413
{
391414
struct drc_comp_data *cd = module_get_private_data(mod);
392415

416+
comp_data_blob_set_validator(cd->model_handler, NULL);
417+
393418
drc_reset_state(mod, &cd->state);
394419

395420
return 0;

0 commit comments

Comments
 (0)