From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C391D5519A9; Wed, 9 Sep 2026 13:53:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788962040; cv=none; b=lughPt0URCeI7RwZOuRGICovUoBpg4cqq/D0NjFn1RguBov8x6JVSsox7M5c4QdbikNALe17EzsQgF2EUCQuNc8mcoyRB3PtMx1TCgHXYZT6UDG6N18sizD8zJqN9NqY6fayvjdVprQbdu0Bz++n0MAZBLwTfenXRSZBVe0uU+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788962040; c=relaxed/simple; bh=JNMqyCmQ0AU3o3Z6s4NqAMZt2UgxYqaN+ChpFUWzD1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nfWhAkjjWSzR/sxbGldXIbfvBko1579iJa/+z9mPyBthiYO5VWiQs/NRcCeAR+kruquW/56x/ecDuPBDQTW/Y5A0x4ZX8HrWwZaEW5h+P07a19VMCIaTtQnmNDUCHSoA9ec+1WFdpRas6yCZmQQqWVTRk69m6uAIJoPFR87sEPw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=N67oLhtD; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="N67oLhtD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2790D1F00A3A; Wed, 9 Sep 2026 13:53:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788962038; bh=VSwuP1wuXGmjSqky6aCtxEMOGkRdWTm3jjyu6Kma+0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=N67oLhtDXDgdBjCEO/sGFTreIdf8BOht9NDZXdzKn1LBdx0kQhdgt/VLO2T0x8xc0 vxGwQuRutNrYAcbJh6gHr4OdmBTGJ/FhKKgC6azG5xe6p9QFO0ZqjpqoNs55W+AKk/ 7GUT9mw2WTM2UXZYUxhdSZA4ereYEW+nCSowJqws= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+225231fce6755d40d078@syzkaller.appspotmail.com, Takashi Iwai Subject: [PATCH 7.2 151/556] ALSA: pcm: Fix race between non-atomic ops and trigger-start Date: Wed, 9 Sep 2026 15:37:11 +0200 Message-ID: <20260909134235.750025156@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134230.441546314@linuxfoundation.org> References: <20260909134230.441546314@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit acac7b5e07349a9d10d78873afb4b93cd1dc721f upstream. We protect the races of the concurrent state transitions between atomic PCM ops, but the checks between the non-atomic ops (hw_params, hw_free and prepare) and the atomic ops aren't perfect; there is a check of the conflicting PCM state at the beginning of hw_params & co, but the atomic PCM ops can be still issued during the non-atomic PCM operations. An example such scenario is that a thread A re-issues the PREPARE or HW_PARAMS for the already prepared stream, while another thread B triggers the PCM start in the middle of the prepare operation. Although this usually doesn't lead to much serious issues, it can give some inconsistency as reported by syzkaller (such as ODEBUG warning). There are various atomic PCM ops, and basically the only problem is the PCM start as it operates from the PREPARED state. Other trigger commands (stop, etc) are for the running or the other special state, hence they are filtered as pre-condition. This patch is for preventing the PCM trigger-start during the non- atomic operations in order to address the problems above. Fortunately, the hw_params, hw_free and prepare operations call snd_pcm_buffer_access_lock(), and this can be used for checking the concurrent operations at the PCM trigger -- which sets the runtime->buffer_accessing to a negative (if possible), so the PCM trigger just needs to check the runtime->buffer_accessing value; if it's negative, it means the concurrent non-atomic PCM ops is running. Reported-by: syzbot+225231fce6755d40d078@syzkaller.appspotmail.com Closes: https://lore.kernel.org/6a8f0de8.1d9ded08.62e62.00b5.GAE@google.com Cc: Link: https://patch.msgid.link/20260828115542.3999-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/pcm_native.c | 2 ++ 1 file changed, 2 insertions(+) --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1468,6 +1468,8 @@ static int snd_pcm_pre_start(struct snd_ struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->state != SNDRV_PCM_STATE_PREPARED) return -EBADFD; + if (atomic_read(&runtime->buffer_accessing) < 0) + return -EBADFD; /* during hw_params, hw_free or prepare */ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && !snd_pcm_playback_data(substream)) return -EPIPE;