Skip to content

Commit ca8ccef

Browse files
committed
dts: validate parameter size against remaining config blob
The configuration parser advanced through packed parameters using a size field read from the blob without checking it against the bytes remaining, allowing reads past the configuration data. Track the remaining length and reject a header or parameter that does not fit. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 3f7738d commit ca8ccef

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/audio/codec/dts/dts.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,29 @@ static int dts_codec_apply_config(struct processing_module *mod)
328328

329329
/* Allow for multiple module_params to be packed into the data pointed to by config
330330
*/
331+
param_header_size = sizeof(param->id) + sizeof(param->size);
331332
for (i = 0; i < config_data_size; param_number++) {
333+
/* Need at least a param header in the remaining bytes to read id/size */
334+
if (config_data_size - i < param_header_size) {
335+
comp_err(dev, "param header truncated");
336+
return -EINVAL;
337+
}
338+
332339
param = (struct module_param *)((char *)config->data + i);
333-
param_header_size = sizeof(param->id) + sizeof(param->size);
334340

335341
/* If param->size is less than param_header_size, then this param is not valid */
336342
if (param->size < param_header_size) {
337343
comp_err(dev, "param is invalid");
338344
return -EINVAL;
339345
}
340346

347+
/* The whole param (header + data) must fit in the remaining config data */
348+
if (param->size > config_data_size - i) {
349+
comp_err(dev, "param size %u exceeds remaining %u",
350+
param->size, config_data_size - i);
351+
return -EINVAL;
352+
}
353+
341354
/* Only process param->data if it has size greater than 0 */
342355
if (param->size > param_header_size) {
343356
/* Calculate size of param->data */

0 commit comments

Comments
 (0)