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 AA79A309DB5; Mon, 13 Apr 2026 16:22:50 +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=1776097370; cv=none; b=T/6KfTLdSHpTe2yGX2sBX1+lCeskkS2lRnN+rX5LGHek3FnOiE+UncCfZYiacMzgHdEKnvZCpsqP9dN3s4VeWetG4sT/3TAvpzlKxOZCHDc4pTMaNcqBrykXKCQl55bP/FpLnlEGMTaUDvDxLTLDV1WRndn0i43iTg+TtExWOZY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776097370; c=relaxed/simple; bh=i+KoiMQHpQfbUFp1nQpUSIknZ3E92VFC4kICKspYDgM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Av5RwjeSe5ToAILCvuYqv7PpLJVKhemgmr3TZMeJDRQLZvHm1bPkx/mxHH11mt6/H22HxhbyZm34khud2+NuyveGXOeQZTxIcZE0hqeuBn9XiczxuyzwAuMSeWXf9ShFhsu1P9farUOy1aMWYVkCvlDkst+V5PXrMWZWCy2ricg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=GsxAB/rg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="GsxAB/rg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4237BC2BCAF; Mon, 13 Apr 2026 16:22:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776097370; bh=i+KoiMQHpQfbUFp1nQpUSIknZ3E92VFC4kICKspYDgM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GsxAB/rgQ+Y6lY2bfpxzhCz0sLBO5wdLkHN3Ob8qL8n43DtxO2Oi+wp2tHW+T9nuN qGQv4oUiyjGMBsueahbcNcz34dVlblbVt/ZYduV2hE5+uV9DJNEPLDdhP460dq9dN5 W6DDtzYbmIRVDk5Q1uKcL3Koe6pX5SfuhF/boltk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Matteo Cotifava , Mark Brown , Sasha Levin Subject: [PATCH 5.15 110/570] ASoC: soc-core: flush delayed work before removing DAIs and widgets Date: Mon, 13 Apr 2026 17:54:01 +0200 Message-ID: <20260413155834.565119623@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260413155830.386096114@linuxfoundation.org> References: <20260413155830.386096114@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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: matteo.cotifava [ Upstream commit 95bc5c225513fc3c4ce169563fb5e3929fbb938b ] When a sound card is unbound while a PCM stream is open, a use-after-free can occur in snd_soc_dapm_stream_event(), called from the close_delayed_work workqueue handler. During unbind, snd_soc_unbind_card() flushes delayed work and then calls soc_cleanup_card_resources(). Inside cleanup, snd_card_disconnect_sync() releases all PCM file descriptors, and the resulting PCM close path can call snd_soc_dapm_stream_stop() which schedules new delayed work with a pmdown_time timer delay. Since this happens after the flush in snd_soc_unbind_card(), the new work is not caught. soc_remove_link_components() then frees DAPM widgets before this work fires, leading to the use-after-free. The existing flush in soc_free_pcm_runtime() also cannot help as it runs after soc_remove_link_components() has already freed the widgets. Add a flush in soc_cleanup_card_resources() after snd_card_disconnect_sync() (after which no new PCM closes can schedule further delayed work) and before soc_remove_link_dais() and soc_remove_link_components() (which tear down the structures the delayed work accesses). Fixes: e894efef9ac7 ("ASoC: core: add support to card rebind") Signed-off-by: Matteo Cotifava Link: https://patch.msgid.link/20260309215412.545628-3-cotifavamatteo@gmail.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/soc-core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index a555fe0a837d5..e406c896a511a 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1933,6 +1933,9 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card) for_each_card_rtds(card, rtd) if (rtd->initialized) snd_soc_link_exit(rtd); + /* flush delayed work before removing DAIs and DAPM widgets */ + snd_soc_flush_all_delayed_work(card); + /* remove and free each DAI */ soc_remove_link_dais(card); soc_remove_link_components(card); -- 2.51.0