Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp5048155rwb; Wed, 21 Sep 2022 02:22:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6YLDTTeIJSfOD3ANPdbvmJSZRsFK3MBGyL0vGxO1Ab6WezC9bhUmqZCc1B00Td1KChsP8j X-Received: by 2002:a17:907:b15:b0:782:f8:8695 with SMTP id h21-20020a1709070b1500b0078200f88695mr2457127ejl.693.1663752163709; Wed, 21 Sep 2022 02:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663752163; cv=none; d=google.com; s=arc-20160816; b=L0gUUSo56lbSx1rlNovHigFP9wPz0dtVPhjRap2tUJ4mivYNNvYBjAwTd+oUrEkFt5 cZs7AxgsZQAFVW8HmMLT2/yiWrulpR2BrF+OknG+fVrz9wRG7B+H+xq4zaWAKujWuAv1 /cdZeFYxDIWiXe9V8KoJ6K3vUBcL/GHDIur9xROc7YCvmiNl5f0BdU1lj/Zk2wvRSD7S BJfeWqYy5Y7o9B7wIFFAY1QNX2Ni9ieIMqWbsuZULnIXJ8CVgb9Jpsq+E+FjFwe+zPk5 DogUMNX+Xc8d3revzLdQQ1uRhOhKJyQ7vi3jFRsxDKanD9ktpg5dohPpBqsqo95IAat2 xGBA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=2SScq0A2/jTDB00G6OKMwCsXStKdNn9mcuDvMyXgdsE=; b=N4jVwcFEdSaq2MMha3pE74B5/hXyeGRM+vFiqKNlgfeV5aUPSJAXSuEgxuK7xW0sDa JsTmPqAolWNikwawTV3J6b6D+cX4YhD47R4zHxlD0DVR88CEHnpLVObd3jO71BuMvE/t Wa/eCWl4G0Wy/UwQVAEs+Uc8DR1z8hCELF/10la5Fn2Suj3zvUWk0PJHPdYhVtSdAiR+ 75/CTLktdO33YJ7Gd8y+E/eIKFjcPcDJXjyRDcG/sC6iVe8Y5tNkwOVPouNkyjm00Y9V ph+b/Pj0RNiLS9ArMU7Tb49xWapPYpi7tJgpJHlJk9dUwpRZBTfd6099vge9rVdg12sG F3uw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u22-20020a170906781600b0073dd47c3873si1577766ejm.878.2022.09.21.02.22.27; Wed, 21 Sep 2022 02:22:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbiIUJUm (ORCPT + 63 others); Wed, 21 Sep 2022 05:20:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230403AbiIUJUP (ORCPT ); Wed, 21 Sep 2022 05:20:15 -0400 Received: from out29-148.mail.aliyun.com (out29-148.mail.aliyun.com [115.124.29.148]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 995EE239; Wed, 21 Sep 2022 02:19:28 -0700 (PDT) X-Alimail-AntiSpam: AC=CONTINUE;BC=0.08073047|-1;BR=01201311R111S08rulernew998_84748_2000303;CH=blue;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.0363558-0.00159698-0.962047;FP=0|0|0|0|0|-1|-1|-1;HT=ay29a033018047190;MF=arda@allwinnertech.com;NM=1;PH=DS;RN=9;RT=9;SR=0;TI=SMTPD_---.PKrbnDF_1663751957; Received: from SunxiBot.allwinnertech.com(mailfrom:arda@allwinnertech.com fp:SMTPD_---.PKrbnDF_1663751957) by smtp.aliyun-inc.com; Wed, 21 Sep 2022 17:19:25 +0800 From: Aran Dalton To: johannes@sipsolutions.net, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: johannes.berg@intel.com, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] cfg80211: fix dead lock for nl80211_del_interface() Date: Wed, 21 Sep 2022 17:19:13 +0800 Message-Id: <20220921091913.110749-2-arda@allwinnertech.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220921091913.110749-1-arda@allwinnertech.com> References: <20220921091913.110749-1-arda@allwinnertech.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY 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-wireless@vger.kernel.org Both nl80211_del_interface and cfg80211_netdev_notifier_call hold the same wiphy_lock, then cause deadlock. The main call stack as bellow: nl80211_del_interface() takes wiphy_lock -> cfg80211_remove_virtual_intf -> rdev_del_virtual_intf -> rdev->ops->del_virtual_intf -> cfg80211_unregister_netdevice -> cfg80211_unregister_wdev -> _cfg80211_unregister_wdev -> unregister_netdevice -> unregister_netdevice_queue -> unregister_netdevice_many -> call_netdevice_notifiers(NETDEV_UNREGISTER, dev); -> call_netdevice_notifiers_extack -> call_netdevice_notifiers_info -> raw_notifier_call_chain -> cfg80211_netdev_notifier_call -> wiphy_lock(&rdev->wiphy), _cfg80211_unregister_wdev Fixes: a05829a7222e ("cfg80211: avoid holding the RTNL when calling the driver") Signed-off-by: Aran Dalton --- net/wireless/nl80211.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index bdacddc3ffa3..664bf977b7bc 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -4269,6 +4269,7 @@ static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) { struct cfg80211_registered_device *rdev = info->user_ptr[0]; struct wireless_dev *wdev = info->user_ptr[1]; + int ret; if (!rdev->ops->del_virtual_intf) return -EOPNOTSUPP; @@ -4296,9 +4297,11 @@ static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) else dev_close(wdev->netdev); + ret = cfg80211_remove_virtual_intf(rdev, wdev); + mutex_lock(&rdev->wiphy.mtx); - return cfg80211_remove_virtual_intf(rdev, wdev); + return ret; } static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) -- 2.29.0