Skip to content

Commit aad0658

Browse files
committed
selector: re-validate configuration on control set
A new configuration accepted at runtime through the control set path was copied in without the validation done when parameters are applied, so a later out-of-range channel count could overflow the channel table. Validate the blob size and channel fields before accepting it. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 3f7738d commit aad0658

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/audio/selector/selector.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,48 @@ static int selector_ctrl_set_data(struct comp_dev *dev,
238238
case SOF_CTRL_CMD_BINARY:
239239
comp_dbg(dev, "SOF_CTRL_CMD_BINARY");
240240

241+
if (cdata->data->size < sizeof(struct sof_sel_config)) {
242+
comp_err(dev, "invalid config blob size %u", cdata->data->size);
243+
return -EINVAL;
244+
}
245+
241246
cfg = (struct sof_sel_config *)
242247
ASSUME_ALIGNED(&cdata->data->data, 4);
243248

249+
/*
250+
* The config validated at .params() time can be replaced here at
251+
* runtime, so re-validate the new channel counts and selected
252+
* channel before accepting them; otherwise an out-of-range value
253+
* later overflows the channel coefficient table during process().
254+
*/
255+
switch (cfg->in_channels_count) {
256+
case 0:
257+
case SEL_SOURCE_2CH:
258+
case SEL_SOURCE_4CH:
259+
break;
260+
default:
261+
comp_err(dev, "invalid in_channels_count %u",
262+
cfg->in_channels_count);
263+
return -EINVAL;
264+
}
265+
266+
switch (cfg->out_channels_count) {
267+
case 0:
268+
case SEL_SINK_1CH:
269+
case SEL_SINK_2CH:
270+
case SEL_SINK_4CH:
271+
break;
272+
default:
273+
comp_err(dev, "invalid out_channels_count %u",
274+
cfg->out_channels_count);
275+
return -EINVAL;
276+
}
277+
278+
if (cfg->sel_channel >= SEL_SOURCE_CHANNELS_MAX) {
279+
comp_err(dev, "invalid sel_channel %u", cfg->sel_channel);
280+
return -EINVAL;
281+
}
282+
244283
/* Just set the configuration */
245284
cd->config.in_channels_count = cfg->in_channels_count;
246285
cd->config.out_channels_count = cfg->out_channels_count;

0 commit comments

Comments
 (0)