Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp275940rwi; Thu, 27 Oct 2022 00:41:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7cqrWQNLt8ih/LYwZj0gnWY0YVL1Mm7VXrv8B7Ijb6heksvGo1vShOmPPIvWfRoXNdPlfF X-Received: by 2002:a63:540b:0:b0:43c:8ce9:2800 with SMTP id i11-20020a63540b000000b0043c8ce92800mr40314604pgb.481.1666856466228; Thu, 27 Oct 2022 00:41:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666856466; cv=none; d=google.com; s=arc-20160816; b=VwKBGJiU2mXj8v7G4Sdz0qOCX3SRLO0CJsGM3w6316ixGgWtiYjALwjPWqfIekQpyr gmJUBAsMCYaIkufvdqkoHs3jpyx5CHtpF7sup08RQ8sT5jkF/udhpZM2mAXiDFwgozwn uFAXKgJyBfVde5eycsn9axWXWCaI9Ph9iiW0dtntX8bYBd/c7Xhe7OvVVPCayRzo3kUH x4nMWEg3GPAORvHFYpeFsTzmdR3pscFW/JKWUkUA32E89wu1ltehUMAEyLkbfPdzORPK Mn9M3g4to9NCrF0n9CRZvQ8HQWh/Lnur2YWAswP1HX/8/yfNMW54BQFS0cAN5zz7AMqK lE2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=UdAlLEOS4lwU8nCule+zhA14g2SedT9Jb5Y5FwjbRf0=; b=Iyu839RHr4QdjVbVZ33nuiNTL3tF/5rJFqbIIhSmV7sXFMzsuQ07sDlTaf4ukZhyMu +vJDtmdbnok8tFy+bwspi9hcw7BWvtoswbJIevtcCAbDzczI6Pa0C+w5IF164YjLkvl8 ZCR5qJOXa2IsEEU6OW+Eu4SFANYZNVQQXq1/3pTS6ZsvHinVq3YHVI/luObjDR+Z48Io saWm9ZF6aoGnhl3QlcOCsksG0h/wXHYDdqjroc9BnCsP3yN40SOl70PC2cWBhZwBkkc7 5zotBa7R3TZ3hAcVKwqVpiImhY6cIR/Q2DA2dPN757pMWoBZhnlGA/n5tpOT6TJVGiMs giJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=V22QXrPa; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="9JToWTO/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k2-20020a63ff02000000b0046f33e0f911si852185pgi.563.2022.10.27.00.40.54; Thu, 27 Oct 2022 00:41:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=V22QXrPa; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="9JToWTO/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234290AbiJ0Gnh (ORCPT + 99 others); Thu, 27 Oct 2022 02:43:37 -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 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 >