[PATCH] ASoC: audio-graph-card2: Fix use-after-free in audio_graph2_link_c2c()

Wentao Liang posted 1 patch 1 week ago
sound/soc/generic/audio-graph-card2.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] ASoC: audio-graph-card2: Fix use-after-free in audio_graph2_link_c2c()
Posted by Wentao Liang 1 week ago
of_graph_get_next_port() consumes the reference of its prev argument.
port0 is only borrowed from the caller's iterator, so the call drops a
reference the function does not own, and port0 is dereferenced again
afterwards. Pass an extra reference, as graph_count_c2c() does, so the
reference the callee consumes is the one taken here.

Fixes: 5f281c3e82b1 ("ASoC: audio-graph-card2: use __free(device_node) for device node")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 sound/soc/generic/audio-graph-card2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/soc/generic/audio-graph-card2.c b/sound/soc/generic/audio-graph-card2.c
index 0202ed0ee78e..268023d6f939 100644
--- a/sound/soc/generic/audio-graph-card2.c
+++ b/sound/soc/generic/audio-graph-card2.c
@@ -969,7 +969,8 @@ int audio_graph2_link_c2c(struct simple_util_priv *priv,
 	struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
 	struct device_node *port0 = lnk;
 	struct device_node *ports __free(device_node) = port_to_ports(port0);
-	struct device_node *port1 __free(device_node) = of_graph_get_next_port(ports, port0);
+	struct device_node *port1 __free(device_node) =
+		of_graph_get_next_port(ports, of_node_get(port0));
 	u32 val = 0;
 	int ret = -EINVAL;
 
-- 
2.34.1
Re: [PATCH] ASoC: audio-graph-card2: Fix use-after-free in audio_graph2_link_c2c()
Posted by Mark Brown 6 days, 7 hours ago
On Thu, 17 Sep 2026 16:58:51 +0000, Wentao Liang wrote:
> ASoC: audio-graph-card2: Fix use-after-free in audio_graph2_link_c2c()

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4

Thanks!

[1/1] ASoC: audio-graph-card2: Fix use-after-free in audio_graph2_link_c2c()
      https://git.kernel.org/broonie/sound/c/5ea495bccfd7

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
Re: [PATCH] ASoC: audio-graph-card2: Fix use-after-free in audio_graph2_link_c2c()
Posted by Kuninori Morimoto 6 days, 22 hours ago
Hi Wentao

> of_graph_get_next_port() consumes the reference of its prev argument.
> port0 is only borrowed from the caller's iterator, so the call drops a
> reference the function does not own, and port0 is dereferenced again
> afterwards. Pass an extra reference, as graph_count_c2c() does, so the
> reference the callee consumes is the one taken here.
> 
> Fixes: 5f281c3e82b1 ("ASoC: audio-graph-card2: use __free(device_node) for device node")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
(snip)
> -	struct device_node *port1 __free(device_node) = of_graph_get_next_port(ports, port0);
> +	struct device_node *port1 __free(device_node) =
> +		of_graph_get_next_port(ports, of_node_get(port0));

Ah, yes indeed.

Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>


Thank you for your help !!

Best regards
---
Kuninori Morimoto