mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-09-22 09:34:56 +02:00
ASoC: SOF: ipc4-control: Fix TOCTOU in sof_ipc4_bytes_put
commit3ad673e713upstream. 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:a062c8899f("ASoC: SOF: ipc4-control: Add support for bytes control get and put") Cc: stable@vger.kernel.org Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com> Reviewed-by: Liam Girdwood <liam.r.girdwood@intel.com> Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com> Link: https://patch.msgid.link/20260609083458.31193-2-peter.ujfalusi@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
d7e7c81383
commit
266f936db8
@@ -407,6 +407,8 @@ static int sof_ipc4_bytes_put(struct snd_sof_control *scontrol,
|
||||
struct snd_soc_component *scomp = scontrol->scomp;
|
||||
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
|
||||
struct sof_abi_hdr *data = cdata->data;
|
||||
const struct sof_abi_hdr *new_hdr =
|
||||
(const struct sof_abi_hdr *)ucontrol->value.bytes.data;
|
||||
size_t size;
|
||||
int ret;
|
||||
|
||||
@@ -417,15 +419,16 @@ static int sof_ipc4_bytes_put(struct snd_sof_control *scontrol,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* scontrol->max_size has been verified to be >= sizeof(struct sof_abi_hdr) */
|
||||
if (data->size > scontrol->max_size - sizeof(*data)) {
|
||||
/* Validate the new data's size, not the old one */
|
||||
if (new_hdr->size > scontrol->max_size - sizeof(*new_hdr)) {
|
||||
dev_err_ratelimited(scomp->dev,
|
||||
"data size too big %u bytes max is %zu\n",
|
||||
data->size, scontrol->max_size - sizeof(*data));
|
||||
new_hdr->size,
|
||||
scontrol->max_size - sizeof(*new_hdr));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
size = data->size + sizeof(*data);
|
||||
size = new_hdr->size + sizeof(*new_hdr);
|
||||
|
||||
/* copy from kcontrol */
|
||||
memcpy(data, ucontrol->value.bytes.data, size);
|
||||
|
||||
Reference in New Issue
Block a user