From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796391328; b=ctp02+7uB3gjPmsNnLGwgL+HpoRtPO1ojsju1QZv+f9isknmuHSXnC+6NZepGP6mJxGM kEaHVdk3awCYdjwk3wyh+d5spB6xKKqgHXRmwMLBeB5W531KXs6fMQY3FXxDyE7/fCqG0 pHGS794g8GnMc/DSvE19kw2SPGj4YpeZhgSSndlvnHan3C2Wv/UNGsaNha7Dl1e9Cmu3z K/Vd1tx3kn0I19SD/FTMB1xCwdkeySR5MJlOaHOBbmAcHotJYA2fysdFRaZpqraiSXZcR Dij1blfvJAqHY7tq8BZQWD3g3/iug9rNLUgulsG1HHHS9qCgyDVmgCc1GHb/5cleh4w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796391328; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=1OkZYsVz4KkXJvaQVeKbJpj4dC8csGjnsB263cG84Dw=; b=qi/YA2y+Dnsgle5OvfRab8dCm/98O+x64NFnF7iXIHIxSE0KU1NgPyei/mytigPHUe5f IKQqdyJrUtacms2T0DwMrNI01lbOc2inRaDSHTjhRSarWcyGQ9cZHKJwyI0BOI3MnRuR1 Rwtilph/9irFKjPVaNMuMG+D0mnKQTjCmYWuW+/Wi4HkaaYH3P3yIRG+ozrfWrFT2HBzG rRb39o4dQLeiQwyf+/l51pGUar2G/LxGjnZzRS1FTfvL83CQNSsQ4qtHDV27rom05EtBn FmstyVvwXSG5pUhOM1t4i8WVjAgNkWPVzEtcarY2WpjFDIqurysiyf4ZEud8sBgeoxw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="TpmByo/3"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8996B606A322; Fri, 4 Dec 2026 13:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TpmByo/3 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17E061F000C2; Fri, 4 Dec 2026 13:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796391328; bh=1OkZYsVz4KkXJvaQVeKbJpj4dC8csGjnsB263cG84Dw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=TpmByo/3i5YhK3qt/aAvvfUrXN2PrZUyri1JhsySdSx0bLFNRRaSLrp8+LZhEaaB3 hI8UkMsz6aypMaPno0MaehCpQH+I1nHmpNzayWEnQfy+rIUM1OHqA5BMgOsZV+AsUL +DOIEXNlXfL7DCp1JU3/n3Id6MJHYqaeJUv7O0PHQ7jWEDzHloQpVOmJjjyUMK9Ryn Nu8VP+9PeZe9A1Cmfgj5IeBVJPfTC5eFe3/f87611R8ujz09QRRlMZn47P01VBqub9 i9NwuvZMwiYQJHD59qRaUIaXs9j7rY3AIYDe+QlzZsGRva2pgQb9BWFDZBR9j5v4Bh zpcmpAuN+P6zw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 09/24] ASoC: qcom: audioreach: add control link support to graphs Reply-To: sashiko-reviews@lists.linux.dev To: "Srinivas Kandagatla" Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204113101.1141644-10-srinivas.kandagatla@oss.qualcomm.com> References: <20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com> <20261204113101.1141644-10-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 13:35:27 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [High] ASoC: qcom: audioreach: fixed link_obj stride mismatches variable prop_size - [Medium] ASoC: qcom: audioreach: control link dedup in audioreach_populate_graph() drops links - [Medium] ASoC: qcom: audioreach: global control_links_idr drops shared control links - [Medium] ASoC: qcom: audioreach: OOB read and hang in audioreach_parse_cl_tokens() - [Medium] ASoC: qcom: audioreach: link->id overwrite corrupts control_links_idr - [Medium] ASoC: qcom: audioreach: ignored errors in audioreach_parse_cl_tokens() - [Medium] ASoC: qcom: audioreach: control link leak on widget load failure -- commit 47c372c9486ab9218c7d3bbd81b6ac2224d34f0e Author: Srinivas Kandagatla ASoC: qcom: audioreach: add control link support to graphs This commit parses control link tokens from topology files into a per-subgraph list and appends deduplicated control link objects to the APM_CMD_GRAPH_OPEN packet sent to the DSP. > diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/aud= ioreach.c > index 5b5289bf6d139..f66d3ff68a441 100644 > --- a/sound/soc/qcom/qdsp6/audioreach.c > +++ b/sound/soc/qcom/qdsp6/audioreach.c [ ... ] > @@ -426,6 +449,47 @@ static void audioreach_populate_graph(struct q6apm *= apm, > =20 > apm_populate_sub_graph_config(sg_cfg, sg); > =20 > + list_for_each_entry(clink, &sg->control_link_list, node) { > + bool dup =3D false; > + int k; > + > + /* Both subgraphs usually declare the link, send it once */ > + for (k =3D 0; k < nlink; k++) { > + struct apm_control_link_obj *o =3D &cl_data->link_obj[k]; > + > + if ((o->peer1_mod_inst_id =3D=3D clink->peer1_mod_inst_id && > + o->peer2_mod_inst_id =3D=3D clink->peer2_mod_inst_id) || > + (o->peer1_mod_inst_id =3D=3D clink->peer2_mod_inst_id && > + o->peer2_mod_inst_id =3D=3D clink->peer1_mod_inst_id)) { > + dup =3D true; > + break; > + } > + } > + if (dup) > + continue; [Severity: Medium] Does this deduplication drop distinct control links between the same two module instances on different control ports? The comparison only checks peer1_mod_inst_id and peer2_mod_inst_id, ignoring peer1_mod_port_id and peer2_mod_port_id. If two modules share more than one control link on separate ports, subsequent links are silently omitted from APM_CMD_GRAPH_OPEN. Comparing both module instance IDs and their matching port IDs in both peer orders would avoid dropping them. > + clink_obj =3D &cl_data->link_obj[nlink++]; > + clink_obj->peer1_mod_inst_id =3D clink->peer1_mod_inst_id; > + clink_obj->peer1_mod_port_id =3D clink->peer1_mod_port_id; > + clink_obj->peer2_mod_inst_id =3D clink->peer2_mod_inst_id; > + clink_obj->peer2_mod_port_id =3D clink->peer2_mod_port_id; > + clink_obj->intent_data.prop_id =3D APM_MODULE_PROP_ID_CTRL_LINK_INTEN= T_LIST; > + clink_obj->num_props =3D 1; > + clink_obj->num_intents =3D 0; > + > + /* Pack the intents that are set into a dense list */ > + for (j =3D 0; j < MAX_INTENTS; j++) { > + if (clink->intent[j]) > + clink_obj->intent_id_list[clink_obj->num_intents++] =3D > + clink->intent[j]; > + } > + > + /* The list length itself is part of the property payload */ > + clink_obj->intent_data.prop_size =3D > + sizeof(clink_obj->num_intents) + > + clink_obj->num_intents * sizeof(clink_obj->intent_id_list[0]); > + } [Severity: High] Can the fixed 48-byte stride of cl_data->link_obj[] misalign the wire layout when a control link has fewer than MAX_INTENTS intents? struct apm_control_link_obj embeds a fixed u32 intent_id_list[MAX_INTENTS], so link_obj[nlink++] always advances by 48 bytes, while intent_data.prop_si= ze only accounts for num_intents entries. When a graph has two or more unique control links and an earlier link has fewer than four intents, the DSP advances past intent_data by prop_size and reads the trailing zero slots as the next link's peer IDs, corrupting subsequent links or failing APM_CMD_GRAPH_OPEN. Using a flexible intent_id_list[] array and advancing a byte pointer per li= nk (as struct apm_mod_list_obj does in this file) would match the variable prop_size. [ ... ] > diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topol= ogy.c > index aa2ab2b058d0f..5dd7f2c51d5cf 100644 > --- a/sound/soc/qcom/qdsp6/topology.c > +++ b/sound/soc/qcom/qdsp6/topology.c [ ... ] > @@ -113,6 +114,51 @@ static struct audioreach_sub_graph *audioreach_tplg_= alloc_sub_graph(struct q6apm > return sg; > } > =20 > +static struct audioreach_control_link *audioreach_tplg_alloc_control_lin= k(struct q6apm *apm, > + struct audioreach_sub_graph *sg, > + uint32_t control_link_id, > + bool *found) > +{ > + struct audioreach_control_link *link; > + int ret; > + > + if (!control_link_id) > + return ERR_PTR(-EINVAL); > + > + mutex_lock(&apm->lock); > + link =3D idr_find(&apm->control_links_idr, control_link_id); > + mutex_unlock(&apm->lock); > + > + if (link) { > + *found =3D true; > + return link; > + } [Severity: Medium] Will the card-global apm->control_links_idr omit control links when two subgraphs use the same AR_TKN_U32_CONTROL_LINK_IID? When idr_find() matches an entry registered under a different subgraph, this returns *found =3D true without adding the link to sg->control_link_list. = Any graph containing only that second subgraph then sends APM_CMD_GRAPH_OPEN without the control link. Since AR_TKN_U32_CONTROL_LINK_IID is never sent to the DSP and apm->control_links_idr is unused elsewhere, searching sg->control_link_list directly would scope deduplication per subgraph and avoid the global IDR. [ ... ] > @@ -348,6 +394,85 @@ audioreach_get_module_priv_data(const struct snd_soc= _tplg_private *private) > return NULL; > } > =20 > +static void audioreach_parse_control_link_tokens(struct q6apm *apm, > + struct audioreach_control_link *link, > + const struct snd_soc_tplg_vendor_array *cl_array) > +{ > + const struct snd_soc_tplg_vendor_value_elem *cl_elem =3D cl_array->valu= e; > + int tkn_count =3D 0; > + > + while (tkn_count <=3D (le32_to_cpu(cl_array->num_elems) - 1)) { > + switch (le32_to_cpu(cl_elem->token)) { > + case AR_TKN_U32_CONTROL_LINK_IID: > + link->id =3D le32_to_cpu(cl_elem->value); > + break; [Severity: Medium] Can overwriting link->id here corrupt apm->control_links_idr? audioreach_tplg_alloc_control_link() has already inserted link into apm->control_links_idr under the original control_link_id. If a vendor arr= ay contains a second AR_TKN_U32_CONTROL_LINK_IID token with a different value (audioreach_parse_cl_tokens() also keeps looping after the first match), link->id is overwritten, so audioreach_widget_unload() removes the wrong IDR key and frees link, leaving a dangling pointer in apm->control_links_idr and causing a use-after-free on later topology reloads. [ ... ] > +static void audioreach_parse_cl_tokens(struct q6apm *apm, struct audiore= ach_sub_graph *sg, > + const struct snd_soc_tplg_private *private) > +{ > + const struct snd_soc_tplg_vendor_value_elem *cl_elem; > + const struct snd_soc_tplg_vendor_array *cl_array; > + struct audioreach_control_link *link; > + int link_id, tkn_count, sz; > + bool found =3D false; > + > + for (sz =3D 0; sz < le32_to_cpu(private->size);) { > + cl_array =3D (struct snd_soc_tplg_vendor_array *)((u8 *)private->array= + sz); > + cl_elem =3D cl_array->value; > + sz =3D sz + le32_to_cpu(cl_array->size); > + tkn_count =3D 0; > + > + /* Module config blobs are not token tuples, stop here */ > + if (le32_to_cpu(cl_array->type) =3D=3D SND_SOC_AR_TPLG_MODULE_CFG_TYPE) > + break; > + > + while (tkn_count <=3D (le32_to_cpu(cl_array->num_elems) - 1)) { [Severity: Medium] Can a malformed topology vendor array hang or read out of bounds in audioreach_parse_cl_tokens() and audioreach_parse_control_link_tokens()? soc_tplg_dapm_widget_elems_load() only checks widget->priv.size against tplg->fw->size. A vendor array with cl_array->size =3D=3D 0 loops forever = here (unlike audioreach_get_module_priv_data() above it), and num_elems =3D=3D 0 underflows le32_to_cpu(cl_array->num_elems) - 1 to U32_MAX in both function= s, driving out-of-bounds reads past the firmware buffer. The walk also does not check that cl_array->size and num_elems fit within t= he remaining private->size, uses signed int sz which can overflow on a large cl_array->size, and never verifies that cl_array->type is a value-tuple type before indexing cl_array->value. > + if (le32_to_cpu(cl_elem->token) =3D=3D AR_TKN_U32_CONTROL_LINK_IID) { > + link_id =3D le32_to_cpu(cl_elem->value); > + link =3D audioreach_tplg_alloc_control_link(apm, sg, link_id, &found= ); > + /* Skip on error or already parsed control link data */ > + if (!IS_ERR(link) && !found) > + audioreach_parse_control_link_tokens(apm, link, cl_array); > + } [Severity: Medium] Should audioreach_parse_cl_tokens() propagate errors from audioreach_tplg_alloc_control_link() instead of returning void? Ignoring ERR_PTR returns such as -ENOMEM or -EINVAL (for link_id =3D=3D 0) = lets widget and topology loading succeed with missing control links, unlike audioreach_parse_sg_tokens() and audioreach_parse_cont_tokens(). [ ... ] > @@ -617,6 +742,8 @@ static int audioreach_widget_load_module_common(struc= t snd_soc_component *compon > if (IS_ERR(sg)) > return PTR_ERR(sg); > =20 > + audioreach_parse_cl_tokens(apm, sg, &tplg_w->priv); > + > cont =3D audioreach_parse_cont_tokens(apm, sg, &tplg_w->priv); > if (IS_ERR(cont)) > return PTR_ERR(cont); [Severity: Medium] Does an error after audioreach_parse_cl_tokens() leak the newly allocated control links and their apm->control_links_idr entries? If audioreach_parse_cont_tokens(), audioreach_parse_common_tokens(), or audioreach_get_module_priv_data() fails, this function returns before setti= ng dobj->private =3D mod. When topology loading unwinds, audioreach_widget_un= load() exits immediately on if (!mod) return 0 and never runs the sg->control_link_list cleanup, leaking both the control link memory and the IDR entries on the persistent q6apm instance across retries or reloads. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204113101.1141= 644-1-srinivas.kandagatla@oss.qualcomm.com?part=3D9