mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>,
	stable@vger.kernel.org
Subject: [PATCH 3/3] ALSA: pcm: Clear mmap tail padding to avoid info leak
Date: Wed,  2 Dec 2026 14:01:17 +0000	[thread overview]
Message-ID: <20261202140117.1164633-4-ahmedabdelmoumen05@gmail.com> (raw)
In-Reply-To: <20261202140117.1164633-1-ahmedabdelmoumen05@gmail.com>

snd_pcm_mmap_data() validates the request against
PAGE_ALIGN(runtime->dma_bytes), so when the logical buffer is smaller
than a page (e.g. 512 bytes via OSS SETFRAGMENT) userspace may map the
whole page. The tail padding is backed by the same page and may hold
data from prior use of the buffer. hw_params zeroes
PAGE_ALIGN(dma_bytes) for MMAP-capable streams, but a stream mapped
through the OSS path can be exposed without that memset having run.

Zero the padding in the mmap path, immediately before the mapping is
established, so bytes beyond the logical buffer are always zero.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Ahmed Abdelmoemen <ahmedabdelmoumen05@gmail.com>
---
 sound/core/pcm_native.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index f8d9d145b..605e596db 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -4136,6 +4136,12 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
 		return -EINVAL;
 	if (offset > dma_bytes - size)
 		return -EINVAL;
+	/* Zero the page tail beyond the logical buffer so the mapping
+	 * cannot expose stale contents (DMA buffers are page-granular).
+	 */
+	if (runtime->dma_area && runtime->dma_bytes < dma_bytes)
+		memset(runtime->dma_area + runtime->dma_bytes, 0,
+		       dma_bytes - runtime->dma_bytes);
 
 	area->vm_ops = &snd_pcm_vm_ops_data;
 	area->vm_private_data = substream;
-- 
2.43.0


      parent 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 [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:01 ` [PATCH 2/3] ALSA: pcm: Check mmap_count before freeing buffer in error path Ahmed Abdelmoemen
2026-12-02 14:01 ` Ahmed Abdelmoemen [this message]

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-4-ahmedabdelmoumen05@gmail.com \
    --to=ahmedabdelmoumen05@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=stable@vger.kernel.org \
    --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®