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=1796392235; b=dV1PZneherlrtTVcr62CnUkt8jGd7WjcAvnAOHsk7sZbA2TRvwBmNoptHpL1MXsejvo8 z1AiK4+VZb1BSBQN+wX5MIRvPJz1q9aktedOx5tPMHWq794j614dFhhoBvqa6F49YHwYm g5Y1Teu3rKoF8fK6F03MREzrdRT/VcBdDHVdiDqXHWir383Kw4axNP/eKmyEuFTsEmGJv NykeRzCvV1uknWSRwS4hOQw3Rwq/xzq81eaFb8xnOa1GfkK1wlOLdPP+v2Zpct7Qcozj5 V9Mpw3+IUOhvXa8zo7ynW6XVU5cFQsnmetj9zA17bGefa8SJAI/L+uPXhR2uWdvN1qw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796392235; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=qQX1CuPML0PZics9D7TodY3BqsSwkNAB2XzLUd9Es/w=; b=S9Yn+ep7Xnx2KRIdUAm9oVFEg5gfv9MUiPjqwobgSME6Cie3a2hihYLFGnNPH4fWwK5u hq8vcFMmeK2TH2VPa6g2dADj8euuegk17rihNcTnf76vrdoxoLI6PXrkZKJ/8WemAg0PB VY+4C+FuQq8xdn3B7QmAlzv4AaLLrLr47+5qRwx9Yj0pf97gRQ8bdpQLvlCwHUb81AUH5 Ut2Kxls/YFqBtbccL0fis1IrCvuDrrHO0GrNe+0sTB/a3Fp/6zBmECaeBqSDBwxNijjDt iKvqkqWKR6+wFPefVpJaPy0jFACX/TMrZq6QfMHGB7I5JRKG7fdLK0UUVdykDxNG28Q== 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=hEfuiwUu; 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 C2533606A688; Fri, 4 Dec 2026 13:50:35 +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=hEfuiwUu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AAE61F00939; Fri, 4 Dec 2026 13:50:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796392234; bh=qQX1CuPML0PZics9D7TodY3BqsSwkNAB2XzLUd9Es/w=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=hEfuiwUu1crwXL1HU12PyQ+LNS4exkErUlfo/EBZ7xI2m8JfXkhXCV7iDQ171ILk6 1CXNlb+H001UOPvj/j0i0xad6B7LO6CZJZA2ydeH0DrxPj5FrfJw0CySJi/3WUBJO8 An4+4kuMXRJ6x8pJX6HXHQFDGLINH63ZuxOW+94d7tFo6sNl/t6Rqsw10jrjPYCKUO 6l3IhOZ0Pqttnd6ZoZpjbPmnF190w9F/nau8BI/G3RHAFiUwEQNvDBj2xkbZBU+hdU QIWF1xsAI2Xt13/hsYdcvCa/FS9/8jlA0JKXYVZRq9XnJ+EZ26GK6UzkPAcRJ/9/6m Ul3sUH7XMv3XA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules 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-16-srinivas.kandagatla@oss.qualcomm.com> References: <20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com> <20261204113101.1141644-16-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 13:50:34 +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 6 potential issues to consider: - [High] ASoC: qcom: audioreach: sp_cal_watchdog never canceled on module unload - [Medium] ASoC: qcom: audioreach: OOB read in audioreach_speaker_protection_send_chunk() - [Medium] ASoC: qcom: audioreach: audioreach_sp_cfg_walk() rejects last sub-word param - [Medium] ASoC: qcom: audioreach: race in audioreach_sp_finish_calibration() - [Medium] ASoC: qcom: audioreach: audioreach_set_media_format() leaks VI cal state - [Low] ASoC: qcom: audioreach: raw cast drops __le32 in static cfg blob parser -- commit 8b5c2a066041593c52f189b47c51b9e22ea4e028 Author: Ravi Hothi ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules This commit parses and sends topology static configuration blobs to the speaker protection and VI sense modules in chunked APM_CMD_SET_CFG commands padded to 8-byte boundaries, falling back to sending non-record blobs whole. > diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/aud= ioreach.c > index 3555c97c2000d..fd803d6ceccd0 100644 > --- a/sound/soc/qcom/qdsp6/audioreach.c > +++ b/sound/soc/qcom/qdsp6/audioreach.c [ ... ] > +static int audioreach_sp_cfg_walk(const u32 *word, u32 num_words, u32 ii= d, > + u32 first, u32 *next, u8 *dst, u32 max_bytes) > +{ > + u32 pos =3D first, bytes =3D 0; > + > + while (pos < num_words) { > + u32 param_size, payload_words, avail, rec_bytes; > + > + if (word[pos] !=3D iid || num_words - pos < 4) > + return -EINVAL; > + > + param_size =3D word[pos + 2]; > + avail =3D (num_words - pos - 4) * sizeof(u32); > + if (param_size < sizeof(u32) && avail && word[pos + 4] =3D=3D iid) { > + payload_words =3D 0; > + } else { > + if (param_size > avail) > + return -EINVAL; > + payload_words =3D DIV_ROUND_UP(param_size, sizeof(u32)); > + } [Severity: Medium] Can a valid blob end with a sub-word parameter that omits its payload word? When such a record is last in the blob (num_words - pos =3D=3D 4), avail is= 0, so the if condition evaluates to false and the else branch returns -EINVAL instead of setting payload_words to 0. Checking (!avail || word[pos + 4] = =3D=3D iid) handles the final record while still guarding word[pos + 4]. [ ... ] > +static int audioreach_speaker_protection_send_static_cfg(struct q6apm_gr= aph *graph, > + const struct audioreach_module *module, > + const char *tag) > +{ > + u32 size, num_words, pos =3D 0; > + const u32 *word; > + int total, rc =3D 0, chunk =3D 0; > + > + if (!module->data || !module->data->size) > + return 0; > + > + size =3D le32_to_cpu(module->data->size); > + word =3D (const u32 *)module->data->data; > + num_words =3D size / sizeof(u32); [Severity: Low] Does this cast drop the __le32 annotation on module->data->data? struct audioreach_module_priv_data declares data[] as __le32, so casting it to const u32 * triggers sparse warnings and reads header words (word[0], word[pos], word[pos + 2], and word[pos + 4]) in host byte order without le32_to_cpu(). On big-endian builds, valid parameter-record blobs either fall back to unchunked sends or fail with -EINVAL. Keeping word as const __le32 * and using le32_to_cpu() when inspecting header fields avoids both. > + /* Not laid out as parameter records, so send it as the topology built = it */ > + if (size % sizeof(u32) || !num_words || word[0] !=3D module->instance_i= d) > + return audioreach_speaker_protection_send_chunk(graph, tag, word, size= , 0); [Severity: Medium] Can this read past the end of module->data when size is not a multiple of 4? audioreach_get_module_priv_data() truncates array_size down to whole __le32 words when allocating and copying pdata->data[], while leaving the unrounded byte count in pdata->size: sound/soc/qcom/qdsp6/topology.c:audioreach_get_module_priv_data() { ... nwords =3D array_size / sizeof(__le32); ... pdata =3D kzalloc_flex(*pdata, data, nwords); if (!pdata) return ERR_PTR(-ENOMEM); memcpy(pdata, ((u8 *)private->data + sz), struct_size(pdata, data, nwords)); ... } Passing the unrounded size to audioreach_speaker_protection_send_chunk() causes memcpy() to read 1 to 3 bytes past the end of the slab object, triggering a KASAN slab-out-of-bounds report and sending adjacent heap bytes to the DSP. [ ... ] > @@ -1989,6 +2126,8 @@ int audioreach_set_media_format(struct q6apm_graph = *graph, > case MODULE_ID_SPEAKER_PROTECTION_VI: > rc =3D audioreach_speaker_protection_vi(graph, module, cfg, > READ_ONCE(sp_operation_mode)); > + if (!rc) > + rc =3D audioreach_speaker_protection_vi_static_cfg(graph, module); > if (!rc) > rc =3D audioreach_module_enable(graph, module, true); [Severity: Medium] If audioreach_speaker_protection_vi_static_cfg() fails during calibration mode, does this leak the armed calibration state? audioreach_speaker_protection_vi() has already called audioreach_arm_vi_calibration() and registered DSP events before returning = 0. Returning on a static cfg error leaves sp_operation_mode stuck in PARAM_ID_SP_VI_OP_MODE_CALIBRATION for up to 60 seconds (causing calibration retries to fail with -EBUSY and configuring subsequent normal streams into calibration mode) and leaves sp_vi_r0.armed set. Even with the later graph-close abort path in the series, audioreach_vi_calibration_abort() returns early when sp_vi_r0.seen_states is all zeros, which is always true when prepare fails before the module is enabled. Unwinding calibration state on failure here (or sending the static cfg blob before arming calibration) would avoid the leak. As a minor side effect in normal mode, audioreach_speaker_protection_vi() also logs "SP active in Normal mode" before the static cfg blob is validated or the module is enabled. [Severity: High] In the surrounding speaker protection calibration state from commit "ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode", is sp_cal_watchdog ever canceled on module unload? audioreach_trigger_sp_calibration() schedules the 60-second delayed work sp_cal_watchdog without pinning snd-q6apm, while audioreach_sp_shutdown() and its call from apm_remove() were dropped (leaving only the declaration in audioreach.h). Unloading snd-q6apm while the watchdog is pending or running causes a use-after-free when the timer fires into freed module text and data. Restoring cancel_delayed_work_sync(&sp_cal_watchdog) on removal after unregistering controls prevents this. [Severity: Medium] Also in commit "ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode", can audioreach_sp_finish_calibration() race with a new calibration trigger or an in-flight watchdog callback? audioreach_sp_finish_calibration() clears sp_operation_mode before calling non-synchronous cancel_delayed_work(&sp_cal_watchdog): CPU0 CPU1 audioreach_sp_finish_calibration() WRITE_ONCE(sp_operation_mode, NORMAL) audioreach_trigger_sp_calibration() cmpxchg(..., NORMAL, CALIBRATION) schedule_delayed_work(...) cancel_delayed_work(...) <-- cancels CPU1's watchdog This leaves the new run stuck in PARAM_ID_SP_VI_OP_MODE_CALIBRATION indefinitely if no playback completes. Because cancel_delayed_work() does not wait for an executing callback, a stale audioreach_sp_cal_watchdog_fn() can also run its cmpxchg after a new calibration starts and abort it back to Normal mode. Canceling the work synchronously before clearing sp_operation_mode closes both races, provided sp_vi_r0_lock is not held across cancel_delayed_work_sync() if the callback ever acquires it. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204113101.1141= 644-1-srinivas.kandagatla@oss.qualcomm.com?part=3D15