linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Johannes Berg <johannes.berg@intel.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.9 23/55] cfg80211: initialize wdev data earlier
Date: Mon,  9 Nov 2020 22:52:46 -0500	[thread overview]
Message-ID: <20201110035318.423757-23-sashal@kernel.org> (raw)
In-Reply-To: <20201110035318.423757-1-sashal@kernel.org>

From: Johannes Berg <johannes.berg@intel.com>

[ Upstream commit 9bdaf3b91efd229dd272b228e13df10310c80d19 ]

There's a race condition in the netdev registration in that
NETDEV_REGISTER actually happens after the netdev is available,
and so if we initialize things only there, we might get called
with an uninitialized wdev through nl80211 - not using a wdev
but using a netdev interface index.

I found this while looking into a syzbot report, but it doesn't
really seem to be related, and unfortunately there's no repro
for it (yet). I can't (yet) explain how it managed to get into
cfg80211_release_pmsr() from nl80211_netlink_notify() without
the wdev having been initialized, as the latter only iterates
the wdevs that are linked into the rdev, which even without the
change here happened after init.

However, looking at this, it seems fairly clear that the init
needs to be done earlier, otherwise we might even re-init on a
netns move, when data might still be pending.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Link: https://lore.kernel.org/r/20201009135821.fdcbba3aad65.Ie9201d91dbcb7da32318812effdc1561aeaf4cdc@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/wireless/core.c    | 57 +++++++++++++++++++++++-------------------
 net/wireless/core.h    |  5 ++--
 net/wireless/nl80211.c |  3 ++-
 3 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/net/wireless/core.c b/net/wireless/core.c
index 354b0ccbdc240..e025493171262 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -1248,8 +1248,7 @@ void cfg80211_stop_iface(struct wiphy *wiphy, struct wireless_dev *wdev,
 }
 EXPORT_SYMBOL(cfg80211_stop_iface);
 
-void cfg80211_init_wdev(struct cfg80211_registered_device *rdev,
-			struct wireless_dev *wdev)
+void cfg80211_init_wdev(struct wireless_dev *wdev)
 {
 	mutex_init(&wdev->mtx);
 	INIT_LIST_HEAD(&wdev->event_list);
@@ -1260,6 +1259,30 @@ void cfg80211_init_wdev(struct cfg80211_registered_device *rdev,
 	spin_lock_init(&wdev->pmsr_lock);
 	INIT_WORK(&wdev->pmsr_free_wk, cfg80211_pmsr_free_wk);
 
+#ifdef CONFIG_CFG80211_WEXT
+	wdev->wext.default_key = -1;
+	wdev->wext.default_mgmt_key = -1;
+	wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
+#endif
+
+	if (wdev->wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT)
+		wdev->ps = true;
+	else
+		wdev->ps = false;
+	/* allow mac80211 to determine the timeout */
+	wdev->ps_timeout = -1;
+
+	if ((wdev->iftype == NL80211_IFTYPE_STATION ||
+	     wdev->iftype == NL80211_IFTYPE_P2P_CLIENT ||
+	     wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr)
+		wdev->netdev->priv_flags |= IFF_DONT_BRIDGE;
+
+	INIT_WORK(&wdev->disconnect_wk, cfg80211_autodisconnect_wk);
+}
+
+void cfg80211_register_wdev(struct cfg80211_registered_device *rdev,
+			    struct wireless_dev *wdev)
+{
 	/*
 	 * We get here also when the interface changes network namespaces,
 	 * as it's registered into the new one, but we don't want it to
@@ -1293,6 +1316,11 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
 	switch (state) {
 	case NETDEV_POST_INIT:
 		SET_NETDEV_DEVTYPE(dev, &wiphy_type);
+		wdev->netdev = dev;
+		/* can only change netns with wiphy */
+		dev->features |= NETIF_F_NETNS_LOCAL;
+
+		cfg80211_init_wdev(wdev);
 		break;
 	case NETDEV_REGISTER:
 		/*
@@ -1300,35 +1328,12 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
 		 * called within code protected by it when interfaces
 		 * are added with nl80211.
 		 */
-		/* can only change netns with wiphy */
-		dev->features |= NETIF_F_NETNS_LOCAL;
-
 		if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
 				      "phy80211")) {
 			pr_err("failed to add phy80211 symlink to netdev!\n");
 		}
-		wdev->netdev = dev;
-#ifdef CONFIG_CFG80211_WEXT
-		wdev->wext.default_key = -1;
-		wdev->wext.default_mgmt_key = -1;
-		wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
-#endif
-
-		if (wdev->wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT)
-			wdev->ps = true;
-		else
-			wdev->ps = false;
-		/* allow mac80211 to determine the timeout */
-		wdev->ps_timeout = -1;
-
-		if ((wdev->iftype == NL80211_IFTYPE_STATION ||
-		     wdev->iftype == NL80211_IFTYPE_P2P_CLIENT ||
-		     wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr)
-			dev->priv_flags |= IFF_DONT_BRIDGE;
-
-		INIT_WORK(&wdev->disconnect_wk, cfg80211_autodisconnect_wk);
 
-		cfg80211_init_wdev(rdev, wdev);
+		cfg80211_register_wdev(rdev, wdev);
 		break;
 	case NETDEV_GOING_DOWN:
 		cfg80211_leave(rdev, wdev);
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 67b0389fca4dc..8cd4a9793298e 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -208,8 +208,9 @@ struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
 int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
 			  struct net *net);
 
-void cfg80211_init_wdev(struct cfg80211_registered_device *rdev,
-			struct wireless_dev *wdev);
+void cfg80211_init_wdev(struct wireless_dev *wdev);
+void cfg80211_register_wdev(struct cfg80211_registered_device *rdev,
+			    struct wireless_dev *wdev);
 
 static inline void wdev_lock(struct wireless_dev *wdev)
 	__acquires(wdev)
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index e14307f2bddcc..8eb43c47e582a 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -3801,7 +3801,8 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
 		 * P2P Device and NAN do not have a netdev, so don't go
 		 * through the netdev notifier and must be added here
 		 */
-		cfg80211_init_wdev(rdev, wdev);
+		cfg80211_init_wdev(wdev);
+		cfg80211_register_wdev(rdev, wdev);
 		break;
 	default:
 		break;
-- 
2.27.0


  parent reply	other threads:[~2020-11-10  3:53 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-10  3:52 [PATCH AUTOSEL 5.9 01/55] ASoC: mediatek: mt8183-da7219: fix DAPM paths for rt1015 Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 02/55] ASoC: qcom: sdm845: set driver name correctly Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 03/55] ASoC: cs42l51: manage mclk shutdown delay Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 04/55] ASoC: SOF: loader: handle all SOF_IPC_EXT types Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 05/55] usb: dwc3: pci: add support for the Intel Alder Lake-S Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 06/55] opp: Reduce the size of critical section in _opp_table_kref_release() Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 07/55] usb: gadget: goku_udc: fix potential crashes in probe Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 08/55] usb: raw-gadget: fix memory leak in gadget_setup Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 09/55] selftests/ftrace: check for do_sys_openat2 in user-memory test Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 10/55] selftests: pidfd: fix compilation errors due to wait.h Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 11/55] ALSA: hda: Separate runtime and system suspend Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 12/55] ALSA: hda: Reinstate runtime_allow() for all hda controllers Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 13/55] x86/boot/compressed/64: Introduce sev_status Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 14/55] gfs2: Free rd_bits later in gfs2_clear_rgrpd to fix use-after-free Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 15/55] gfs2: Add missing truncate_inode_pages_final for sd_aspace Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 16/55] gfs2: check for live vs. read-only file system in gfs2_fitrim Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 17/55] scsi: hpsa: Fix memory leak in hpsa_init_one() Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 18/55] drm/amdgpu: perform srbm soft reset always on SDMA resume Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 19/55] drm/amd/pm: correct the baco reset sequence for CI ASICs Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 20/55] drm/amd/pm: perform SMC reset on suspend/hibernation Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 21/55] drm/amd/pm: do not use ixFEATURE_STATUS for checking smc running Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 22/55] mac80211: fix use of skb payload instead of header Sasha Levin
2020-11-10  3:52 ` Sasha Levin [this message]
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 24/55] mac80211: always wind down STA state Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 25/55] cfg80211: regulatory: Fix inconsistent format argument Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 26/55] wireguard: selftests: check that route_me_harder packets use the right sk Sasha Levin
2020-11-10 12:29   ` Jason A. Donenfeld
2020-11-10 17:21     ` Greg KH
2020-11-13 22:40       ` Jason A. Donenfeld
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 27/55] tracing: Fix the checking of stackidx in __ftrace_trace_stack Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 28/55] Revert "nvme-pci: remove last_sq_tail" Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 29/55] ARC: [plat-hsdk] Remap CCMs super early in asm boot trampoline Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 30/55] scsi: scsi_dh_alua: Avoid crash during alua_bus_detach() Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 31/55] scsi: mpt3sas: Fix timeouts observed while reenabling IRQ Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 32/55] nvme: introduce nvme_sync_io_queues Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 33/55] nvme-rdma: avoid race between time out and tear down Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 34/55] nvme-tcp: " Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 35/55] nvme-rdma: avoid repeated request completion Sasha Levin
2020-11-10  3:52 ` [PATCH AUTOSEL 5.9 36/55] nvme-tcp: " Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 37/55] iommu/amd: Increase interrupt remapping table limit to 512 entries Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 38/55] s390/smp: move rcu_cpu_starting() earlier Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 39/55] vfio: platform: fix reference leak in vfio_platform_open Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 40/55] vfio/pci: Bypass IGD init in case of -ENODEV Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 41/55] i2c: mediatek: move dma reset before i2c reset Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 42/55] net: usb: qmi_wwan: add Telit LE910Cx 0x1230 composition Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 43/55] amd/amdgpu: Disable VCN DPG mode for Picasso Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 44/55] kprobes: Tell lockdep about kprobe nesting Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 45/55] iomap: clean up writeback state logic on writepage error Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 46/55] selftests: proc: fix warning: _GNU_SOURCE redefined Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 47/55] arm64: kexec_file: try more regions if loading segments fails Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 48/55] riscv: Set text_offset correctly for M-Mode Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 49/55] i2c: sh_mobile: implement atomic transfers Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 50/55] i2c: designware: call i2c_dw_read_clear_intrbits_slave() once Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 51/55] i2c: designware: slave should do WRITE_REQUESTED before WRITE_RECEIVED Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 52/55] tpm_tis: Disable interrupts on ThinkPad T490s Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 53/55] seq_file: add seq_read_iter Sasha Levin
2020-11-10  6:30   ` Greg Kroah-Hartman
2020-11-10  9:05   ` Christoph Hellwig
2020-11-10 17:35     ` Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 54/55] vt: Disable KD_FONT_OP_COPY Sasha Levin
2020-11-10  3:53 ` [PATCH AUTOSEL 5.9 55/55] fork: fix copy_process(CLONE_PARENT) race with the exiting ->real_parent Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201110035318.423757-23-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=johannes.berg@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).