From: sashiko-bot@kernel.org
To: "Ahmed Abdelmoemen" <ahmedabdelmoumen05@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH 1/3] ALSA: pcm: Remove is_oss_stream() bypass of mmap_count check
Date: Wed, 02 Dec 2026 14:21:31 +0000 [thread overview]
Message-ID: <sashiko-outbox-245949@kernel.org> (raw)
In-Reply-To: <20261202140117.1164633-2-ahmedabdelmoumen05@gmail.com>
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 <ahmedabdelmoumen05@gmail.com>
> 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 <ahmedabdelmoumen05@gmail.com>
[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_substream *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 = 1;
else
direct = 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 = 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 = 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 = 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202140117.1164633-1-ahmedabdelmoumen05@gmail.com?part=1
next prev parent reply other threads:[~2026-12-02 14:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 14:01 [PATCH 0/3] ALSA: pcm: Fix OSS mmap buffer-lifetime issues Ahmed Abdelmoemen
2026-12-02 14:01 ` [PATCH 1/3] ALSA: pcm: Remove is_oss_stream() bypass of mmap_count check Ahmed Abdelmoemen
2026-12-02 14:20 ` Takashi Iwai
2026-12-02 14:21 ` sashiko-bot [this message]
2026-12-02 14:01 ` [PATCH 2/3] ALSA: pcm: Check mmap_count before freeing buffer in error path Ahmed Abdelmoemen
2026-12-02 14:16 ` sashiko-bot
2026-12-02 14:01 ` [PATCH 3/3] ALSA: pcm: Clear mmap tail padding to avoid info leak Ahmed Abdelmoemen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-245949@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ahmedabdelmoumen05@gmail.com \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.