From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EBD3C11F6A for ; Tue, 6 Jul 2021 11:44:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 789BD61F6A for ; Tue, 6 Jul 2021 11:44:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237359AbhGFLoP (ORCPT ); Tue, 6 Jul 2021 07:44:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:42402 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235654AbhGFLaR (ORCPT ); Tue, 6 Jul 2021 07:30:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3147F61DCA; Tue, 6 Jul 2021 11:21:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625570489; bh=i9LbO88BQlRz9UewtnHD4ToRZXkZ1jIba8GKpBuY0pk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CMfhmf3hyheNyBMalAWHPOQ71uzZ2nMMIEeNbf/AKjkiDJrlglW+LkQNHjHaIxB7/ C7zZE+VG82+9Y9WWcElBg/H6Nbvk563y0/uHe7DEYREjDgAL9noOWdXE4YzaNLc1hz XWSehGflOAyEyg5/K9r7+THkx28ySD638JXiSduOhPC3N7syxGf0AHWzF0z/lzsMsw dlk6m9wdu1/UBnJlJva0Hoi3ksO0huCUGmRhjnYq5Bf+BwyUpz2U5OlGFIH6lgAnuj O6uBkKkCNszqgvNkOZ7R3E6MnmdsLASbYwlIC23RWPWEURbZfVpri5PW7nrunfZXz1 MB9+5yvIXSFyA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ilan Peer , Luca Coelho , Johannes Berg , Sasha Levin , linux-wireless@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.12 136/160] mac80211: Properly WARN on HW scan before restart Date: Tue, 6 Jul 2021 07:18:02 -0400 Message-Id: <20210706111827.2060499-136-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210706111827.2060499-1-sashal@kernel.org> References: <20210706111827.2060499-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilan Peer [ Upstream commit 45daaa1318410794de956fb8e9d06aed2dbb23d0 ] The following race was possible: 1. The device driver requests HW restart. 2. A scan is requested from user space and is propagated to the driver. During this flow HW_SCANNING flag is set. 3. The thread that handles the HW restart is scheduled, and before starting the actual reconfiguration it checks that HW_SCANNING is not set. The flow does so without acquiring any lock, and thus the WARN fires. Fix this by checking that HW_SCANNING is on only after RTNL is acquired, i.e., user space scan request handling is no longer in transit. Signed-off-by: Ilan Peer Signed-off-by: Luca Coelho Link: https://lore.kernel.org/r/iwlwifi.20210618133832.8238ab3e19ab.I2693c581c70251472b4f9089e37e06fb2c18268f@changeid Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- net/mac80211/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net/mac80211/main.c b/net/mac80211/main.c index 9dd741b68f26..937a024a13e2 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -257,14 +257,13 @@ static void ieee80211_restart_work(struct work_struct *work) /* wait for scan work complete */ flush_workqueue(local->workqueue); flush_work(&local->sched_scan_stopped_work); + flush_work(&local->radar_detected_work); + + rtnl_lock(); WARN(test_bit(SCAN_HW_SCANNING, &local->scanning), "%s called with hardware scan in progress\n", __func__); - flush_work(&local->radar_detected_work); - /* we might do interface manipulations, so need both */ - rtnl_lock(); - wiphy_lock(local->hw.wiphy); list_for_each_entry(sdata, &local->interfaces, list) { /* * XXX: there may be more work for other vif types and even -- 2.30.2