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=1796289787; b=kppRT6XomxDWEAnVfgQr8cNGbEotlcjGTo92YhcGC408myovWP6O/F8/Lkq1GuAZ7gun szm+ND/eqKZhzLwRgU0GIUC2JM7Cm7XAUSD9wdDQGLlS19t1eQ8+cVQ/+wMlAfxGO475R O5fg380LjnmOSB9zULGsVYsEb2xXc8lmhmnRb+sZsoczu2RT7XHewgP5OYMVnybvSKh7Q AxlAukD40BkmaciyeDmnUNvt1nquvyfIRiwN+vSvrtCyxJ7IAe4pvT0HFVF6ehH87RvW2 0Jj8Z3/FDZPdRYEv3z1xciIxt8Y9i9DYTZxwr6D/NtHGsf6TSNTAo4vQND0hOdwAbcQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796289787; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=VPiO0KQmEXwr28BfuEUZVij+KAC1Z8IYY1BAK+Za3Ro=; b=DhtEHMctQZYf/nLAkRiTrl9BYY76ZtmbAy15TRpfqTsvOg/QKSjre7Zj9EvZEsIs8QIr qVM09ssFs3X8AhABZ64++EHNkZrV14FySJPcgeS2NOSVowxM5WDlldFM0KfnJH27NfuUl zP5mJEhiNw2Y4YO4rG5QbSj4W3uqNrjF7yPFMxBFSet7lQYksx3SDXe5aJQKbopZ1IPp0 K9rkvy5u2wVVzxOU0wFYSxc0P24HJxgIycIobR81k0QjaL1I4HJ0stc082NIZ8nsj8xr7 iP0VawekFLTvC+kmPRKchQfGnOVADnD7a0FdAs3mwThUdEP38eqB5S655iPqlNkJ8ig== 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=hrGKfgh6; 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 D0D64606A32C for ; Thu, 3 Dec 2026 09:23:07 +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=hrGKfgh6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F18A1F00896; Thu, 3 Dec 2026 09:23:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796289787; bh=VPiO0KQmEXwr28BfuEUZVij+KAC1Z8IYY1BAK+Za3Ro=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=hrGKfgh6e1S6xUvaWOmEr0HInq0Szuvro3btU9CWxbNqSs/VHRWm9WEWQwKtibGgZ yufkojNaKOjhMaQ7wji/GA51K4D/NNrFtLaTeRmFGgYTNAA9p6A/4rKf/tnfZx32hZ IIfeuX+Nas+6h0ZtgQiUQmP318wy61EqKDldnYA48734m+1cw7mmdb25AqTjIrql4A 9epI6TZjgvg02gX8VQXtYP4ZOQJv459pgNmdljrb1mX7RfZY7dZtUv8lNYeuL87jgK C8zWZ/uWLQVByUqwX1/0SdsW5Hsl+2Lo6kVTE2C6epIaMSGqQoAeKSWJu72uDWBuYb UOKE461gmoz1w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 2/4] ALSA: pcm: Reject hw_params with buffer size changes while mmapped Reply-To: sashiko-reviews@lists.linux.dev To: "Takashi Iwai" , linux-sound@vger.kernel.org In-Reply-To: <20261203084041.914026-3-tiwai@suse.de> References: <20261203084041.914026-1-tiwai@suse.de> <20261203084041.914026-3-tiwai@suse.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 09:23:07 +0000 X-Mailing-List: linux-sound@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 1 potential issue to consider: - [Medium] ASoC: __soc_pcm_hw_params() runs hw_free rollback while PCM is mmapped -- commit 2730ca1aecc2de34e1b87564c9fe83017af5300d Author: Takashi Iwai ALSA: pcm: Reject hw_params with buffer size changes while mmapped This commit rejects snd_pcm_hw_params() calls with -EBADFD when a substream is mmapped and the requested buffer size differs from the current one, and skips managed buffer reallocation while mmapped. Link: https://lore.kernel.org/20261202140117.1164633-1-ahmedabdelmoumen05@g= mail.com > diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c > index 6d17be7f9beb8..7f0c47379c96e 100644 > --- a/sound/core/pcm_native.c > +++ b/sound/core/pcm_native.c [ ... ] > @@ -826,9 +827,18 @@ static int snd_pcm_hw_params(struct snd_pcm_substrea= m *substream, > if (err < 0) > goto _error; > =20 > - if (substream->managed_buffer_alloc) { > - err =3D snd_pcm_lib_malloc_pages(substream, > - params_buffer_bytes(params)); > + /* OSS still allows hw_params change during mmap -- except for the case > + * where the buffer size actually changes (that can go wrong with mmap). > + */ > + buffer_bytes =3D params_buffer_bytes(params); > + if (atomic_read(&substream->mmap_count)) { > + if (buffer_bytes !=3D frames_to_bytes(runtime, runtime->buffer_size)) { > + err =3D -EBADFD; > + goto _error; > + } > + runtime->buffer_changed =3D 0; > + } else if (substream->managed_buffer_alloc) { > + err =3D snd_pcm_lib_malloc_pages(substream, buffer_bytes); > if (err < 0) > goto _error; > runtime->buffer_changed =3D err > 0; [Severity: Medium] Can continuing to call substream->ops->hw_params() while mmapped leave ASoC driver state torn down while runtime->state stays in SNDRV_PCM_STATE_SETUP? When substream->mmap_count is non-zero and buffer_bytes is unchanged, snd_pcm_hw_params() still invokes substream->ops->hw_params(). On ASoC, if __soc_pcm_hw_params() fails (for example on an OSS SNDCTL_DSP_SPEED change), it unconditionally calls soc_pcm_hw_clean(rtd, substream, 1) without checking substream->mmap_count. Because the initial pre-mmap hw_params already marked the links, components, and DAIs, rollback executes their hw_free callbacks while the substream is still mmapped. Combined with commit "ALSA: pcm: Avoid forcibly changing to OPEN state at hw_params errors", the _error path in snd_pcm_hw_params() leaves runtime->state in SNDRV_PCM_STATE_SETUP when mmap_count is non-zero. A concurrent thread in snd_pcm_oss_make_ready() that passed the unlocked runtime->oss.params check can then prepare and start the stream after ASoC has already torn down its resources: CPU0 CPU1 snd_pcm_oss_make_ready() if (runtime->oss.params) /* false */ SNDCTL_DSP_SPEED (mmapped) snd_pcm_hw_params() __soc_pcm_hw_params() -> err soc_pcm_hw_clean(..., 1) __avs_dai_fe_hw_free() data->path =3D NULL /* mmap_count > 0: state stays * SNDRV_PCM_STATE_SETUP */ mutex_lock(&runtime->oss.params_lock) snd_pcm_oss_prepare() avs_dai_prepare() -> 0 (!data->path) SNDRV_PCM_IOCTL_START avs_path_pause(NULL) <-- NULL deref On Intel AVS this results in a kernel NULL pointer dereference in avs_path_pause() at path->owner; on drivers such as Samsung IDMA, rollback directly clears runtime->dma_area and runtime->dma_bytes via snd_pcm_set_runtime_buffer(substream, NULL), causing a racing prepare to program DMA with a zero transfer size. Should __soc_pcm_hw_params() skip soc_pcm_hw_clean() when substream->mmap_count is non-zero, or should driver hw_params callbacks be avoided while mmapped? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203084041.9140= 26-1-tiwai@suse.de?part=3D2