FAILED: patch "[PATCH] ASoC: qcom: audioreach: fix module cfg blob size handling" failed to apply to 6.18-stable tree
Subsystems (4)
Sasha Levin
maintainerThe patch below does not apply to the 6.18-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.18.y
git checkout FETCH_HEAD
git cherry-pick -x e21fb64a8c4aecae31ec63f994423ac944705c3e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From e21fb64a8c4aecae31ec63f994423ac944705c3e Mon Sep 17 00:00:00 2001
From: Ravi Hothi <[email protected]>
Date: Fri, 23 Oct 2026 18:13:10 +0100
Subject: [PATCH] ASoC: qcom: audioreach: fix module cfg blob size handling
audioreach_get_module_priv_data() passes mod_array->size, a byte count, as the element count of the __le32 data[] flex array. The allocation and the copy are four times too large, and the memcpy() can read past the end of the topology firmware buffer. The size is also never checked against the private data it must lie within, and a zero size makes the loop spin forever.
Convert the size to a word count, bound the blob by the remaining private data and reject a zero size. Also check the returned pointer before storing it in mod->data, as an error pointer there is dereferenced when the graph is opened.
--- sound/soc/qcom/qdsp6/topology.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-)
sound/soc/qcom/qdsp6/topology.c +26 -5
@@ -312,22 +312,37 @@ audioreach_get_module_priv_data(const struct snd_soc_tplg_private *private)for (sz =0 ; sz <le32_to_cpu (private->size); ) {const struct snd_soc_tplg_vendor_array *mod_array; +u32 array_size; mod_array = (struct snd_soc_tplg_vendor_array *)((u8 *)private->array + sz); + array_size =le32_to_cpu (mod_array->size); +if (le32_to_cpu (mod_array->type) ==SND_SOC_AR_TPLG_MODULE_CFG_TYPE ) {struct audioreach_module_priv_data *pdata; +u32 nwords; + +/* size is the byte count of the __le32 data[] */ + nwords = array_size /sizeof (__le32); + +/* the blob must lie within the private data */ +if (sizeof (*pdata) + (u64 )array_size > +le32_to_cpu (private->size) - sz) +return ERR_PTR (-EINVAL ); - pdata =kzalloc_flex (*pdata, data, -le32_to_cpu (mod_array->size)); + pdata =kzalloc_flex (*pdata, data, nwords);if (!pdata)return ERR_PTR (-ENOMEM ); -memcpy (pdata, ((u8 *)private->data + sz),struct_size (pdata, data, -le32_to_cpu (mod_array->size))); +memcpy (pdata, ((u8 *)private->data + sz), +struct_size (pdata, data, nwords));return pdata; } - sz = sz +le32_to_cpu (mod_array->size); +/* a zero size would never advance the walk */ +if (!array_size) +return ERR_PTR (-EINVAL ); + + sz = sz + array_size; }return NULL ;
@@ -611,6 +626,12 @@ static int audioreach_widget_load_module_common(struct snd_soc_component *componreturn mod ?PTR_ERR (mod) : -ENODEV ; mod->data =audioreach_get_module_priv_data (&tplg_w->priv); +if (IS_ERR (mod->data)) { +int rc =PTR_ERR (mod->data); + + mod->data =NULL ; +return rc; + } dobj = &w->dobj; dobj->private = mod;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 ASoC: qcom: audioreach: fix module cfg blob size handling
From: Ravi Hothi <[email protected]>
[ Upstream commit e21fb64a8c4aecae31ec63f994423ac944705c3e ]
audioreach_get_module_priv_data() passes mod_array->size, a byte count, as the element count of the __le32 data[] flex array. The allocation and the copy are four times too large, and the memcpy() can read past the end of the topology firmware buffer. The size is also never checked against the private data it must lie within, and a zero size makes the loop spin forever.
Convert the size to a word count, bound the blob by the remaining private data and reject a zero size. Also check the returned pointer before storing it in mod->data, as an error pointer there is dereferenced when the graph is opened.
--- sound/soc/qcom/qdsp6/topology.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-)
sound/soc/qcom/qdsp6/topology.c +26 -5
@@ -312,22 +312,37 @@ static struct audioreach_module_priv_data *audioreach_get_module_priv_data(for (sz =0 ; sz <le32_to_cpu (private->size); ) {struct snd_soc_tplg_vendor_array *mod_array; +u32 array_size; mod_array = (struct snd_soc_tplg_vendor_array *)((u8 *)private->array + sz); + array_size =le32_to_cpu (mod_array->size); +if (le32_to_cpu (mod_array->type) ==SND_SOC_AR_TPLG_MODULE_CFG_TYPE ) {struct audioreach_module_priv_data *pdata; +u32 nwords; + +/* size is the byte count of the __le32 data[] */ + nwords = array_size /sizeof (__le32); + +/* the blob must lie within the private data */ +if (sizeof (*pdata) + (u64 )array_size > +le32_to_cpu (private->size) - sz) +return ERR_PTR (-EINVAL ); - pdata =kzalloc (struct_size (pdata, data,le32_to_cpu (mod_array->size)), -GFP_KERNEL ); + pdata =kzalloc_flex (*pdata, data, nwords);if (!pdata)return ERR_PTR (-ENOMEM ); -memcpy (pdata, ((u8 *)private->data + sz),struct_size (pdata, data, -le32_to_cpu (mod_array->size))); +memcpy (pdata, ((u8 *)private->data + sz), +struct_size (pdata, data, nwords));return pdata; } - sz = sz +le32_to_cpu (mod_array->size); +/* a zero size would never advance the walk */ +if (!array_size) +return ERR_PTR (-EINVAL ); + + sz = sz + array_size; }return NULL ;
@@ -611,6 +626,12 @@ static int audioreach_widget_load_module_common(struct snd_soc_component *componreturn mod ?PTR_ERR (mod) : -ENODEV ; mod->data =audioreach_get_module_priv_data (&tplg_w->priv); +if (IS_ERR (mod->data)) { +int rc =PTR_ERR (mod->data); + + mod->data =NULL ; +return rc; + } dobj = &w->dobj; dobj->private = mod;
Signature · 1 line
2.53.0