From: Takashi Iwai <tiwai@suse.de>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Guenter Roeck <linux@roeck-us.net>,
Stephen Boyd <sboyd@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
alsa-devel@alsa-project.org
Subject: Re: [PATCH] ALSA: Use del_timer_sync() before freeing timer
Date: Thu, 27 Oct 2022 08:43:32 +0200 [thread overview]
Message-ID: <87pmedojfv.wl-tiwai@suse.de> (raw)
In-Reply-To: <20221026231236.6834b551@gandalf.local.home>
On Thu, 27 Oct 2022 05:12:36 +0200,
Steven Rostedt wrote:
>
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
>
> The current code for freeing the emux timer is extremely dangerous:
>
> CPU0 CPU1
> ---- ----
> snd_emux_timer_callback()
> snd_emux_free()
> spin_lock(&emu->voice_lock)
> del_timer(&emu->tlist); <-- returns immediately
> spin_unlock(&emu->voice_lock);
> [..]
> kfree(emu);
>
> spin_lock(&emu->voice_lock);
>
> [BOOM!]
>
> Instead just use del_timer_sync() which will wait for the timer to finish
> before continuing. No need to check if the timer is active or not when
> doing so.
>
> This doesn't fix the race of a possible re-arming of the timer, but at
> least it won't use the data that has just been freed.
>
> Cc: stable@vger.kernel.org
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Applied now with the fix of unused variable warning.
Thanks!
Takashi
> ---
> sound/synth/emux/emux.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/sound/synth/emux/emux.c b/sound/synth/emux/emux.c
> index 5ed8e36d2e04..a2ee78809cfb 100644
> --- a/sound/synth/emux/emux.c
> +++ b/sound/synth/emux/emux.c
> @@ -131,10 +131,7 @@ int snd_emux_free(struct snd_emux *emu)
> if (! emu)
> return -EINVAL;
>
> - spin_lock_irqsave(&emu->voice_lock, flags);
> - if (emu->timer_active)
> - del_timer(&emu->tlist);
> - spin_unlock_irqrestore(&emu->voice_lock, flags);
> + del_timer_sync(&emu->tlist);
>
> snd_emux_proc_free(emu);
> snd_emux_delete_virmidi(emu);
> --
> 2.35.1
>
next prev parent reply other threads:[~2022-10-27 6:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-27 3:12 [PATCH] ALSA: Use del_timer_sync() before freeing timer Steven Rostedt
2022-10-27 4:04 ` Guenter Roeck
2022-10-27 5:58 ` kernel test robot
2022-10-27 6:43 ` Takashi Iwai [this message]
2022-10-27 13:37 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pmedojfv.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=perex@perex.cz \
--cc=rostedt@goodmis.org \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
--cc=tiwai@suse.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox