Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2579870rdb; Wed, 15 Nov 2023 05:08:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0caxTOFeNDV8dkWCm0HXncVv1IiWMD82ardxTBF1OSmzOsIecjt/sxyWBb0aIYTj33Zpm X-Received: by 2002:a05:6a20:9381:b0:181:82f0:6f77 with SMTP id x1-20020a056a20938100b0018182f06f77mr1149936pzh.61.1700053707981; Wed, 15 Nov 2023 05:08:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700053707; cv=none; d=google.com; s=arc-20160816; b=kk20BQeKsZk6bAcdeWyMrBhvmN6RjMGP96CgFzAu0BJ49NJM0JEcCwfVtP3JUtmj6j tq7qVXeu+v+5eRc3r3FJ70mX9qh4TCaA5vIITvvubBKDmsOtdONODK3kGsAKEDV4uJ8f q0jTTz17e3MB9YxyHaRO+/Nl+uVbcpaA4Hu1FDaeiyOGV/N/Qs+U6yWuwgR7XoLj0hoT YYirmrNjTa9Okenobu5vxEeOui8NExCo2wB2EfDsWTqz7oEqaCkvW5OG3kSJCJ58x4O5 rnIToT0Oq1FuVT5maKBfLUR5Wjv2o3ABz/9lA7oGDqr1bxyT6p8vyi0F4s8H/67g56kB H0bA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=99AeEgO4YKKkqs5GbnXnOD1UmJxYdENFAMY89H21CxQ=; fh=vrOMOa9fxevIRncQTsrYzJN+mVaRbyoQYw3A51yr6WQ=; b=oT/jspyTsIXDcM8oPg0ohAIUac73K4AYQ5sq0uVsMtZbVgRB+G6rsBLvbOcZ5dpoZV mmde+gx+rV8eClou+T1pfTmAawfvfnhaaKGJ21Chv7ym1ZFE7jOiqAODZ+in/RVj454K 0ReUCS4ELE2iaCTWkWLSaRNEz68s5+5MUjTDNHjKJkfmJUfNmAg5YMIBdNYyXPVucJqJ zcEAQskz6S9Skk0X0WwssuO+GiRDfzUfywaY9mvPLsvvebStceEBjflPkP4b5dqjUd+3 9XGwxTxQtndBYuv36QcUXUmlOuVw9VG3zDDbTPuPCo+IyfXP7kv6sNVd5bNCu7alkNTT 2Svw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=wST83kiU; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id h63-20020a638342000000b005bd3056e1fcsi1787240pge.466.2023.11.15.05.08.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 05:08:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=wST83kiU; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D393180212E6; Wed, 15 Nov 2023 05:08:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343863AbjKONIW (ORCPT + 53 others); Wed, 15 Nov 2023 08:08:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343723AbjKONIV (ORCPT ); Wed, 15 Nov 2023 08:08:21 -0500 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:242:246e::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D94FDCE for ; Wed, 15 Nov 2023 05:08:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-To:Resent-Cc: Resent-Message-ID:In-Reply-To:References; bh=99AeEgO4YKKkqs5GbnXnOD1UmJxYdENFAMY89H21CxQ=; t=1700053697; x=1701263297; b=wST83kiUVPoBotj4FhlbC0uCXFT7Azu8EhFF9yxrpUe+9a6XML87TB3xa7XuMolxADuUk9oNtbM DuQCWBObbDReEo3MGuHhrt61gxnwGcieGstrAxAkEvVw66VM/xFvf65FTPs78JOL1RcoEaoHmzmkl s7KNYZSJxT8mjrG5y08cw0IwQ8UKzSIgeaZbDPa8g98T52HipY5n7E/b61a+oC1Y9hL18CFGMZMC8 ohwX9bBKnZ4fZoxCEBucOW2ZEob3N6OYME6zni+UqlUjCoU758Y6x0RGBmRUgfREnGJOlk9oCjo1z z8R/BK4k+RwgUwIFP2kNeQ6fcjrn/AX6ckdg==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97) (envelope-from ) id 1r3Fch-00000009BMD-3bnK; Wed, 15 Nov 2023 14:08:04 +0100 From: Johannes Berg To: linux-wireless@vger.kernel.org Cc: Johannes Berg , Johan Hovold Subject: [PATCH] wifi: cfg80211: hold wiphy mutex for send_interface Date: Wed, 15 Nov 2023 13:06:16 +0100 Message-ID: <20231115130615.b1ccadaf9e13.Ic207e2f99f806e9120278f92fdebc2822842c301@changeid> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 05:08:21 -0800 (PST) From: Johannes Berg Given all the locking rework in mac80211, we pretty much need to get into the driver with the wiphy mutex held in all callbacks. This is already mostly the case, but as Johan reported, in the get_txpower it may not be true. Lock the wiphy mutex around nl80211_send_iface(), then is also around callers of nl80211_notify_iface(). This is easy to do, fixes the problem, and aligns the locking between various calls to it in different parts of the code of cfg80211. Fixes: 0e8185ce1dde ("wifi: mac80211: check wiphy mutex in ops") Reported-by: Johan Hovold Closes: https://lore.kernel.org/r/ZVOXX6qg4vXEx8dX@hovoldconsulting.com Signed-off-by: Johannes Berg --- net/wireless/core.c | 4 ++-- net/wireless/nl80211.c | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index 758c9a2a12c0..1786ebc5e5cd 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -191,13 +191,13 @@ int cfg80211_switch_netns(struct cfg80211_registered_device *rdev, return err; } + wiphy_lock(&rdev->wiphy); list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { if (!wdev->netdev) continue; nl80211_notify_iface(rdev, wdev, NL80211_CMD_DEL_INTERFACE); } - wiphy_lock(&rdev->wiphy); nl80211_notify_wiphy(rdev, NL80211_CMD_DEL_WIPHY); wiphy_net_set(&rdev->wiphy, net); @@ -206,13 +206,13 @@ int cfg80211_switch_netns(struct cfg80211_registered_device *rdev, WARN_ON(err); nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY); - wiphy_unlock(&rdev->wiphy); list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { if (!wdev->netdev) continue; nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); } + wiphy_unlock(&rdev->wiphy); return 0; } diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 569234bc2be6..358ca88b5292 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -3822,6 +3822,8 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag struct net_device *dev = wdev->netdev; void *hdr; + lockdep_assert_wiphy(&rdev->wiphy); + WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && cmd != NL80211_CMD_DEL_INTERFACE && cmd != NL80211_CMD_SET_INTERFACE); @@ -3989,6 +3991,7 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback * if_idx = 0; + wiphy_lock(&rdev->wiphy); list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { if (if_idx < if_start) { if_idx++; @@ -3998,10 +4001,12 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback * cb->nlh->nlmsg_seq, NLM_F_MULTI, rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { + wiphy_unlock(&rdev->wiphy); goto out; } if_idx++; } + wiphy_unlock(&rdev->wiphy); wp_idx++; } -- 2.41.0