From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2D1A830C629 for ; Wed, 13 May 2026 14:10:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778681429; cv=none; b=DuqchQ6VW8s6oXHGmmgZsB3nLVFUyIjQZglP4tL/X3xL22tUZr5+d9P+lwkEx9SSMgDAf4c4GWnrQQYMJAq4QmIB0+yYLbfuQPOaHoKPv1BNnrIam+AvmJ9ID5oxgmij8BK8Tvea1XeOi14ZVS4SQqfPsDiIsniATfUvc/BubrQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778681429; c=relaxed/simple; bh=8DN6coJTPUxuqrpo4XenHfxMg55z27zILPTOyVh/F3I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WwEqbfy/dPbRN8HGfBuN5jHzRCxscmfPCH0kHI9qaaoYWti987skEqA0RMDaboIVzG1x+Z6U7d1Qo2uONr2c+Pj1EncPAodeqlZybscJQ0/bYlUZv68xudD8xD1ZdqEeR0vqgqqW/pAlg4MaDM+qb4UeuNA6mew1E9Zdp6WF3Cg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D3jqh7Zc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D3jqh7Zc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F98AC2BCB3; Wed, 13 May 2026 14:10:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778681428; bh=8DN6coJTPUxuqrpo4XenHfxMg55z27zILPTOyVh/F3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D3jqh7Zc++5f4/3qmwlGR56wYzrI4N5OGdi5uV/VLTu6/MvmN8Djl/mTv6uNqwFws 0FTBbARMbc8DexYx1OOZ1cgctdoFkHXRLmuiy93XHkBynXf+cRiH3t+cld8A6+NW39 pPeGnmclWdyVaxBvWtRc5DxA67iTDFqjUtWfwMLbEzxtih33nW0PkY66I75Q+Ctbq+ 39PQTy5HwBTIzyi5IzdLNtCmLMOzs0jsM1JO3C9ruhY1lryFCuuFjcXkCTAI/sJd6T Yg6Vt5YtnMuVJsIhoNTGIuZYM+pTIkd6FJBRG1xd8LuUO+izKoSjmVwSxqIuObxteT +eBnVQU7SHwwg== From: Sasha Levin To: stable@vger.kernel.org Cc: Takashi Iwai , Jake Lamberson , Sasha Levin Subject: [PATCH 6.6.y 2/3] ALSA: core: Fix potential data race at fasync handling Date: Wed, 13 May 2026 10:10:24 -0400 Message-ID: <20260513141025.3748103-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260513141025.3748103-1-sashal@kernel.org> References: <2026051250-tattered-mulled-92f0@gregkh> <20260513141025.3748103-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Takashi Iwai [ Upstream commit 8146cd333d235ed32d48bb803fdf743472d7c783 ] In snd_fasync_work_fn(), which is the offload work for traversing and processing the pending fasync list, the call of kill_fasync() is done outside the snd_fasync_lock for avoiding deadlocks. The problem is that its the references of fasync->on, fasync->signal and fasync->poll are done there also outside the lock. Since these may be modified by snd_kill_fasync() call concurrently from other process, inconsistent values might be passed to kill_fasync(). Although there shouldn't be critical UAF, it's still better to be addressed. This patch moves the kill_fasync() argument evaluations inside the snd_fasync_lock for avoiding the data races above. The handling in fasync->on flag is optimized in the loop to skip directly. Also, for more clarity, snd_fasync_free() takes the lock and unlink the pending entry more directly instead of clearing fasync->on flag. Reported-by: Jake Lamberson Fixes: ef34a0ae7a26 ("ALSA: core: Add async signal helpers") Cc: Link: https://patch.msgid.link/20260420061721.3253644-1-tiwai@suse.de Signed-off-by: Takashi Iwai Stable-dep-of: 5337213381df ("ALSA: core: Serialize deferred fasync state checks") Signed-off-by: Sasha Levin --- sound/core/misc.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sound/core/misc.c b/sound/core/misc.c index a6dd4d38a46b3..918d59a541c82 100644 --- a/sound/core/misc.c +++ b/sound/core/misc.c @@ -171,14 +171,18 @@ static LIST_HEAD(snd_fasync_list); static void snd_fasync_work_fn(struct work_struct *work) { struct snd_fasync *fasync; + int signal, poll; spin_lock_irq(&snd_fasync_lock); while (!list_empty(&snd_fasync_list)) { fasync = list_first_entry(&snd_fasync_list, struct snd_fasync, list); list_del_init(&fasync->list); + if (!fasync->on) + continue; + signal = fasync->signal; + poll = fasync->poll; spin_unlock_irq(&snd_fasync_lock); - if (fasync->on) - kill_fasync(&fasync->fasync, fasync->signal, fasync->poll); + kill_fasync(&fasync->fasync, signal, poll); spin_lock_irq(&snd_fasync_lock); } spin_unlock_irq(&snd_fasync_lock); @@ -229,7 +233,10 @@ void snd_fasync_free(struct snd_fasync *fasync) { if (!fasync) return; - fasync->on = 0; + + scoped_guard(spinlock_irq, &snd_fasync_lock) + list_del_init(&fasync->list); + flush_work(&snd_fasync_work); kfree(fasync); } -- 2.53.0