From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94AB8C38A2D for ; Thu, 27 Oct 2022 06:43:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234366AbiJ0Gni (ORCPT ); Thu, 27 Oct 2022 02:43:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbiJ0Gnf (ORCPT ); Thu, 27 Oct 2022 02:43:35 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3B141707B for ; Wed, 26 Oct 2022 23:43:34 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 54EA2229C1; Thu, 27 Oct 2022 06:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666853013; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UdAlLEOS4lwU8nCule+zhA14g2SedT9Jb5Y5FwjbRf0=; b=V22QXrPauFPFU9bfRuERi3WHBV57t2L8/DpcXhH3X75FCJDRXwVnAdt3cJwhedsOykZOmN D8n78B0EeIMJDsunVLEkeXsMgaFD+m5xCZAeOZH6qwHr8GgXGs+rPyodjCq7OR2FUZB8/p vzTZBg/YHaLbpUUw5z+hsAu+jI6a/Fc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666853013; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UdAlLEOS4lwU8nCule+zhA14g2SedT9Jb5Y5FwjbRf0=; b=9JToWTO/qhNG46d5QkMe4d7rd7Uc+RM7060qt7lMf/SI/DFlFSf5p37XRegzfLSm85n0Nt quvHGFRxSNCKv6DA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2386313357; Thu, 27 Oct 2022 06:43:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id dQfXB5UoWmNKEgAAMHmgww (envelope-from ); Thu, 27 Oct 2022 06:43:33 +0000 Date: Thu, 27 Oct 2022 08:43:32 +0200 Message-ID: <87pmedojfv.wl-tiwai@suse.de> From: Takashi Iwai To: Steven Rostedt Cc: LKML , Linus Torvalds , Thomas Gleixner , Guenter Roeck , Stephen Boyd , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org Subject: Re: [PATCH] ALSA: Use del_timer_sync() before freeing timer In-Reply-To: <20221026231236.6834b551@gandalf.local.home> References: <20221026231236.6834b551@gandalf.local.home> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 27 Oct 2022 05:12:36 +0200, Steven Rostedt wrote: > > From: "Steven Rostedt (Google)" > > 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) 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 >