From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796220089; b=MWsNsH0I5T5ONyVnTyccGdqIHInQjKp+pCEnO5yjf/XEK6Jsz8ceboJXdDk1l2oqtqaP yMpRdmls1IGUJ7fZCgDeqNejzqa6r3vfeLvFLAb16D8vZ5pO8IZustCn2EAQIbbMLh05r g+dPvsJ5lPOnBgKKjWka1S/5wVMGhV5RgHEJnSZl6yz/9Jorj0BE9F+Sti6aEzdHyY0a7 2LJV371H5ZfdegwAqXKgtuBFQkgk3IY49Rxk1qv1sQQN/KxNlUtsdoBObvCE5Lv5ytkks 23WqpmNK41p+a4DrgCvId3EV2NMErHagxaOg6rYPosXMV+hcL8OV+ta/aIUHdKEGBVw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796220089; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=pmsz1M3ikMmg6y3DtHwoCY2+7/CK+3Jnn+M7/aOPLVo=; b=ps2tvFzaZ/35jtcP18EhWSmZdgx88Fk7UBmqzHGLnl/WnCSs10pY6tB84Xg0CkESaR+E uFWihUABpkl9kDs2Xb6V5Kpc1fu5ue4vCeqipm5NSenu1BRsAZhcEIEWnUueCU8Hnmudz 4RZtUP5PhIyKkq+RIOPYpvEu3Rs9JS4tNxqvuwsvzIVAyDddgoyi/20Hb0ol/uICf47Cb hb615e2DQOIqNKn2rvPN/oYfJgMOy8L3JGZm3snZ81tfeAd8BJhkdZ2Lv4CNAaKYEo0Mz NNVQqxYkAxjggmqPWL4ALFcU/ugf+DiXyHM3tDwDvD/1cwGj7NyWQ3UpQu5MyvG17ZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=k1+Bbx19; arc=none smtp.remote-ip=209.85.128.44 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 256A7606A334 for ; Wed, 2 Dec 2026 14:01:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 256A7606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=k1+Bbx19 Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4ba013938d7so122017255e9.2 for ; Wed, 02 Dec 2026 06:01:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796220087; x=1796824887; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=pmsz1M3ikMmg6y3DtHwoCY2+7/CK+3Jnn+M7/aOPLVo=; b=k1+Bbx19ccXMW4lFCtacEgcTZ2PP+7aXnOq1W10QB+O/bxfAQCmITqvn1LUixsWiZd 0eUJuOnDJTk0TYObdfqD61hGD4RU2WN5etv5MEvpbTYuic1piUmIPexMxztpxxY9qQm1 onOvU351wMlriiqs5KABeKDjy5bgjVWnM0ez1EXikGy19onIOcwLQTAmx8XngsSvNvul UPXv+yHPCVr+y1isE9NmqXC6ybwjmpoPpUJ8xxZSzi3El1vx0AImEC6khMhRVPaAHLLu XjX3SQsj+iwjXKw3CUrtjMTu4TJy6c4OpwdhTIP0jHCkPpJJ5QPqZjqF8zW2MSbN0NJC LyLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796220087; x=1796824887; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pmsz1M3ikMmg6y3DtHwoCY2+7/CK+3Jnn+M7/aOPLVo=; b=OgNMrfMGpS2wuq97cYLyQQuYuttd5WFg18i5LKZWYIq/0ie/j06gHF5FLSh3sXYxAo 18dn5YJQ+ylQNBQ+/E0azqHdgVXor3WsbdAjDcAC0OKSzJgbT225GhDfNN6aLcxT0Xkj s7Nf4yfeYc04Pt7y6gNNFAAyZFlqcqtWKy8Mw3zlbcFi0w/Pxs6yLofg5N9hlxOsPoAI gQH7ARbWw/minoO6MD0Cwkf2C25U4uSv767y+SIncUMeDaW4EeRX7fcTE26chjlJkktY mk13DnFV3jlZaMatizGbQh6pD0B+/ghyv3QKiURGlGC9ytwj3sC2njpj7ys6OusZEDz2 zwXQ== X-Forwarded-Encrypted: i=1; AL+hErFVZSZUIEGmjDETqM0y8qx4i4X4adZDbR4HIUs7Hbjlbr6suLF263vTkCpuXGB1kN1nPtTSoxGKnrO0Q34=@vger.kernel.org X-Gm-Message-State: APuU4Z+kcVe1u0gj/5qV7qp7bUCB0i1pZPagZy8lkkbcF6yNqideAbYk I2hu0VM0gR2N26R/iJy1K1DUzntAwjN0HupTLeQxF8XWYKNIxAOTEkQe X-Gm-Gg: AZFdTZcx4EIkKSXQ20fZp56G8BoAtxc9z2qKNiqJZIl8ZSUuc59QY7xFj2WIsneXiSb cV/Uq1x7rq+4L0ppbEO6APNi0ue8WbbDxijf00grCRs38MuQYrwjtyS/9zUayHKG6QuwnKcdG3+ eIg1KKLDrXuP8Hzd1qD0iV3A56g4DRsDlYSvHVcQa7Z0BjQ/QP77OkYX9nHBUhwjBNgd606WGtC SNufIo44SkWzCgV7Qp7HFSs218E4yhgYoCVa3EnTsbTBmCnlywfSwLPNn15DBtOQXVMvJ0uS1UD MSfsxUBNFSNSw4ORAOvr7EyBCOvmrl6qUiTxav/ZqcqtRm1WVT15MXnGfbIAa+w1JL8wI+M1GNr URuelfsCLs+KJrqaPcNKpUMUAYzKZEx60RyO41pgmNqLWUd3CraDxFzlNGgFZSYmstaJcWT55D7 /zcfouYwBv/NvyTBaeTAjzjhI0Ms4KCoLAoT6S+k0cMMrLdskzOV4pxzvX8oAHMK8g+RzmvMkTP 4POH5S2oXZBPfbAPYlF6GiPFC6BSuSUmceavpLDwwKQNWUSawMfrpZxhLuAa92Q4Wn1EsC64fyh prXupoej9W6mWzI1SuOPNp1ssMA3I8sBLeZMgXPOICpY3soj80cmD5G0AHUNAi5W X-Received: by 2002:a05:600c:4e4c:b0:4b6:5dac:b61e with SMTP id 5b1f17b1804b1-4bb88938d2dmr753377545e9.32.1796220087412; Wed, 02 Dec 2026 06:01:27 -0800 (PST) Received: from WIN-11-2.drag-and-code.local ([196.179.202.103]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbab390cf5sm678088995e9.7.2026.12.02.06.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 06:01:27 -0800 (PST) From: Ahmed Abdelmoemen To: tiwai@suse.com, perex@perex.cz Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Ahmed Abdelmoemen Subject: [PATCH 0/3] ALSA: pcm: Fix OSS mmap buffer-lifetime issues Date: Wed, 2 Dec 2026 14:01:14 +0000 Message-ID: <20261202140117.1164633-1-ahmedabdelmoumen05@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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