Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3656249ybz; Mon, 20 Apr 2020 07:07:20 -0700 (PDT) X-Google-Smtp-Source: APiQypKkr0EFtnLHw07GtEZxbyVMb9JIbaQ1gjkAGKWJYmYYGpbV3+3mK9alM48XE0quE23d8sHv X-Received: by 2002:a17:906:b28f:: with SMTP id q15mr15594116ejz.188.1587391640090; Mon, 20 Apr 2020 07:07:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587391640; cv=none; d=google.com; s=arc-20160816; b=QvxffqvoXyfNWze9ZqAhKGTAPev2W8K+W5mROpDtyOuEpIWmJb9/7zGLnxsnpE6unK 5Tteu7jGibuBztmbHO3rwG2dtJ00kzrZIEB355JlBWxC18jUBoh2T7Sd2z1IBkfQkdVD DNfMWgKlHuQeLh/Wo3BmZeslpf+QwTwA5fX4ZdfHzxx6AYlrjNcYYhjzs7W0IbzM/Chq ZtvYztV2hQicbPjmMglyuztcXV4X+0+guRrarElNWNHGpvdSl6KlthwvJ3rVptDWeI4b UnVr6kdDKLxuR8nGK0Z5FufIWxLnvR1ThWUVGV32jsEtV269TPR93PEZo6NonMhi2a8K v7sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SC2rD/a7Yvc6crUlWadwZgrAaWE8DTfWtr7xGJ3Xzjs=; b=DDu/Jqp3zMyGIXPw82fiIsqwr7cyRWrDhJEWSxJuGFIgEZgdlhBxYeXEf1tCjx+lZ6 i+nITg6rBRJuOCON01bRGeZXuSeg0yj9D07uab+4BL/AKxahe6va7Z9re3WarduNuBQE 8ejwK6Zmkc8SvQNM8FV2qikv2l3oaRswuPvdcObzWvVasRuymwgWluJVQSDeO5oRSuYX SI+EVOy9YcO/euVL/bIyA6UKPZcrxHFP0O3dFVxodOMdCemuQwETumlvs+yBoEGVRrsV RCOqKbxfRDXZNnsJ5sox0KCyRRIoqrl8yhpRfFlxnVcsdI7qOgdebK1pcQqpzeZEDeGB FiQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V3bmyava; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a23si584451edy.27.2020.04.20.07.06.55; Mon, 20 Apr 2020 07:07:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V3bmyava; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728105AbgDTMot (ORCPT + 99 others); Mon, 20 Apr 2020 08:44:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:38700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728606AbgDTMom (ORCPT ); Mon, 20 Apr 2020 08:44:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8F6D82072B; Mon, 20 Apr 2020 12:44:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587386682; bh=3w05jCYjIhoDyDncLmt8aY0aq/NFMnH9Bfe0njl5I1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V3bmyavaQYnmDjghg0JXBId9APbPVqTZ3eOl4sfdsIO2zODcjpI89AjkfsEqCBctW TPr9PCbghBOShmJQvgr/Xe0Rb8aXxLCyoYDY3BdsoLNrLNYc3w2LylszLWrzrBq6cl bpcFeeTwqX3ANbUM615fxFvMzTPqAp/jCBF0oZLg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sumit Garg , Johannes Berg Subject: [PATCH 5.6 53/71] mac80211: fix race in ieee80211_register_hw() Date: Mon, 20 Apr 2020 14:39:07 +0200 Message-Id: <20200420121519.805021247@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200420121508.491252919@linuxfoundation.org> References: <20200420121508.491252919@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sumit Garg commit 52e04b4ce5d03775b6a78f3ed1097480faacc9fd upstream. A race condition leading to a kernel crash is observed during invocation of ieee80211_register_hw() on a dragonboard410c device having wcn36xx driver built as a loadable module along with a wifi manager in user-space waiting for a wifi device (wlanX) to be active. Sequence diagram for a particular kernel crash scenario: user-space ieee80211_register_hw() ieee80211_tasklet_handler() ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | | | |<---phy0----wiphy_register() | |-----iwd if_add---->| | | |<---IRQ----(RX packet) | Kernel crash | | due to unallocated | | workqueue. | | | | | alloc_ordered_workqueue() | | | | | Misc wiphy init. | | | | | ieee80211_if_add() | | | | As evident from above sequence diagram, this race condition isn't specific to a particular wifi driver but rather the initialization sequence in ieee80211_register_hw() needs to be fixed. So re-order the initialization sequence and the updated sequence diagram would look like: user-space ieee80211_register_hw() ieee80211_tasklet_handler() ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | | | | alloc_ordered_workqueue() | | | | | Misc wiphy init. | | | | |<---phy0----wiphy_register() | |-----iwd if_add---->| | | |<---IRQ----(RX packet) | | | | ieee80211_if_add() | | | | Cc: stable@vger.kernel.org Signed-off-by: Sumit Garg Link: https://lore.kernel.org/r/1586254255-28713-1-git-send-email-sumit.garg@linaro.org [Johannes: fix rtnl imbalances] Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- net/mac80211/main.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -1051,7 +1051,7 @@ int ieee80211_register_hw(struct ieee802 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; if (hw->max_signal <= 0) { result = -EINVAL; - goto fail_wiphy_register; + goto fail_workqueue; } } @@ -1113,7 +1113,7 @@ int ieee80211_register_hw(struct ieee802 result = ieee80211_init_cipher_suites(local); if (result < 0) - goto fail_wiphy_register; + goto fail_workqueue; if (!local->ops->remain_on_channel) local->hw.wiphy->max_remain_on_channel_duration = 5000; @@ -1139,10 +1139,6 @@ int ieee80211_register_hw(struct ieee802 local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CSA_COUNTERS_NUM; - result = wiphy_register(local->hw.wiphy); - if (result < 0) - goto fail_wiphy_register; - /* * We use the number of queues for feature tests (QoS, HT) internally * so restrict them appropriately. @@ -1198,9 +1194,9 @@ int ieee80211_register_hw(struct ieee802 goto fail_flows; rtnl_lock(); - result = ieee80211_init_rate_ctrl_alg(local, hw->rate_control_algorithm); + rtnl_unlock(); if (result < 0) { wiphy_debug(local->hw.wiphy, "Failed to initialize rate control algorithm\n"); @@ -1254,6 +1250,12 @@ int ieee80211_register_hw(struct ieee802 local->sband_allocated |= BIT(band); } + result = wiphy_register(local->hw.wiphy); + if (result < 0) + goto fail_wiphy_register; + + rtnl_lock(); + /* add one default STA interface if supported */ if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION) && !ieee80211_hw_check(hw, NO_AUTO_VIF)) { @@ -1293,17 +1295,17 @@ int ieee80211_register_hw(struct ieee802 #if defined(CONFIG_INET) || defined(CONFIG_IPV6) fail_ifa: #endif + wiphy_unregister(local->hw.wiphy); + fail_wiphy_register: rtnl_lock(); rate_control_deinitialize(local); ieee80211_remove_interfaces(local); - fail_rate: rtnl_unlock(); + fail_rate: fail_flows: ieee80211_led_exit(local); destroy_workqueue(local->workqueue); fail_workqueue: - wiphy_unregister(local->hw.wiphy); - fail_wiphy_register: if (local->wiphy_ciphers_allocated) kfree(local->hw.wiphy->cipher_suites); kfree(local->int_scan_req); @@ -1353,8 +1355,8 @@ void ieee80211_unregister_hw(struct ieee skb_queue_purge(&local->skb_queue_unreliable); skb_queue_purge(&local->skb_queue_tdls_chsw); - destroy_workqueue(local->workqueue); wiphy_unregister(local->hw.wiphy); + destroy_workqueue(local->workqueue); ieee80211_led_exit(local); kfree(local->int_scan_req); }