* [PATCH] ASoC: qcom: common: Fix refcounting in qcom_snd_parse_of()
@ 2020-11-05 12:51 Dan Carpenter
2020-11-10 21:38 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2020-11-05 12:51 UTC (permalink / raw)
To: Patrick Lai, Dinghao Liu, Kuninori Morimoto
Cc: alsa-devel, Banajit Goswami, kernel-janitors, Takashi Iwai,
Liam Girdwood, Mark Brown
There are two issues in this function.
1) We can't drop the refrences on "cpu", "codec" and "platform" before
we take the reference. This doesn't cause a problem on the first
iteration because those pointers start as NULL so the of_node_put()
is a no-op. But on the subsequent iterations, it will lead to a use
after free.
2) If the devm_kzalloc() allocation failed then the code returned
directly instead of cleaning up.
Fixes: c1e6414cdc37 ("ASoC: qcom: common: Fix refcount imbalance on error")
Fixes: 1e36ea360ab9 ("ASoC: qcom: common: use modern dai_link style")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
sound/soc/qcom/common.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c
index 54660f126d09..09af00700700 100644
--- a/sound/soc/qcom/common.c
+++ b/sound/soc/qcom/common.c
@@ -58,7 +58,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL);
if (!dlc) {
ret = -ENOMEM;
- goto err;
+ goto err_put_np;
}
link->cpus = &dlc[0];
@@ -70,7 +70,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
ret = of_property_read_string(np, "link-name", &link->name);
if (ret) {
dev_err(card->dev, "error getting codec dai_link name\n");
- goto err;
+ goto err_put_np;
}
cpu = of_get_child_by_name(np, "cpu");
@@ -130,8 +130,10 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
} else {
/* DPCM frontend */
dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL);
- if (!dlc)
- return -ENOMEM;
+ if (!dlc) {
+ ret = -ENOMEM;
+ goto err;
+ }
link->codecs = dlc;
link->num_codecs = 1;
@@ -158,10 +160,11 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
return 0;
err:
- of_node_put(np);
of_node_put(cpu);
of_node_put(codec);
of_node_put(platform);
+err_put_np:
+ of_node_put(np);
return ret;
}
EXPORT_SYMBOL(qcom_snd_parse_of);
--
2.28.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ASoC: qcom: common: Fix refcounting in qcom_snd_parse_of()
2020-11-05 12:51 [PATCH] ASoC: qcom: common: Fix refcounting in qcom_snd_parse_of() Dan Carpenter
@ 2020-11-10 21:38 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2020-11-10 21:38 UTC (permalink / raw)
To: Dinghao Liu, Dan Carpenter, Kuninori Morimoto, Patrick Lai
Cc: alsa-devel, Banajit Goswami, kernel-janitors, Liam Girdwood,
Takashi Iwai
On Thu, 5 Nov 2020 15:51:54 +0300, Dan Carpenter wrote:
> There are two issues in this function.
>
> 1) We can't drop the refrences on "cpu", "codec" and "platform" before
> we take the reference. This doesn't cause a problem on the first
> iteration because those pointers start as NULL so the of_node_put()
> is a no-op. But on the subsequent iterations, it will lead to a use
> after free.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/1] ASoC: qcom: common: Fix refcounting in qcom_snd_parse_of()
commit: 4e59dd249cd513a211e2ecce2cb31f4e29a5ce5b
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-11-10 21:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-05 12:51 [PATCH] ASoC: qcom: common: Fix refcounting in qcom_snd_parse_of() Dan Carpenter
2020-11-10 21:38 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).