Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6257341iob; Tue, 10 May 2022 14:09:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwQZ2rRi+6UZPL4GSDaObX/OBbziZYZIEyYKSrieXe2Oi8sgRUlgmxGDz5Y74muU11cpNV X-Received: by 2002:a17:907:7f87:b0:6f5:1c31:6b6 with SMTP id qk7-20020a1709077f8700b006f51c3106b6mr20468533ejc.248.1652216955401; Tue, 10 May 2022 14:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652216955; cv=none; d=google.com; s=arc-20160816; b=CZdDV+vDX4t8tE7s9tsRMeLIrXJoRUJPIV+AHaz0JsD+uMcXxt8rOlWaC1VG8RwXCS sXvzagx9XXoIAeoSyNqTo485iqO9SJDPN9owUm17hdg2bE2yf2FujVib55poPzrNTKPH VXsP9EoUYEPsElbAVrWibpKrIVe7jD+skc8VS/Nf966i5E5Gktw9KQj+8oABWUoiHzvE M+r042v4uksPaBZL/+MEOdLmF5JqNtTmWOvbAf8M3PlwV/HT3iZ+kFG1Di4Ag8Cnx0L8 UfJJ9+aXNS+0jtKTCIoFDAHvzN2LJ0ZV/tJoQoQiQYbjRexujU0v1l0lRJH81DexFNvR j/IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xYWSgwNCHIKZ8aG8VMbA3+aMe7D6+3/G1/Ge8DqclAU=; b=Rts2JQcUPZCg9pFO0Uf1373JUTuvTb7TkTsfFZ1hgyXCHZEbcagca7XcjaxiKQoTAv yQPope1tXLxMC/SC0Khb4ulnCsEJeYCGHEZFbTLnYUUO7CVM+c122vvjdlQcZZ/6F451 QCXqv/+yMF0ZJCNy0CwAjoJRdcfCIeq7F26hvbI/Vhrw7flApN4PlB7zznwsdwyNkGxZ tSfSnmO8nJAW5MwhU1I5ELR/JVY4sLUe9f1jYKB5BVJXuD2RcJfru9WkGYLLbk8Uk0g0 2eaNJ15J4h0V6K7SMThrRxk8Qc60SRZrDkVGo9OkIGrpXZl8aT8xzql8qoxJ86v4yLPO fkuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=acgM7P5c; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp16-20020a170906c15000b006f37a0e4737si351110ejc.381.2022.05.10.14.08.50; Tue, 10 May 2022 14:09:15 -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=@linuxfoundation.org header.s=korg header.b=acgM7P5c; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343904AbiEJNsm (ORCPT + 99 others); Tue, 10 May 2022 09:48:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243849AbiEJNcS (ORCPT ); Tue, 10 May 2022 09:32:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6098A22EA74; Tue, 10 May 2022 06:22:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F0D9F6170D; Tue, 10 May 2022 13:22:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07D91C385C2; Tue, 10 May 2022 13:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652188959; bh=IWBx+5sO3Vp2iBsahPhayhdg6TUAZM8E8BQ3PDzgWgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=acgM7P5couVN3WC84/PUakJt9AUYYvBpLu/U4+wCDLTTWLTnK+csVteQM7YL4YbbE Y0GD9FZVjpnRJ0bnpXOnPkZTSNEPg/yhlx4tyiTMDf2huk7LfokZAklPLj9rvhDURX gDDZDNSIE0VME0IitKDcQN6TdWHwGOxKFkYuV56c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Andreas Larsson , Marc Kleine-Budde Subject: [PATCH 5.4 18/52] can: grcan: grcan_close(): fix deadlock Date: Tue, 10 May 2022 15:07:47 +0200 Message-Id: <20220510130730.389893254@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130729.852544477@linuxfoundation.org> References: <20220510130729.852544477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 From: Duoming Zhou commit 47f070a63e735bcc8d481de31be1b5a1aa62b31c upstream. There are deadlocks caused by del_timer_sync(&priv->hang_timer) and del_timer_sync(&priv->rr_timer) in grcan_close(), one of the deadlocks are shown below: (Thread 1) | (Thread 2) | grcan_reset_timer() grcan_close() | mod_timer() spin_lock_irqsave() //(1) | (wait a time) ... | grcan_initiate_running_reset() del_timer_sync() | spin_lock_irqsave() //(2) (wait timer to stop) | ... We hold priv->lock in position (1) of thread 1 and use del_timer_sync() to wait timer to stop, but timer handler also need priv->lock in position (2) of thread 2. As a result, grcan_close() will block forever. This patch extracts del_timer_sync() from the protection of spin_lock_irqsave(), which could let timer handler to obtain the needed lock. Link: https://lore.kernel.org/all/20220425042400.66517-1-duoming@zju.edu.cn Fixes: 6cec9b07fe6a ("can: grcan: Add device driver for GRCAN and GRHCAN cores") Cc: stable@vger.kernel.org Signed-off-by: Duoming Zhou Reviewed-by: Andreas Larsson Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/grcan.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -1113,8 +1113,10 @@ static int grcan_close(struct net_device priv->closing = true; if (priv->need_txbug_workaround) { + spin_unlock_irqrestore(&priv->lock, flags); del_timer_sync(&priv->hang_timer); del_timer_sync(&priv->rr_timer); + spin_lock_irqsave(&priv->lock, flags); } netif_stop_queue(dev); grcan_stop_hardware(dev);