From: Ahmed Abdelmoemen <ahmedabdelmoumen05@gmail.com>
To: tiwai@suse.com, perex@perex.cz
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
Ahmed Abdelmoemen <ahmedabdelmoumen05@gmail.com>
Subject: [PATCH 0/3] ALSA: pcm: Fix OSS mmap buffer-lifetime issues
Date: Wed, 2 Dec 2026 14:01:14 +0000 [thread overview]
Message-ID: <20261202140117.1164633-1-ahmedabdelmoumen05@gmail.com> (raw)
These three patches fix memory-safety issues in the ALSA PCM OSS
compatibility path (sound/core/pcm_native.c, CONFIG_SND_PCM_OSS=y).
I reported them earlier; as Greg noted that went to a public list, so
here are the patches.
Common root cause: the DMA buffer is mapped to userspace with
remap_pfn_range() (VM_PFNMAP), which carries no page refcount. The
kernel therefore cannot revoke the mapping when the buffer is cleared,
reallocated, or freed. Each patch removes one way to reach that state.
Patch 1 - hw_params_state_check() skips the mmap_count guard for OSS
streams via is_oss_stream(). That lets hw_params reconfigure (clear or
reallocate) the buffer while userspace still holds a live mapping.
Removing the exception makes the guard apply to all stream types.
Patch 2 - the hw_params error path frees a managed buffer without
checking mmap_count. With preallocate_dma=0 the pages go back to the
allocator while a VM_PFNMAP mapping may still reference them - a
use-after-free. The free is guarded directly, so it holds even
independent of patch 1.
Patch 3 - snd_pcm_mmap_data() allows mapping PAGE_ALIGN(dma_bytes); when
the logical buffer is sub-page (e.g. 512 bytes via OSS SETFRAGMENT) the
page tail can be exposed with stale contents. The tail is now zeroed
before the mapping is established.
Reproduction: on an unprivileged /dev/dsp with preallocate_dma=0, a
mapping that outlives the buffer free (patches 1+2) can be used to read
and write pages after they are reallocated to other kernel objects. PoC
and a QEMU harness (x86-64, intel8x0/AC97, kernel 6.8.12):
https://github.com/bohmiiidd/linux-UAF
The code paths are present in current mainline. Built and checkpatch-
clean against 7.4.0-rc with CONFIG_SND_PCM_OSS=m.
Feedback welcome - happy to respin.
Ahmed Abdelmoemen (3):
ALSA: pcm: Remove is_oss_stream() bypass of mmap_count check
ALSA: pcm: Check mmap_count before freeing buffer in error path
ALSA: pcm: Clear mmap tail padding to avoid info leak
sound/core/pcm_native.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
--
2.43.0
next reply other threads:[~2026-12-02 14:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 14:01 Ahmed Abdelmoemen [this message]
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:01 ` [PATCH 2/3] ALSA: pcm: Check mmap_count before freeing buffer in error path Ahmed Abdelmoemen
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=20261202140117.1164633-1-ahmedabdelmoumen05@gmail.com \
--to=ahmedabdelmoumen05@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®