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 78CFD47AF5C; Sat, 12 Sep 2026 16:16:51 +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=1789229813; cv=none; b=eFK3pa00aEr/TO5hgwiwoWcIMuMaqmAxIMyAMeQYlgZsFnEZdnXF2OnR845h1u7UFBdAW1GDf/f+xPeOuGs/K3APIAyRhW5jOPQJ7kxO1hGhJRgPZ0tBN+hzWKqeuolVBytVJigQlc9Bif5+AHi7zyffgHNW2JiCrokCg7XUELA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789229813; c=relaxed/simple; bh=zmegObNQn110kROxRLZUAFNgvDUuwgT0hIKqu0htymk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HhniAGBA6dCQmpzhBc9Yf6sS5Fmj7duZ+huhpxumcjdYoj1LwsBs4FluMJszGLUbVcnyNPFkJzvwy6Q0d3NPm/KlezT9NMp0wybosaYD07335uSdHJ8S1ionJc7PvmR/u8MPfiNBezqtdsyb6IjbRaTyVI78RSmuHqe2V9pp2Lk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=I7CQRbPZ; 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="I7CQRbPZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 375741F000FF; Sat, 12 Sep 2026 16:16:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789229811; bh=iRmk6xJD1Dbmkj1St414Hx7sB5mQY16ZL3IhSqT23iE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=I7CQRbPZQfyNNieTMS6L96zsGa4y+/bFGNlPv44rfsPMeINGj9A7qSJ/bccFS/uqN 3dVe/RS9o9ZrL+Z2Mlbxp+j30PIbWF1V66swm9918AaccMV2CifZ/ZOJWYKQW+5S4R BiCy7yENjCjnPKOR5y55YrFIbFHUhASZF329FCcY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Linmao Li , Jerome Brunet , Mark Brown , Sasha Levin Subject: [PATCH 6.1 0666/1191] ASoC: meson: Keep link pointers valid on realloc failure Date: Sat, 12 Sep 2026 08:56:34 +0200 Message-ID: <20260912065603.215613420@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065548.086904252@linuxfoundation.org> References: <20260912065548.086904252@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Linmao Li [ Upstream commit 2aaa41cf974f83a6fb105422bac4e2f107150774 ] meson_card_reallocate_links() grows the DAI link and private data arrays with two consecutive krealloc() calls and updates the owner pointers only after both calls have succeeded. A successful krealloc() may move the data: it frees the old block and returns a new one. When that happens for the link array and the second krealloc() then fails, card->dai_link still points to the block that krealloc() already freed, and the error path frees the new block too. The probe error path then calls meson_card_clean_references(), which dereferences card->dai_link and kfree()s it again, resulting in a use-after-free and a double free. Commit card->dai_link and card->num_links right after the first krealloc() succeeds, so the pointer always refers to a valid allocation that meson_card_clean_references() can walk and free. krealloc() with __GFP_ZERO zero-initializes the added entries, so walking them on the error path is safe. With both failure paths reduced to a plain return, drop the goto labels and the error message. Fixes: 7864a79f37b5 ("ASoC: meson: add axg sound card support") Signed-off-by: Linmao Li Reviewed-by: Jerome Brunet Link: https://patch.msgid.link/20260717012433.1432285-1-lilinmao@kylinos.cn Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/meson/meson-card-utils.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/sound/soc/meson/meson-card-utils.c b/sound/soc/meson/meson-card-utils.c index 344ab52963316..6a4bc408befe8 100644 --- a/sound/soc/meson/meson-card-utils.c +++ b/sound/soc/meson/meson-card-utils.c @@ -50,25 +50,20 @@ int meson_card_reallocate_links(struct snd_soc_card *card, num_links * sizeof(*priv->card.dai_link), GFP_KERNEL | __GFP_ZERO); if (!links) - goto err_links; + return -ENOMEM; + + priv->card.dai_link = links; + priv->card.num_links = num_links; ldata = krealloc(priv->link_data, num_links * sizeof(*priv->link_data), GFP_KERNEL | __GFP_ZERO); + /* meson_card_clean_references() will free the links on this error path */ if (!ldata) - goto err_ldata; + return -ENOMEM; - priv->card.dai_link = links; priv->link_data = ldata; - priv->card.num_links = num_links; return 0; - -err_ldata: - kfree(links); -err_links: - dev_err(priv->card.dev, "failed to allocate links\n"); - return -ENOMEM; - } EXPORT_SYMBOL_GPL(meson_card_reallocate_links); -- 2.53.0