Skip to content

Commit 04807e5

Browse files
committed
ipc3: Add size checks on ipc subtypes
We have a few gaps in input validation from the kernel. Right now we check the IPC doesn't claim its larger the window, this patch adds the following checks: 1. That the IPC size is at least large enough for any downcast type on comp new 2. That any reported size for a process total size is less than the IPC window. Also adjust the other helper to be a bit safer and more direct Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
1 parent b58df6d commit 04807e5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/include/sof/ipc/common.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ struct ipc_msg;
2727

2828
/* validates internal non tail structures within IPC command structure */
2929
#define IPC_IS_SIZE_INVALID(object) \
30-
(object).hdr.size == sizeof(object) ? 0 : 1
30+
((object).hdr.size != sizeof(object))
31+
32+
#define IPC_TAIL_IS_SIZE_INVALID(object) \
33+
((object).comp.hdr.size + (object).comp.ext_data_length < sizeof(object))
3134

3235
/* ipc trace context, used by multiple units */
3336
extern struct tr_ctx ipc_tr;

src/ipc/ipc3/helper.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ static int comp_specific_builder(struct sof_ipc_comp *comp,
215215
case SOF_COMP_SG_HOST:
216216
case SOF_COMP_DAI:
217217
case SOF_COMP_SG_DAI:
218+
if (IPC_TAIL_IS_SIZE_INVALID(*file))
219+
return -EBADMSG;
218220
config->file.channels = file->channels;
219221
config->file.fn = file->fn;
220222
config->file.frame_fmt = file->frame_fmt;
@@ -225,30 +227,40 @@ static int comp_specific_builder(struct sof_ipc_comp *comp,
225227
#else
226228
case SOF_COMP_HOST:
227229
case SOF_COMP_SG_HOST:
230+
if (IPC_TAIL_IS_SIZE_INVALID(*host))
231+
return -EBADMSG;
228232
config->host.direction = host->direction;
229233
config->host.no_irq = host->no_irq;
230234
config->host.dmac_config = host->dmac_config;
231235
break;
232236
case SOF_COMP_DAI:
233237
case SOF_COMP_SG_DAI:
238+
if (IPC_TAIL_IS_SIZE_INVALID(*dai))
239+
return -EBADMSG;
234240
config->dai.dai_index = dai->dai_index;
235241
config->dai.direction = dai->direction;
236242
config->dai.type = dai->type;
237243
break;
238244
#endif
239245
case SOF_COMP_VOLUME:
246+
if (IPC_TAIL_IS_SIZE_INVALID(*vol))
247+
return -EBADMSG;
240248
config->volume.channels = vol->channels;
241249
config->volume.initial_ramp = vol->initial_ramp;
242250
config->volume.max_value = vol->max_value;
243251
config->volume.min_value = vol->min_value;
244252
config->volume.ramp = vol->ramp;
245253
break;
246254
case SOF_COMP_SRC:
255+
if (IPC_TAIL_IS_SIZE_INVALID(*src))
256+
return -EBADMSG;
247257
config->src.rate_mask = src->rate_mask;
248258
config->src.sink_rate = src->sink_rate;
249259
config->src.source_rate = src->source_rate;
250260
break;
251261
case SOF_COMP_TONE:
262+
if (IPC_TAIL_IS_SIZE_INVALID(*tone))
263+
return -EBADMSG;
252264
config->tone.ampl_mult = tone->ampl_mult;
253265
config->tone.amplitude = tone->amplitude;
254266
config->tone.freq_mult = tone->freq_mult;
@@ -260,6 +272,8 @@ static int comp_specific_builder(struct sof_ipc_comp *comp,
260272
config->tone.sample_rate = tone->sample_rate;
261273
break;
262274
case SOF_COMP_ASRC:
275+
if (IPC_TAIL_IS_SIZE_INVALID(*asrc))
276+
return -EBADMSG;
263277
config->asrc.source_rate = asrc->source_rate;
264278
config->asrc.sink_rate = asrc->sink_rate;
265279
config->asrc.asynchronous_mode = asrc->asynchronous_mode;
@@ -276,6 +290,12 @@ static int comp_specific_builder(struct sof_ipc_comp *comp,
276290
case SOF_COMP_SMART_AMP:
277291
case SOF_COMP_MODULE_ADAPTER:
278292
case SOF_COMP_NONE:
293+
if (IPC_TAIL_IS_SIZE_INVALID(*proc))
294+
return -EBADMSG;
295+
296+
if (proc->comp.hdr.size + proc->comp.ext_data_length > SOF_IPC_MSG_MAX_SIZE)
297+
return -EBADMSG;
298+
279299
config->process.type = proc->type;
280300
config->process.size = proc->size;
281301
#if CONFIG_LIBRARY || UNIT_TEST

0 commit comments

Comments
 (0)