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 21EB840DFD0 for ; Sun, 3 May 2026 11:03:48 +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=1777806229; cv=none; b=GFYL7MG9Aarj4pw9AqNovI1+ZjmGMfgW3y2tmXbi+pmp9i2/HnE2Hq/8a4rNKZ0WoLbAatcWnB6FlaxPxZ6vf5zX/5wJTTSDXC1vRt1IuSoe+vIkDA/lAMhKf9FJrEzXW7rpb2VBZrCvPndG00iWZgK/YouXBbpmMxFQCjsGXbk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777806229; c=relaxed/simple; bh=MnMeLaZvZD2xUxbxIB7wu8xpax81ioDO8sW9CRJv5Po=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HjiVSkG/i9VIGcE7eu69NPUXWPr4Y1se8oIbGYT5NPmi2GzC8nc8iSv/90WSOsNk6e3XnqZiUxrgz1Jbij2HdSH52K+oEy9Wf1G4WHFNky6p0+kopwJ+9ODFdqCEkwv7kO/LwpBp4QvW+yrigy4c2L+L+m2fx3pOCqfX6HjeII4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JcSuKISa; 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="JcSuKISa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77661C2BCB4; Sun, 3 May 2026 11:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777806228; bh=MnMeLaZvZD2xUxbxIB7wu8xpax81ioDO8sW9CRJv5Po=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JcSuKISaz8FmLxPJIt1tq2VXmH4odTkLr+M2JjrB1oLMhlOkh+yl32rnvwn611E/Q NRtMX6qD4EwEC0Xdqr9IbyHQQlc/tMe8CgiDze9D5tDgjggTmcnL71KBW/OwKhKCgO mc8/1VlP8ZKrTISey9G1gCmDBfVzyHji7BWedEFNYS1mM0TL+hqXKDnkEJ+Iy0PhaE FZuf0qTOw2u/SXZ84RY8qlTObkGXmPknWEFTcFAUL6ybU7OXppuu0vnkqbFJgOcPU2 1ENggPyf6eK3+FqwpUNaixFKEF91kLO7Gx/Zv0l9oTc+bPlZRrWc8PD9MQK/8UuhMb /AKw3WOHZo0Bw== From: Sasha Levin To: stable@vger.kernel.org Cc: Takashi Iwai , Jake Lamberson , Sasha Levin Subject: [PATCH 5.10.y] ALSA: core: Fix potential data race at fasync handling Date: Sun, 3 May 2026 07:03:44 -0400 Message-ID: <20260503110344.1034091-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026050119-propose-appendage-ec32@gregkh> References: <2026050119-propose-appendage-ec32@gregkh> 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 [ replaced scoped_guard(spinlock_irq, &snd_fasync_lock) with explicit spin_lock_irq()/spin_unlock_irq() ] Signed-off-by: Sasha Levin --- sound/core/misc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sound/core/misc.c b/sound/core/misc.c index c3f3d94b51970..057bb390e679d 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); @@ -234,7 +238,11 @@ void snd_fasync_free(struct snd_fasync *fasync) { if (!fasync) return; - fasync->on = 0; + + spin_lock_irq(&snd_fasync_lock); + list_del_init(&fasync->list); + spin_unlock_irq(&snd_fasync_lock); + flush_work(&snd_fasync_work); kfree(fasync); } -- 2.53.0