FAILED: patch "[PATCH] ASoC: SOF: ipc3-control: Fix heap overflow in bytes_ext" failed to apply to 6.1-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x fd46668d538993218eea19c6925c868ac0f2630c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072001-unvocal-backtrack-aa11@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From fd46668d538993218eea19c6925c868ac0f2630c Mon Sep 17 00:00:00 2001
From: Peter Ujfalusi <[email protected]>
Date: Tue, 9 Jun 2026 11:34:58 +0300
Subject: [PATCH] ASoC: SOF: ipc3-control: Fix heap overflow in bytes_ext
put/get
The ipc_control_data buffer is allocated as kzalloc(max_size), where max_size covers the entire struct sof_ipc_ctrl_data including its flexible array payload. However, the bounds checks in bytes_ext_put and _bytes_ext_get compared user data lengths against max_size directly, ignoring that cdata->data sits at an offset of sizeof(struct sof_ipc_ctrl_data) bytes into the allocation.
This allowed writing up to sizeof(struct sof_ipc_ctrl_data) bytes past the end of the heap buffer from unprivileged userspace via the ALSA TLV kcontrol interface, and similarly allowed over-reading adjacent heap data on the get path.
Fix all bounds checks to subtract sizeof(*cdata) from max_size so they reflect the actual space available at the cdata->data offset. Also fix the error-path restore in bytes_ext_put which wrote to cdata->data instead of cdata, causing the same overflow.
sound/soc/sof/ipc3-control.c +19 -8
@@ -398,9 +398,17 @@ static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol, }/* be->max is coming from topology */ -if (header.length > scontrol->max_size) { -dev_err_ratelimited (scomp->dev,"Bytes data size %d exceeds max %zu\n" , - header.length, scontrol->max_size); +if (header.length > scontrol->max_size -sizeof (*cdata)) { +dev_err_ratelimited (scomp->dev,"Bytes data size %u exceeds max %zu\n" , + header.length, scontrol->max_size -sizeof (*cdata)); +return -EINVAL ; + } + +/* Ensure the data is large enough to contain the ABI header */ +if (header.length <sizeof (struct sof_abi_hdr )) { +dev_err_ratelimited (scomp->dev, +"Bytes data size %u less than ABI header %zu\n" , + header.length,sizeof (struct sof_abi_hdr ));return -EINVAL ; }
@@ -436,7 +444,7 @@ static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol, }/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */ -if (cdata->data->size > scontrol->max_size -sizeof (struct sof_abi_hdr )) { +if (cdata->data->size > scontrol->max_size -sizeof (*cdata) -sizeof (struct sof_abi_hdr )) {dev_err_ratelimited (scomp->dev,"Mismatch in ABI data size (truncated?)\n" ); goto err_restore; }
@@ -452,7 +460,7 @@ static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol, err_restore:/* If we have an issue, we restore the old, valid bytes control data */ if (scontrol->old_ipc_control_data) { -memcpy (cdata->data, scontrol->old_ipc_control_data, scontrol->max_size); +memcpy (cdata, scontrol->old_ipc_control_data, scontrol->max_size);kfree (scontrol->old_ipc_control_data); scontrol->old_ipc_control_data =NULL ; }
@@ -491,10 +499,13 @@ static int _sof_ipc3_bytes_ext_get(struct snd_sof_control *scontrol, }/* check data size doesn't exceed max coming from topology */ -if (cdata->data->size > scontrol->max_size -sizeof (struct sof_abi_hdr )) { -dev_err_ratelimited (scomp->dev,"User data size %d exceeds max size %zu\n" , +if (cdata->data->size > scontrol->max_size -sizeof (*cdata) - +sizeof (struct sof_abi_hdr )) { +dev_err_ratelimited (scomp->dev, +"User data size %u exceeds max size %zu\n" , cdata->data->size, - scontrol->max_size -sizeof (struct sof_abi_hdr )); + scontrol->max_size -sizeof (*cdata) - +sizeof (struct sof_abi_hdr ));return -EINVAL ; }
Sasha Levin
maintainerPATCH 1/1 ASoC: SOF: ipc3-control: Fix heap overflow in bytes_ext put/get
From: Peter Ujfalusi <[email protected]>
[ Upstream commit fd46668d538993218eea19c6925c868ac0f2630c ]
The ipc_control_data buffer is allocated as kzalloc(max_size), where max_size covers the entire struct sof_ipc_ctrl_data including its flexible array payload. However, the bounds checks in bytes_ext_put and _bytes_ext_get compared user data lengths against max_size directly, ignoring that cdata->data sits at an offset of sizeof(struct sof_ipc_ctrl_data) bytes into the allocation.
This allowed writing up to sizeof(struct sof_ipc_ctrl_data) bytes past the end of the heap buffer from unprivileged userspace via the ALSA TLV kcontrol interface, and similarly allowed over-reading adjacent heap data on the get path.
Fix all bounds checks to subtract sizeof(*cdata) from max_size so they reflect the actual space available at the cdata->data offset. Also fix the error-path restore in bytes_ext_put which wrote to cdata->data instead of cdata, causing the same overflow.
--- sound/soc/sof/ipc3-control.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-)
sound/soc/sof/ipc3-control.c +24 -10
@@ -354,10 +354,13 @@ static int sof_ipc3_bytes_ext_get(struct snd_sof_control *scontrol, cdata->data->abi =SOF_ABI_VERSION ;/* check data size doesn't exceed max coming from topology */ -if (cdata->data->size > scontrol->max_size -sizeof (struct sof_abi_hdr )) { -dev_err_ratelimited (scomp->dev,"User data size %d exceeds max size %zu\n" , +if (cdata->data->size > scontrol->max_size -sizeof (*cdata) - +sizeof (struct sof_abi_hdr )) { +dev_err_ratelimited (scomp->dev, +"User data size %u exceeds max size %zu\n" , cdata->data->size, - scontrol->max_size -sizeof (struct sof_abi_hdr )); + scontrol->max_size -sizeof (*cdata) - +sizeof (struct sof_abi_hdr ));return -EINVAL ; }
@@ -403,9 +406,17 @@ static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol, }/* be->max is coming from topology */ -if (header.length > scontrol->max_size) { -dev_err_ratelimited (scomp->dev,"Bytes data size %d exceeds max %zu\n" , - header.length, scontrol->max_size); +if (header.length > scontrol->max_size -sizeof (*cdata)) { +dev_err_ratelimited (scomp->dev,"Bytes data size %u exceeds max %zu\n" , + header.length, scontrol->max_size -sizeof (*cdata)); +return -EINVAL ; + } + +/* Ensure the data is large enough to contain the ABI header */ +if (header.length <sizeof (struct sof_abi_hdr )) { +dev_err_ratelimited (scomp->dev, +"Bytes data size %u less than ABI header %zu\n" , + header.length,sizeof (struct sof_abi_hdr ));return -EINVAL ; }
@@ -431,7 +442,7 @@ static int sof_ipc3_bytes_ext_put(struct snd_sof_control *scontrol, }/* be->max has been verified to be >= sizeof(struct sof_abi_hdr) */ -if (cdata->data->size > scontrol->max_size -sizeof (struct sof_abi_hdr )) { +if (cdata->data->size > scontrol->max_size -sizeof (*cdata) -sizeof (struct sof_abi_hdr )) {dev_err_ratelimited (scomp->dev,"Mismatch in ABI data size (truncated?)\n" );return -EINVAL ; }
@@ -473,10 +484,13 @@ static int sof_ipc3_bytes_ext_volatile_get(struct snd_sof_control *scontrol,return ret;/* check data size doesn't exceed max coming from topology */ -if (cdata->data->size > scontrol->max_size -sizeof (struct sof_abi_hdr )) { -dev_err_ratelimited (scomp->dev,"User data size %d exceeds max size %zu\n" , +if (cdata->data->size > scontrol->max_size -sizeof (*cdata) - +sizeof (struct sof_abi_hdr )) { +dev_err_ratelimited (scomp->dev, +"User data size %u exceeds max size %zu\n" , cdata->data->size, - scontrol->max_size -sizeof (struct sof_abi_hdr )); + scontrol->max_size -sizeof (*cdata) - +sizeof (struct sof_abi_hdr ));return -EINVAL ; }
Signature · 1 line
2.53.0