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=1796221292; b=HswGT2pkPqHFaabzLgMnQDiendgvz2bnJqHFyWudwH+LFLIwLfWXolSTNyFqNIWIw5do M0FMhXQD9A/gcmDZEpad5xIcn+Gxn2ObitiGM80Bmj15C6bisYLtMimxuAsPQ7Z4vJ+GM mOWw4BCYXyq/49GuHznjdFPtLtaOHbSXYMniTDWnu35IHpIPFo8elnWFtMa0/KYOt6PDn diQX9jitTAyYKH/cQFSNCGSowbnXizBzRnO3fnZYJZidmXbAKVsxtsZunT377jExckYWl PFfGcGJ+NiRUYuMLn5QP7Bph32Gqtp2NGK0YAEVUl+Ix6IVLYfm+Igp0M8SQMFTKaYw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221292; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=tN81iRo8jMjMSoMRQlEep99zF82NfVVCXuK8viPAUrg=; b=QTDVHC0SBlWp3wYBWIeM1OPpA3Ek5xLRUW8V3rwj4iOHOAMe+xC09YnbNs+5RFLIDAJz +X4o1LkitLGIxZrB/0c7k1/vbIKA0GIB5DlfKXXeqo6Rcwh2scVFCIgmALrwib9tJ+ey/ MlshjKHl5pPsBVO9UdVoaEp8dLPzT2XfFPxVtfwjWrgUqTGolIWlLcrn8GKO/zTe70gDc 2yvieIQMmsAVGAZh9AuIPv5B7T+FJFh4dx3oeLHVYqYOGfG/ZoE43DlmJ1LK0U9YgDFjx niOTYIttNqnOPnnbDpBLzNtKZm2INZ4IdjLKbvm88Om/HT2sx56T+VB5HUkMQg1TX6Q== 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=POF9Y866; 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 54CBA606A31A for ; Wed, 2 Dec 2026 14:21:32 +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=POF9Y866 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E75C1F00896; Wed, 2 Dec 2026 14:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796221292; bh=tN81iRo8jMjMSoMRQlEep99zF82NfVVCXuK8viPAUrg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=POF9Y866mYrPlGtudiBZXyOAilZvmkK7tyfsijirZQcrsfUaC1MYN5hZeSuwtjdI9 tASe/px9gak5aCF0IzqQmF6rpNKAAfjrzCs19xqCG5IrJGgx8Vx9l/jfZ05oQWALyx bwn2qYStZnNSrzo8KlI7DQkwpSESW6PGjHN5eF/gYRRFNl+xh2w5ha9HlJ16J+fr6N rCazKguY9Vc1SzIFhDTfajZd6J+kW/TZh1wLMyAi4ubnHI87GPZkBAEorXoHqrCjN0 1MFkglzUV7/RkeA12+H6jcTQe+9p6Bmw1XEDiT5Dtz4sq5S9Dw3U5A44Gbt+oJIAB2 35hk9kpLw+RIw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/3] ALSA: pcm: Remove is_oss_stream() bypass of mmap_count check Reply-To: sashiko-reviews@lists.linux.dev To: "Ahmed Abdelmoemen" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261202140117.1164633-2-ahmedabdelmoumen05@gmail.com> References: <20261202140117.1164633-1-ahmedabdelmoumen05@gmail.com> <20261202140117.1164633-2-ahmedabdelmoumen05@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 14:21:31 +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 2 potential issues to consider: - [High] ALSA: pcm: removing is_oss_stream() in hw_params_state_check() wedges OSS mmap - [Low] ALSA: pcm: Fixes trailer in commit message cites refactoring commit 92ee3c60ec9f -- commit 421134d72db5ebc0315596afb99aa7522ec2fe0d Author: Ahmed Abdelmoemen > ALSA: pcm: Remove is_oss_stream() bypass of mmap_count check > > hw_params_state_check() skips the mmap_count guard for OSS streams via > the is_oss_stream() condition. This lets hw_params run while userspace > holds a live VM_PFNMAP mapping obtained through /dev/dsp. > > remap_pfn_range() mappings (VM_PFNMAP) carry no page reference counts, > so the kernel cannot revoke them when hw_params reconfigures or > reallocates the DMA buffer. The buffer can be cleared or freed while > userspace retains read/write access to it. > > Removing the bypass restores the intended safety invariant: an OSS > caller holding a mapping gets -EBADFD on reconfiguration, the same as a > native PCM stream. Reconfiguring the buffer under an active mapping is > never safe regardless of stream type. > > Fixes: 92ee3c60ec9f ("ALSA: pcm: Fix races among concurrent hw_params and= hw_free calls") > Cc: stable@vger.kernel.org > Signed-off-by: Ahmed Abdelmoemen [Severity: Low] Does the Fixes: tag point to the commit that introduced this bypass? 92ee3c60ec9f ("ALSA: pcm: Fix races among concurrent hw_params and hw_free calls") only wrapped the existing !substream->oss.oss check in is_oss_stream() and moved it inside the stream lock, whereas the check itself dates back to 1da177e4c3f4 ("Linux-2.6.12-rc2"). > diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c > index 897975e43a9bd..d77045aba17b6 100644 > --- a/sound/core/pcm_native.c > +++ b/sound/core/pcm_native.c > @@ -784,8 +784,7 @@ static int hw_params_state_check(struct snd_pcm_subst= ream *substream, > case SNDRV_PCM_STATE_OPEN: > case SNDRV_PCM_STATE_SETUP: > case SNDRV_PCM_STATE_PREPARED: > - if (check_mmap && !is_oss_stream(substream) && > - atomic_read(&substream->mmap_count)) > + if (check_mmap && atomic_read(&substream->mmap_count)) > return -EBADFD; > return 0; > default: [Severity: High] Does removing !is_oss_stream(substream) here break OSS parameter reconfiguration after mmap() and wedge the OSS substream? The OSS emulation layer supports changing parameters while /dev/dsp is mapped: snd_pcm_oss_period_size() clamps oss_buffer_size to runtime->oss.mmap_bytes, and snd_pcm_oss_change_params_locked() forces direct mode and SNDRV_PCM_ACCESS_MMAP_INTERLEAVED when substream->mmap_count is non-zero before invoking SNDRV_PCM_IOCTL_HW_PARAMS: sound/core/oss/pcm_oss.c:snd_pcm_oss_change_params_locked() { ... if (atomic_read(&substream->mmap_count)) direct =3D 1; else direct =3D substream->oss.setup.direct; _snd_pcm_hw_params_any(sparams); _snd_pcm_hw_param_setinteger(sparams, SNDRV_PCM_HW_PARAM_PERIODS); _snd_pcm_hw_param_min(sparams, SNDRV_PCM_HW_PARAM_PERIODS, 2, 0); snd_mask_none(&mask); if (atomic_read(&substream->mmap_count)) snd_mask_set(&mask, SNDRV_PCM_ACCESS_MMAP_INTERLEAVED); ... snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL); err =3D snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_HW_PARAMS, sparams= ); if (err < 0) { pcm_dbg(substream->pcm, "HW_PARAMS failed: %i\n", err); goto failure; } ... failure: if (err) { runtime->oss.params =3D 1; snd_pcm_oss_release_buffers(substream); } ... } Because the OSS parameter setters (such as snd_pcm_oss_set_rate() or snd_pcm_oss_set_fragment1()) update runtime->oss and set runtime->oss.params =3D 1 without checking mmap_count, rejecting SNDRV_PCM_IOCTL_HW_PARAMS with -EBADFD sends snd_pcm_oss_change_params_locked() to the failure path after dropping the stream. That frees the OSS buffers and leaves runtime->oss.params set to 1 while mmap_count > 0, so every subsequent OSS ioctl that calls snd_pcm_oss_make_ready() or snd_pcm_oss_get_active_substream() re-enters snd_pcm_oss_change_params_locked() and fails with -EBADFD. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202140117.1164= 633-1-ahmedabdelmoumen05@gmail.com?part=3D1