* [PATCH v2 12/12] ASoC: Fix use-after-free at card unregistration [not found] <1497857229-12049-1-git-send-email-robert.jarzmik@free.fr> @ 2017-06-19 7:27 ` Robert Jarzmik 2017-06-19 9:25 ` Takashi Iwai 0 siblings, 1 reply; 7+ messages in thread From: Robert Jarzmik @ 2017-06-19 7:27 UTC (permalink / raw) To: Dmitry Torokhov, Lee Jones, Jaroslav Kysela, Takashi Iwai, Daniel Mack, Haojian Zhuang, Robert Jarzmik, Liam Girdwood, Mark Brown, Lars-Peter Clausen, Charles Keepax Cc: linux-kernel, linux-input, patches, alsa-devel, linux-arm-kernel, Takashi Iwai, stable From: Takashi Iwai <tiwai@suse.de> soc_cleanup_card_resources() call snd_card_free() at the last of its procedure. This turned out to lead to a use-after-free. PCM runtimes have been already removed via soc_remove_pcm_runtimes(), while it's dereferenced later in soc_pcm_free() called via snd_card_free(). The fix is simple: just move the snd_card_free() call to the beginning of the whole procedure. This also gives another benefit: it guarantees that all operations have been shut down before actually releasing the resources, which was racy until now. Reported-and-tested-by: Robert Jarzmik <robert.jarzmik@free.fr> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de> --- sound/soc/soc-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 2722bb0c5573..98d60f471c5d 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2286,6 +2286,9 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card) list_for_each_entry(rtd, &card->rtd_list, list) flush_delayed_work(&rtd->delayed_work); + /* free the ALSA card at first; this syncs with pending operations */ + snd_card_free(card->snd_card); + /* remove and free each DAI */ soc_remove_dai_links(card); soc_remove_pcm_runtimes(card); @@ -2300,9 +2303,7 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card) if (card->remove) card->remove(card); - snd_card_free(card->snd_card); return 0; - } /* removes a socdev */ -- 2.1.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 12/12] ASoC: Fix use-after-free at card unregistration 2017-06-19 7:27 ` [PATCH v2 12/12] ASoC: Fix use-after-free at card unregistration Robert Jarzmik @ 2017-06-19 9:25 ` Takashi Iwai 2017-06-19 11:57 ` Robert Jarzmik 0 siblings, 1 reply; 7+ messages in thread From: Takashi Iwai @ 2017-06-19 9:25 UTC (permalink / raw) To: Robert Jarzmik Cc: Dmitry Torokhov, Haojian Zhuang, Liam Girdwood, Mark Brown, Lee Jones, Lars-Peter Clausen, Charles Keepax, Jaroslav Kysela, Daniel Mack, alsa-devel, linux-arm-kernel, patches, linux-input, linux-kernel, stable On Mon, 19 Jun 2017 09:27:09 +0200, Robert Jarzmik wrote: > > From: Takashi Iwai <tiwai@suse.de> > > soc_cleanup_card_resources() call snd_card_free() at the last of its > procedure. This turned out to lead to a use-after-free. > PCM runtimes have been already removed via soc_remove_pcm_runtimes(), > while it's dereferenced later in soc_pcm_free() called via > snd_card_free(). > > The fix is simple: just move the snd_card_free() call to the beginning > of the whole procedure. This also gives another benefit: it > guarantees that all operations have been shut down before actually > releasing the resources, which was racy until now. > > Reported-and-tested-by: Robert Jarzmik <robert.jarzmik@free.fr> > Cc: <stable@vger.kernel.org> > Signed-off-by: Takashi Iwai <tiwai@suse.de> This patch must be superfluous :) Takashi > --- > sound/soc/soc-core.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c > index 2722bb0c5573..98d60f471c5d 100644 > --- a/sound/soc/soc-core.c > +++ b/sound/soc/soc-core.c > @@ -2286,6 +2286,9 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card) > list_for_each_entry(rtd, &card->rtd_list, list) > flush_delayed_work(&rtd->delayed_work); > > + /* free the ALSA card at first; this syncs with pending operations */ > + snd_card_free(card->snd_card); > + > /* remove and free each DAI */ > soc_remove_dai_links(card); > soc_remove_pcm_runtimes(card); > @@ -2300,9 +2303,7 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card) > if (card->remove) > card->remove(card); > > - snd_card_free(card->snd_card); > return 0; > - > } > > /* removes a socdev */ > -- > 2.1.4 > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 12/12] ASoC: Fix use-after-free at card unregistration 2017-06-19 9:25 ` Takashi Iwai @ 2017-06-19 11:57 ` Robert Jarzmik 2017-06-28 19:53 ` [alsa-devel] " Mark Brown 0 siblings, 1 reply; 7+ messages in thread From: Robert Jarzmik @ 2017-06-19 11:57 UTC (permalink / raw) To: Takashi Iwai Cc: Dmitry Torokhov, Haojian Zhuang, Liam Girdwood, Mark Brown, Lee Jones, Lars-Peter Clausen, Charles Keepax, Jaroslav Kysela, Daniel Mack, alsa-devel, linux-arm-kernel, patches, linux-input, linux-kernel, stable Takashi Iwai <tiwai@suse.de> writes: > On Mon, 19 Jun 2017 09:27:09 +0200, > Robert Jarzmik wrote: >> >> From: Takashi Iwai <tiwai@suse.de> >> >> soc_cleanup_card_resources() call snd_card_free() at the last of its >> procedure. This turned out to lead to a use-after-free. >> PCM runtimes have been already removed via soc_remove_pcm_runtimes(), >> while it's dereferenced later in soc_pcm_free() called via >> snd_card_free(). >> >> The fix is simple: just move the snd_card_free() call to the beginning >> of the whole procedure. This also gives another benefit: it >> guarantees that all operations have been shut down before actually >> releasing the resources, which was racy until now. >> >> Reported-and-tested-by: Robert Jarzmik <robert.jarzmik@free.fr> >> Cc: <stable@vger.kernel.org> >> Signed-off-by: Takashi Iwai <tiwai@suse.de> > > This patch must be superfluous :) Haha :) My serie shifted by one, so the very first of the serie is therefore missing, formerly "ALSA: ac97: split out the generic ac97 registers" in https://patchwork.kernel.org/patch/9398143/, and the shift triggered the inclusion of the last patch of my tree, ie. yours :) Cheers. -- Robert ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [alsa-devel] [PATCH v2 12/12] ASoC: Fix use-after-free at card unregistration 2017-06-19 11:57 ` Robert Jarzmik @ 2017-06-28 19:53 ` Mark Brown 2017-06-28 22:03 ` Robert Jarzmik 0 siblings, 1 reply; 7+ messages in thread From: Mark Brown @ 2017-06-28 19:53 UTC (permalink / raw) To: Robert Jarzmik Cc: Takashi Iwai, linux-input, alsa-devel, Lars-Peter Clausen, linux-kernel, Dmitry Torokhov, Liam Girdwood, Haojian Zhuang, linux-arm-kernel, patches, stable, Charles Keepax, Lee Jones, Daniel Mack [-- Attachment #1: Type: text/plain, Size: 418 bytes --] On Mon, Jun 19, 2017 at 01:57:20PM +0200, Robert Jarzmik wrote: > My serie shifted by one, so the very first of the serie is therefore missing, > formerly "ALSA: ac97: split out the generic ac97 registers" in > https://patchwork.kernel.org/patch/9398143/, and the shift triggered the > inclusion of the last patch of my tree, ie. yours :) Based on the missing first patch I was expecting the series to get reposted? [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [alsa-devel] [PATCH v2 12/12] ASoC: Fix use-after-free at card unregistration 2017-06-28 19:53 ` [alsa-devel] " Mark Brown @ 2017-06-28 22:03 ` Robert Jarzmik 2017-06-30 11:56 ` Mark Brown 0 siblings, 1 reply; 7+ messages in thread From: Robert Jarzmik @ 2017-06-28 22:03 UTC (permalink / raw) To: Mark Brown Cc: Takashi Iwai, linux-input, alsa-devel, Lars-Peter Clausen, linux-kernel, Dmitry Torokhov, Liam Girdwood, Haojian Zhuang, linux-arm-kernel, patches, stable, Charles Keepax, Lee Jones, Daniel Mack Mark Brown <broonie@kernel.org> writes: > On Mon, Jun 19, 2017 at 01:57:20PM +0200, Robert Jarzmik wrote: > >> My serie shifted by one, so the very first of the serie is therefore missing, >> formerly "ALSA: ac97: split out the generic ac97 registers" in >> https://patchwork.kernel.org/patch/9398143/, and the shift triggered the >> inclusion of the last patch of my tree, ie. yours :) > > Based on the missing first patch I was expecting the series to get > reposted? Hi Mark, The first patch is only moving around a .h file. I was expecting a review before reposting a v3. Cheers. -- Robert ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [alsa-devel] [PATCH v2 12/12] ASoC: Fix use-after-free at card unregistration 2017-06-28 22:03 ` Robert Jarzmik @ 2017-06-30 11:56 ` Mark Brown 2017-06-30 15:06 ` Robert Jarzmik 0 siblings, 1 reply; 7+ messages in thread From: Mark Brown @ 2017-06-30 11:56 UTC (permalink / raw) To: Robert Jarzmik Cc: Takashi Iwai, linux-input, alsa-devel, Lars-Peter Clausen, linux-kernel, Dmitry Torokhov, Liam Girdwood, Haojian Zhuang, linux-arm-kernel, patches, stable, Charles Keepax, Lee Jones, Daniel Mack [-- Attachment #1: Type: text/plain, Size: 476 bytes --] On Thu, Jun 29, 2017 at 12:03:58AM +0200, Robert Jarzmik wrote: > Mark Brown <broonie@kernel.org> writes: > > Based on the missing first patch I was expecting the series to get > > reposted? > The first patch is only moving around a .h file. I was expecting a review before > reposting a v3. I can't tell what's in the first patch if you didn't send it.... :( In general it's best to resend for things like this, I know I focus my review on things that can progress as-is. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [alsa-devel] [PATCH v2 12/12] ASoC: Fix use-after-free at card unregistration 2017-06-30 11:56 ` Mark Brown @ 2017-06-30 15:06 ` Robert Jarzmik 0 siblings, 0 replies; 7+ messages in thread From: Robert Jarzmik @ 2017-06-30 15:06 UTC (permalink / raw) To: Mark Brown Cc: Takashi Iwai, linux-input, alsa-devel, Lars-Peter Clausen, linux-kernel, Dmitry Torokhov, Liam Girdwood, Haojian Zhuang, linux-arm-kernel, patches, stable, Charles Keepax, Lee Jones, Daniel Mack Mark Brown <broonie@kernel.org> writes: > On Thu, Jun 29, 2017 at 12:03:58AM +0200, Robert Jarzmik wrote: >> Mark Brown <broonie@kernel.org> writes: > >> > Based on the missing first patch I was expecting the series to get >> > reposted? > >> The first patch is only moving around a .h file. I was expecting a review before >> reposting a v3. > > I can't tell what's in the first patch if you didn't send it.... :( > In general it's best to resend for things like this, I know I focus my > review on things that can progress as-is. OK, no problem, I'll resend a v2 resend in the following hours. Cheers. -- Robert ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-06-30 15:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1497857229-12049-1-git-send-email-robert.jarzmik@free.fr>
2017-06-19 7:27 ` [PATCH v2 12/12] ASoC: Fix use-after-free at card unregistration Robert Jarzmik
2017-06-19 9:25 ` Takashi Iwai
2017-06-19 11:57 ` Robert Jarzmik
2017-06-28 19:53 ` [alsa-devel] " Mark Brown
2017-06-28 22:03 ` Robert Jarzmik
2017-06-30 11:56 ` Mark Brown
2017-06-30 15:06 ` Robert Jarzmik
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox