Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6202499iob; Tue, 10 May 2022 12:43:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoxQ2plvnmR3J4dZkp/BlvW5UWcrhzvBxgVLDbKS0nbqt24NFWPFG03z/CcJaL7hn3nsnq X-Received: by 2002:a05:6808:1641:b0:2f9:b0c6:1a5c with SMTP id az1-20020a056808164100b002f9b0c61a5cmr883646oib.140.1652211828290; Tue, 10 May 2022 12:43:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652211828; cv=none; d=google.com; s=arc-20160816; b=jmW2rrlrNfA8eJHq/o7QUCkYzd5PkIv20sfcvCv+RD8HVZRCPrQOU66NEpcgoxDbNP pt9pS/WyiEremK8oa2t8cDAGIo0GTk0E7U26YnKG+AQLpCZ4N9aPaxnpXfwGEYlCLzXJ DvkTxTrIaC1U++VSjOqFXbxT4V9rINE9sEy3N/wlCjKsJjIjcNzmq0yHp6Fk53XGgQUf hQJ1tRcyv9V3V7Ok4OVZ9enQF4I3sBLIEfaMg37CnAN63bBKMyaOocT2i/rs87guHJhj QnLTYMDzoDRvHgni54JpH/cO0Lk/oSLJyP48F4RVdKChyGMAezrRcztpdHH9Prnka96x Anqg== 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=cOgph11px6oIBgrANP+mi8RCmqEtCQC7bfrnRIR+RnwRlf433nAIV+pc0UdHCZLWze 0L5noNh4CAcwiSg/C7fbSR/p4n65I2qkhoPcA0yYDZ0Qyb1dIock6m/bu/FNhF32Icus 1wNkLq+ieRoFuXfMqullSj7K0fzXllTu79bZ7z2kSOl8ITgozQojBETA/rXWugM80cZl Fxhwx7x9HidB+oVAtojbo1LA1iA3Rs+HblL8y15rMgBq69tGa53L9Odj1FUGRF4dOAk8 SVmTk/7XhwnJOkhA4iwg0oj8EfZsFE0W00+Mhbw5EzI5z1I2oM5W876Jt+/LCUVL5Igu A2AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=o1j2iIuj; 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 g108-20020a9d12f5000000b006060f0026a7si109484otg.36.2022.05.10.12.43.34; Tue, 10 May 2022 12:43:48 -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=o1j2iIuj; 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 S245099AbiEJN5L (ORCPT + 99 others); Tue, 10 May 2022 09:57:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245118AbiEJNic (ORCPT ); Tue, 10 May 2022 09:38:32 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CC46245611; Tue, 10 May 2022 06:27:10 -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 sin.source.kernel.org (Postfix) with ESMTPS id E0F57CE1EDE; Tue, 10 May 2022 13:27:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE414C385C6; Tue, 10 May 2022 13:27:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652189227; bh=IWBx+5sO3Vp2iBsahPhayhdg6TUAZM8E8BQ3PDzgWgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o1j2iIujho08PF6DqqogWkkKeGYkFitKx+FgCxlo5ZtYvIR6FBP3tPU/QMUj3UXGt IIcvv7dCVU2s+Uoo960eXhCp3voMAXvjInZVmMy74oKydzesRBu9HagFeBj5/VH4D2 pS6j8GYhxSOHh4oWs6iuLBpG3ZTo66zSapvPSztI= 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.10 26/70] can: grcan: grcan_close(): fix deadlock Date: Tue, 10 May 2022 15:07:45 +0200 Message-Id: <20220510130733.634427211@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130732.861729621@linuxfoundation.org> References: <20220510130732.861729621@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);