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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4780C38A2D for ; Thu, 27 Oct 2022 06:44:36 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id D21DC32CC; Thu, 27 Oct 2022 08:43:44 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D21DC32CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1666853074; bh=tiSLKNxVi19a+hvvnna0WV/8Pw//SyMIgkiIxjBEpeQ=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=JZR7iD1UCddK17juQNjjRLtaUEMMlDPsC/HPfyY7iEJ6PjeZXwn+dRTzswImDj8pu re+eFCO9kLsVvnm5z8TTwgaRrHfd8/742Q3QBWCTtU1Sc34uKzDeIkOL319LXdEFNS JDiO3Fwkl0MSht2j7ljlu8SG1OvkJAkOSLFZ485E= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 595CDF8025A; Thu, 27 Oct 2022 08:43:44 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id CB21CF8025E; Thu, 27 Oct 2022 08:43:43 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 5ECBAF80095 for ; Thu, 27 Oct 2022 08:43:33 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5ECBAF80095 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="V22QXrPa"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="9JToWTO/" 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 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 Cc: alsa-devel@alsa-project.org, Stephen Boyd , Takashi Iwai , LKML , Thomas Gleixner , Linus Torvalds , Guenter Roeck X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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 >