Skip to content

Commit e7488f0

Browse files
ujfalusibardliao
authored andcommitted
ASoC: SOF: ipc3-control: Use overflow checks in control_update size calc
In sof_ipc3_control_update(), the expected_size calculation uses firmware-provided cdata->num_elems in arithmetic that could overflow on 32-bit platforms, wrapping to a small value. This would allow the cdata->rhdr.hdr.size comparison to pass with mismatched sizes, potentially leading to out-of-bounds access in snd_sof_update_control. Use check_mul_overflow() and check_add_overflow() to detect and reject overflowed size calculations. Fixes: 10f461d ("ASoC: SOF: Add IPC3 topology control ops") Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent faafa30 commit e7488f0

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

sound/soc/sof/ipc3-control.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,16 +626,28 @@ static void sof_ipc3_control_update(struct snd_sof_dev *sdev, void *ipc_control_
626626
return;
627627
}
628628

629-
expected_size = sizeof(struct sof_ipc_ctrl_data);
630629
switch (cdata->type) {
631630
case SOF_CTRL_TYPE_VALUE_CHAN_GET:
632631
case SOF_CTRL_TYPE_VALUE_CHAN_SET:
633-
expected_size += cdata->num_elems *
634-
sizeof(struct sof_ipc_ctrl_value_chan);
632+
if (check_mul_overflow((size_t)cdata->num_elems,
633+
sizeof(struct sof_ipc_ctrl_value_chan),
634+
&expected_size))
635+
return;
636+
if (check_add_overflow(expected_size,
637+
sizeof(struct sof_ipc_ctrl_data),
638+
&expected_size))
639+
return;
635640
break;
636641
case SOF_CTRL_TYPE_DATA_GET:
637642
case SOF_CTRL_TYPE_DATA_SET:
638-
expected_size += cdata->num_elems + sizeof(struct sof_abi_hdr);
643+
if (check_add_overflow((size_t)cdata->num_elems,
644+
sizeof(struct sof_abi_hdr),
645+
&expected_size))
646+
return;
647+
if (check_add_overflow(expected_size,
648+
sizeof(struct sof_ipc_ctrl_data),
649+
&expected_size))
650+
return;
639651
break;
640652
default:
641653
return;

0 commit comments

Comments
 (0)