mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 17:47:41 +02:00
ASoC: SOF: ipc3-control: Fix TOCTOU in bytes_put and bytes_get
In sof_ipc3_bytes_put(), the size used for the memcpy is derived from
the old data->size already in the buffer, not the incoming new data's
size field. If the new data has a different size, the copy length is
wrong: it may truncate valid data or copy stale bytes.
Similarly, sof_ipc3_bytes_get() checks data->size against max_size
without accounting for the sizeof(struct sof_ipc_ctrl_data) offset
of the flex array within the allocation.
Fix bytes_put to validate and use the incoming data's sof_abi_hdr.size
from ucontrol before copying. Fix bytes_get to subtract sizeof(*cdata)
from the bounds check to match the actual available space.
Fixes: 544ac8858f ("ASoC: SOF: Add bytes_get/put control IPC ops for IPC3")
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-6-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
390aa4c933
commit
1f97760417
|
|
@ -315,10 +315,13 @@ static int sof_ipc3_bytes_get(struct snd_sof_control *scontrol,
|
|||
}
|
||||
|
||||
/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */
|
||||
if (data->size > scontrol->max_size - sizeof(*data)) {
|
||||
if (data->size > scontrol->max_size - sizeof(*cdata) -
|
||||
sizeof(*data)) {
|
||||
dev_err_ratelimited(scomp->dev,
|
||||
"%u bytes of control data is invalid, max is %zu\n",
|
||||
data->size, scontrol->max_size - sizeof(*data));
|
||||
data->size,
|
||||
scontrol->max_size - sizeof(*cdata) -
|
||||
sizeof(*data));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -336,6 +339,8 @@ static int sof_ipc3_bytes_put(struct snd_sof_control *scontrol,
|
|||
struct sof_ipc_ctrl_data *cdata = scontrol->ipc_control_data;
|
||||
struct snd_soc_component *scomp = scontrol->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;
|
||||
|
||||
if (scontrol->max_size > sizeof(ucontrol->value.bytes.data)) {
|
||||
|
|
@ -344,14 +349,18 @@ static int sof_ipc3_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)) {
|
||||
dev_err_ratelimited(scomp->dev, "data size too big %u bytes max is %zu\n",
|
||||
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(*cdata) -
|
||||
sizeof(*new_hdr)) {
|
||||
dev_err_ratelimited(scomp->dev,
|
||||
"data size too big %u bytes max is %zu\n",
|
||||
new_hdr->size,
|
||||
scontrol->max_size - sizeof(*cdata) -
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user