Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp636009iog; Mon, 13 Jun 2022 09:35:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOj9uWNYukLKTs9qVyhqLwWPaUaJqNCE3AbtPvngzDJJB7P4vMgPV8F4NLYqL6Zuit7hWk X-Received: by 2002:a05:6a00:1683:b0:4f7:e497:6a55 with SMTP id k3-20020a056a00168300b004f7e4976a55mr173975pfc.21.1655138147758; Mon, 13 Jun 2022 09:35:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655138147; cv=none; d=google.com; s=arc-20160816; b=afXrDEYeM1n+t18uXHcESt0AQSi8vxjcozmqNocVCtheR7IjJuM6SznLfXLF8nPwOk te94y775YNnaYG0ShSPa5NG0g3Xa2ZE7UhyHH4QPs6UqFIQw8VZhV8xUAMHX3yDnRIsU zKAa+Ecy/ysLFu2g8tY21hfSmN+AGM1EOj3KBMDsUbn4As+2WxPVzuO544+40mpRH0Jw xXbvRmExkWkKU4cwyPJM89y4LpYhhXU2xjWVJe84JoyagBD9nwdTqr/lwMXrQQBETdt2 squLRNDxAm++K3C5opJerXphKwCO47SvrU+ug8N/ovt8YFC1aLM8xo5eUVtD89R6e4XX gapw== 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=hcVADV0ETrwUAIL9buCqG51SNrIfikqo7tUlczJQTKI=; b=OfqjDxuQJYiRlLG0e5QdJqRulf7F6o5f+ZVisMpCjXdf5A32KQhSqEdd6o9Yxoc38S UIrMTA4iMpZ9CSJVh1hn3ktMWkPB+99p9j+aEPpDPQQyGB1u9nwEIDSNIq/U4Hy30828 WF3ztkEyvisYhkjdwY0uMV0BuJHgRPba2e2EP49m7EnLAwQkK7FObTsHGMYrnN/dZjWl N659AmpgpuK1ezZmAWYHKW6mpdRNzu7DG5nNCwNjjD8NPblFiOqAUYIBWVT1hNSZemy7 wqB7MQ1xuZFKtf9vynKbIcelrzzzBbHJQgaD2QKIHXqVAW7PI5aySYg6D5d+DCumi4Ug ykAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OHm6Jz7Z; 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 w13-20020a170902d70d00b001674d61c1c7si9400007ply.400.2022.06.13.09.35.23; Mon, 13 Jun 2022 09:35:47 -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=OHm6Jz7Z; 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 S1376493AbiFMNS7 (ORCPT + 99 others); Mon, 13 Jun 2022 09:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359490AbiFMNJ6 (ORCPT ); Mon, 13 Jun 2022 09:09:58 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6072F3A1AB; Mon, 13 Jun 2022 04:20:59 -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 ams.source.kernel.org (Postfix) with ESMTPS id EAC35B80D3A; Mon, 13 Jun 2022 11:20:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5436FC34114; Mon, 13 Jun 2022 11:20:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655119256; bh=UZ5Dc/FfKOsM7z4voa90CsZSNexUen7lsXLITcFOEA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OHm6Jz7ZBPj0lBT5i7taaK8dTi6QL5E508dQpc0hzZOd/xf1HifYAI0OGpSksq8/c imM6BUYQ5iUaXdFxJ3V7UkM8uqiq1Nspx3K2zhuX2iqJvYLOhBj5pJp0zhZVVI4hT/ eHjiH7crnlE/t44BkVikS2vycr/FjT4O40TOR0Ik= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duoming Zhou , Sasha Levin Subject: [PATCH 5.15 169/247] drivers: staging: rtl8723bs: Fix deadlock in rtw_surveydone_event_callback() Date: Mon, 13 Jun 2022 12:11:11 +0200 Message-Id: <20220613094928.083747391@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@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=-8.3 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 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 [ Upstream commit cc7ad0d77b51c872d629bcd98aea463a3c4109e7 ] There is a deadlock in rtw_surveydone_event_callback(), which is shown below: (Thread 1) | (Thread 2) | _set_timer() rtw_surveydone_event_callback()| mod_timer() spin_lock_bh() //(1) | (wait a time) ... | rtw_scan_timeout_handler() del_timer_sync() | spin_lock_bh() //(2) (wait timer to stop) | ... We hold pmlmepriv->lock in position (1) of thread 1 and use del_timer_sync() to wait timer to stop, but timer handler also need pmlmepriv->lock in position (2) of thread 2. As a result, rtw_surveydone_event_callback() will block forever. This patch extracts del_timer_sync() from the protection of spin_lock_bh(), which could let timer handler to obtain the needed lock. What`s more, we change spin_lock_bh() in rtw_scan_timeout_handler() to spin_lock_irq(). Otherwise, spin_lock_bh() will also cause deadlock() in timer handler. Signed-off-by: Duoming Zhou Link: https://lore.kernel.org/r/20220409061836.60529-1-duoming@zju.edu.cn Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/rtl8723bs/core/rtw_mlme.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c index cf79bec916c5..2c20bf26b10e 100644 --- a/drivers/staging/rtl8723bs/core/rtw_mlme.c +++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c @@ -749,7 +749,9 @@ void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf) } if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) { + spin_unlock_bh(&pmlmepriv->lock); del_timer_sync(&pmlmepriv->scan_to_timer); + spin_lock_bh(&pmlmepriv->lock); _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY); } @@ -1584,11 +1586,11 @@ void rtw_scan_timeout_handler(struct timer_list *t) mlmepriv.scan_to_timer); struct mlme_priv *pmlmepriv = &adapter->mlmepriv; - spin_lock_bh(&pmlmepriv->lock); + spin_lock_irq(&pmlmepriv->lock); _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY); - spin_unlock_bh(&pmlmepriv->lock); + spin_unlock_irq(&pmlmepriv->lock); rtw_indicate_scan_done(adapter, true); } -- 2.35.1