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 0EE6278C9C; Sat, 12 Sep 2026 14:35:52 +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=1789223753; cv=none; b=Ty7/rzK9xkqL8dKzJC0lOPmzerc/oAxaQ1WGKRYJu3VVRnok/MozsWQ0WpQYPHCfx4ZSe43Xv/T8oP4YqfnktGSC6ld7uDoj/2lF4k7OmLe4rsc2+xGfJIArZarx4ilDuDitcOcSbH7dxnlr8kBBVZUkDzzf+qKU8/LIDqZbMew= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789223753; c=relaxed/simple; bh=Dbl8urdUZ4qxfxvi1fx9Xlhoi06mVj34GMyCCHoyg5M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nmZpmpdtLKyM87i9FoRi4ZhU9caBu/PiNnMzzBs4tdZbtJvzoF9ZAPiBTFip9uHyiFThXSiKX02TG/HmvUZ+N9x/k7m39H+4UvhVfmPaa4vNyXkwZ7NC4FBW5SZkX3WEfjT24m5Ficq/a2ykkZ81LquMxuUfIQlv5lSArHwUI54= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TrE73iN0; 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="TrE73iN0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D57E81F000FF; Sat, 12 Sep 2026 14:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789223752; bh=lYVhAjJfzPUr/REZSoZ3o8tSkh/mePki7S+a43CzNPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TrE73iN0qb7ZqfZbbOQdCSTUn72ey4IrP/HF73ka8f5Ku/nM75vsgRBN0irYzz6DR ji5gg/NP0U1A/XC8LrkjW/NBos5NlQtdYbqus/P2zEmYziZUGkJKeKLwUgnxhN/ZtN 8cuc42yQCyFc20I4PIvWZ8LWqkuugdxuptDOYsgg= 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.6 0816/1424] ASoC: meson: Keep link pointers valid on realloc failure Date: Sat, 12 Sep 2026 08:54:08 +0200 Message-ID: <20260912065625.575944352@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.279695368@linuxfoundation.org> References: <20260912065607.279695368@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.6-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 1adaf0041a480..cd27c522f9da2 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