Skip to content

Commit faafa30

Browse files
ujfalusibardliao
authored andcommitted
ASoC: SOF: ipc4-control: Fix TOCTOU in sof_ipc4_bytes_put
In sof_ipc4_bytes_put(), the copy size is derived from the old data->size in the buffer rather than the incoming new data's size field from ucontrol. If the new data has a different size, the copy uses the wrong length: it may truncate valid data or copy stale bytes. Fix by validating and using the incoming data's sof_abi_hdr.size from ucontrol before copying. Fixes: a062c88 ("ASoC: SOF: ipc4-control: Add support for bytes control get and put") Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 7177a28 commit faafa30

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

sound/soc/sof/ipc4-control.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ static int sof_ipc4_bytes_put(struct snd_sof_control *scontrol,
554554
struct snd_soc_component *scomp = scontrol->scomp;
555555
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
556556
struct sof_abi_hdr *data = cdata->data;
557+
const struct sof_abi_hdr *new_hdr =
558+
(const struct sof_abi_hdr *)ucontrol->value.bytes.data;
557559
size_t size;
558560
int ret;
559561

@@ -564,15 +566,16 @@ static int sof_ipc4_bytes_put(struct snd_sof_control *scontrol,
564566
return -EINVAL;
565567
}
566568

567-
/* scontrol->max_size has been verified to be >= sizeof(struct sof_abi_hdr) */
568-
if (data->size > scontrol->max_size - sizeof(*data)) {
569+
/* Validate the new data's size, not the old one */
570+
if (new_hdr->size > scontrol->max_size - sizeof(*new_hdr)) {
569571
dev_err_ratelimited(scomp->dev,
570572
"data size too big %u bytes max is %zu\n",
571-
data->size, scontrol->max_size - sizeof(*data));
573+
new_hdr->size,
574+
scontrol->max_size - sizeof(*new_hdr));
572575
return -EINVAL;
573576
}
574577

575-
size = data->size + sizeof(*data);
578+
size = new_hdr->size + sizeof(*new_hdr);
576579

577580
/* copy from kcontrol */
578581
memcpy(data, ucontrol->value.bytes.data, size);

0 commit comments

Comments
 (0)