Skip to content

Commit 221f511

Browse files
ujfalusibardliao
authored andcommitted
ASoC: SOF: ipc4-control: Validate notification payload size
Validate MODULE_NOTIFICATION payload length before reading bytes/channel data in control update handling. Fixes: 2a28b52 ("ASoC: SOF: ipc4-control: Add support for generic bytes control") Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 001d86e commit 221f511

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

sound/soc/sof/ipc4-control.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,16 @@ static void sof_ipc4_control_update(struct snd_sof_dev *sdev, void *ipc_message)
875875
*/
876876
if (type == SND_SOC_TPLG_TYPE_BYTES) {
877877
struct sof_abi_hdr *data = cdata->data;
878+
size_t source_size = struct_size(msg_data, data, msg_data->num_elems);
879+
880+
if (source_size > ndata->event_data_size) {
881+
dev_warn(sdev->dev,
882+
"%s: invalid bytes notification size for %s (%zu, %u)\n",
883+
__func__, scontrol->name, source_size,
884+
ndata->event_data_size);
885+
scontrol->comp_data_dirty = true;
886+
goto notify;
887+
}
878888

879889
if (msg_data->num_elems > scontrol->max_size - sizeof(*data)) {
880890
dev_warn(sdev->dev,
@@ -887,6 +897,17 @@ static void sof_ipc4_control_update(struct snd_sof_dev *sdev, void *ipc_message)
887897
scontrol->size = sizeof(*cdata) + sizeof(*data) + data->size;
888898
}
889899
} else {
900+
size_t source_size = struct_size(msg_data, chanv, msg_data->num_elems);
901+
902+
if (source_size > ndata->event_data_size) {
903+
dev_warn(sdev->dev,
904+
"%s: invalid channel notification size for %s (%zu, %u)\n",
905+
__func__, scontrol->name, source_size,
906+
ndata->event_data_size);
907+
scontrol->comp_data_dirty = true;
908+
goto notify;
909+
}
910+
890911
for (i = 0; i < msg_data->num_elems; i++) {
891912
u32 channel = msg_data->chanv[i].channel;
892913

@@ -914,6 +935,8 @@ static void sof_ipc4_control_update(struct snd_sof_dev *sdev, void *ipc_message)
914935
scontrol->comp_data_dirty = true;
915936
}
916937

938+
notify:
939+
917940
/*
918941
* Look up the ALSA kcontrol of the scontrol to be able to send a
919942
* notification to user space

0 commit comments

Comments
 (0)