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=1796385080; b=ZnojTsQ1iZ7E+ZsoT12615rTgCEfObFcu6ZC9acHbaEFbKh9hI8mskp9kDCAZGhZoYc6 T1Ymv3MITjeIHj//M889eSoKyNH2Z0endCZcdhPPi9AO/5qmrmKIvvr1eGbbUQKPD4o8V VSdzcuBOBz0nJEblUNyuCwBr9hqCkSC9436OHJtQXxml36byKA/xGETN/GGE3Y9/Rkx3E M5z/HGYn+/6Bx1A/9d/UoZ3Kzac2jt1NK1UcrnrBm3ldZt5O0nOX78L7tHaQdZHS7TpFI CIeN2fcnjAbn1cziXMyPUCTNetpX+GXwYWuMC71cJ4ukHuCWn+ereDq/HN4NLcFdAFA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385080; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=r0YRiYQXFAYbMfkOr41QOLToOzanYWr5feBSdGdoJHs=; b=wdu1uUhHgXzU4fr42PKnopGkEB0THnmH0qdcvczXF54z9kFW3Z5j/91LCqMlLosYDnPJ n2fP/g7Ua2ykVIHJ+oKw86WEy3pW+MAxysq2+Ow4ldsVEcErKTjmWnStD//i6eLH9FWWH aO4w7t1Y+EUuujseW1GL9K7aZV51HI3v+v1osyMeHdYXZSbFSIGbCcPmLefp4u+DgPd7d QCSh1OfYrY2jyB+3erVAC87fabo0wIjIVX6R7zkz8rwZyoH6mQ9f/bu+xD6J6qoQtb7xV 5rBbzP6u6DAaIZCPeaviz6OWVW4gmFfSXDi/6egoC+rfB3ggxwHVl3o3v0+GFO9pRPg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=KjaX0uwo; 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 C069D606A339; Fri, 4 Dec 2026 11:51:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=KjaX0uwo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 387B01F000C2; Fri, 4 Dec 2026 11:51:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385080; bh=r0YRiYQXFAYbMfkOr41QOLToOzanYWr5feBSdGdoJHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KjaX0uwobbJH6enfX1KptJigXxGMSsJvGwWxspK0LAfwOvAxDgHnv7Euj5T/nWZ3x B/LQH0WPBjfLuUztiaZLiwhRu6Bs6hwAf0OVsWtKqPewrC8DbZ4C4UZKIS7fyQWCdd RvrYq7JYnXT+OpgD4xJKnWFR2j7G3C5ZmGSpzu5U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Takashi Iwai , Sasha Levin Subject: [PATCH 6.6 0409/1167] ALSA: pcm: Protect delay DMA sync in forward and rewind, too Date: Fri, 4 Dec 2026 18:57:16 +0900 Message-ID: <20261204100712.677317927@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai [ Upstream commit d5096bb9beacb448091c1c9541432021dd5c1fcd ] Like the previous fix for snd_pcm_delay() (in the commit 50f413b83b31 "ALSA: pcm: Protect delay DMA sync against concurrent HW_FREE"), the snd_pcm_dma_buffer_sync() call in snd_pcm_forward() and snd_pcm_rewind() needs the similar protection against the concurrent hw_free action for avoiding potential UAFs. Fixes: a25684a95646 ("ALSA: memalloc: Support for non-contiguous page allocation") Reported-by: Sashiko Link: https://patch.msgid.link/20261013120528.52586-4-tiwai@suse.de Signed-off-by: Takashi Iwai [ sashal: Kept the existing explicit snd_pcm_stream_lock_irq()/unlock_irq() calls instead of upstream's scoped_guard form, adding the buffer_accessing check and atomic_dec() around them. ] Signed-off-by: Sasha Levin --- sound/core/pcm_native.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 0d0f5af95faa8..2a3e17fb208d1 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -3058,11 +3058,15 @@ static snd_pcm_sframes_t rewind_appl_ptr(struct snd_pcm_substream *substream, static snd_pcm_sframes_t snd_pcm_rewind(struct snd_pcm_substream *substream, snd_pcm_uframes_t frames) { + struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_sframes_t ret; if (frames == 0) return 0; + /* Keep the DMA buffer alive through the sync below. */ + if (!atomic_inc_unless_negative(&runtime->buffer_accessing)) + return -EBUSY; snd_pcm_stream_lock_irq(substream); ret = do_pcm_hwsync(substream); if (!ret) @@ -3071,17 +3075,22 @@ static snd_pcm_sframes_t snd_pcm_rewind(struct snd_pcm_substream *substream, snd_pcm_stream_unlock_irq(substream); if (ret >= 0) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); + atomic_dec(&runtime->buffer_accessing); return ret; } static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream, snd_pcm_uframes_t frames) { + struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_sframes_t ret; if (frames == 0) return 0; + /* Keep the DMA buffer alive through the sync below. */ + if (!atomic_inc_unless_negative(&runtime->buffer_accessing)) + return -EBUSY; snd_pcm_stream_lock_irq(substream); ret = do_pcm_hwsync(substream); if (!ret) @@ -3090,6 +3099,7 @@ static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream, snd_pcm_stream_unlock_irq(substream); if (ret >= 0) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); + atomic_dec(&runtime->buffer_accessing); return ret; } -- 2.53.0