netdev.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: Lukas Wunner <lukas@wunner.de>,
	Oleksij Rempel <o.rempel@pengutronix.de>,
	Ferry Toth <fntoth@gmail.com>, Oliver Neukum <oneukum@suse.com>,
	Martyn Welch <martyn.welch@collabora.com>,
	Andrew Lunn <andrew@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Sasha Levin <sashal@kernel.org>,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	steve.glendinning@shawell.net, UNGLinuxDriver@microchip.com,
	linux@rempel-privat.de, colin.king@intel.com,
	paskripkin@gmail.com, linux-usb@vger.kernel.org,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.18 118/159] usbnet: Run unregister_netdev() before unbind() again
Date: Mon, 30 May 2022 09:23:43 -0400	[thread overview]
Message-ID: <20220530132425.1929512-118-sashal@kernel.org> (raw)
In-Reply-To: <20220530132425.1929512-1-sashal@kernel.org>

From: Lukas Wunner <lukas@wunner.de>

[ Upstream commit d1408f6b4dd78fb1b9e26bcf64477984e5f85409 ]

Commit 2c9d6c2b871d ("usbnet: run unbind() before unregister_netdev()")
sought to fix a use-after-free on disconnect of USB Ethernet adapters.

It turns out that a different fix is necessary to address the issue:
https://lore.kernel.org/netdev/18b3541e5372bc9b9fc733d422f4e698c089077c.1650177997.git.lukas@wunner.de/

So the commit was not necessary.

The commit made binding and unbinding of USB Ethernet asymmetrical:
Before, usbnet_probe() first invoked the ->bind() callback and then
register_netdev().  usbnet_disconnect() mirrored that by first invoking
unregister_netdev() and then ->unbind().

Since the commit, the order in usbnet_disconnect() is reversed and no
longer mirrors usbnet_probe().

One consequence is that a PHY disconnected (and stopped) in ->unbind()
is afterwards stopped once more by unregister_netdev() as it closes the
netdev before unregistering.  That necessitates a contortion in ->stop()
because the PHY may only be stopped if it hasn't already been
disconnected.

Reverting the commit allows making the call to phy_stop() unconditional
in ->stop().

Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> # LAN9514/9512/9500
Tested-by: Ferry Toth <fntoth@gmail.com> # LAN9514
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Acked-by: Oliver Neukum <oneukum@suse.com>
Cc: Martyn Welch <martyn.welch@collabora.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/usb/asix_devices.c | 6 +-----
 drivers/net/usb/smsc95xx.c     | 3 +--
 drivers/net/usb/usbnet.c       | 6 +++---
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 38e47a93fb83..5b5eb630c4b7 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -795,11 +795,7 @@ static int ax88772_stop(struct usbnet *dev)
 {
 	struct asix_common_private *priv = dev->driver_priv;
 
-	/* On unplugged USB, we will get MDIO communication errors and the
-	 * PHY will be set in to PHY_HALTED state.
-	 */
-	if (priv->phydev->state != PHY_HALTED)
-		phy_stop(priv->phydev);
+	phy_stop(priv->phydev);
 
 	return 0;
 }
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 4ef61f6b85df..edf0492ad489 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -1243,8 +1243,7 @@ static int smsc95xx_start_phy(struct usbnet *dev)
 
 static int smsc95xx_stop(struct usbnet *dev)
 {
-	if (dev->net->phydev)
-		phy_stop(dev->net->phydev);
+	phy_stop(dev->net->phydev);
 
 	return 0;
 }
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 9a6450f796dc..36b24ec11650 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1616,9 +1616,6 @@ void usbnet_disconnect (struct usb_interface *intf)
 		   xdev->bus->bus_name, xdev->devpath,
 		   dev->driver_info->description);
 
-	if (dev->driver_info->unbind)
-		dev->driver_info->unbind(dev, intf);
-
 	net = dev->net;
 	unregister_netdev (net);
 
@@ -1626,6 +1623,9 @@ void usbnet_disconnect (struct usb_interface *intf)
 
 	usb_scuttle_anchored_urbs(&dev->deferred);
 
+	if (dev->driver_info->unbind)
+		dev->driver_info->unbind(dev, intf);
+
 	usb_kill_urb(dev->interrupt);
 	usb_free_urb(dev->interrupt);
 	kfree(dev->padding_pkt);
-- 
2.35.1


  parent reply	other threads:[~2022-05-30 13:37 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220530132425.1929512-1-sashal@kernel.org>
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 004/159] ath11k: fix the warning of dev_wake in mhi_pm_disable_transition() Sasha Levin
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 006/159] selftests/bpf: Fix vfs_link kprobe definition Sasha Levin
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 007/159] selftests/bpf: Fix parsing of prog types in UAPI hdr for bpftool sync Sasha Levin
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 008/159] ath11k: Change max no of active probe SSID and BSSID to fw capability Sasha Levin
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 009/159] selftests/bpf: Fix file descriptor leak in load_kallsyms() Sasha Levin
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 010/159] rtw89: ser: fix CAM leaks occurring in L2 reset Sasha Levin
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 011/159] rtw89: fix misconfiguration on hw_scan channel time Sasha Levin
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 012/159] mwifiex: add mutex lock for call in mwifiex_dfs_chan_sw_work_queue Sasha Levin
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 013/159] b43legacy: Fix assigning negative value to unsigned variable Sasha Levin
2022-05-30 13:21 ` [PATCH AUTOSEL 5.18 014/159] b43: " Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 015/159] ipw2x00: Fix potential NULL dereference in libipw_xmit() Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 016/159] ipv6: fix locking issues with loops over idev->addr_list Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 020/159] libbpf: Fix a bug with checking bpf_probe_read_kernel() support in old kernels Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 021/159] mac80211: minstrel_ht: fix where rate stats are stored (fixes debugfs output) Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 027/159] sfc: ef10: Fix assigning negative value to unsigned variable Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 029/159] rtw88: fix incorrect frequency reported Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 030/159] rtw88: 8821c: fix debugfs rssi value Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 033/159] tcp: consume incoming skb leading to a reset Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 040/159] net: sched: use queue_mapping to pick tx queue Sasha Levin
2022-05-30 18:10   ` Jakub Kicinski
2022-06-05 12:55     ` Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 046/159] net: macb: In ZynqMP initialization make SGMII phy configuration optional Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 047/159] ath9k: fix QCA9561 PA bias level Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 062/159] ath11k: disable spectral scan during spectral deinit Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 068/159] ath10k: skip ath10k_halt during suspend for driver state RESTARTING Sasha Levin
2022-05-30 13:22 ` [PATCH AUTOSEL 5.18 073/159] ath11k: fix warning of not found station for bssid in message Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 075/159] ipv6: Don't send rs packets to the interface of ARPHRD_TUNNEL Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 076/159] net/mlx5: use kvfree() for kvzalloc() in mlx5_ct_fs_smfs_matcher_create Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 077/159] net/mlx5: fs, delete the FTE when there are no rules attached to it Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 080/159] mlxsw: spectrum_dcb: Do not warn about priority changes Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 081/159] mlxsw: Treat LLDP packets as control Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 085/159] ice: always check VF VSI pointer values Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 090/159] net/mlx5: Increase FW pre-init timeout for health recovery Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 095/159] net: remove two BUG() from skb_checksum_help() Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 108/159] rtlwifi: Use pr_warn instead of WARN_ONCE Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 109/159] mt76: mt7915: accept rx frames with non-standard VHT MCS10-11 Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 110/159] mt76: mt7921: " Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 111/159] mt76: fix encap offload ethernet type check Sasha Levin
2022-05-30 13:23 ` Sasha Levin [this message]
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 119/159] Bluetooth: HCI: Add HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN quirk Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 122/159] bnxt_en: Configure ptp filters during bnxt open Sasha Levin
2022-05-30 13:23 ` [PATCH AUTOSEL 5.18 134/159] net: phy: micrel: Allow probing without .driver_data Sasha Levin
2022-05-30 13:24 ` [PATCH AUTOSEL 5.18 137/159] rtw89: cfo: check mac_id to avoid out-of-bounds Sasha Levin
2022-05-30 13:24 ` [PATCH AUTOSEL 5.18 144/159] can: mcp251xfd: silence clang's -Wunaligned-access warning Sasha Levin
2022-05-30 13:24 ` [PATCH AUTOSEL 5.18 146/159] net: ipa: ignore endianness if there is no header Sasha Levin
2022-05-30 13:24 ` [PATCH AUTOSEL 5.18 148/159] selftests/bpf: Add missing trampoline program type to trampoline_count test Sasha Levin
2022-05-30 13:24 ` [PATCH AUTOSEL 5.18 152/159] rxrpc: Return an error to sendmsg if call failed Sasha Levin
2022-05-30 13:24 ` [PATCH AUTOSEL 5.18 153/159] rxrpc, afs: Fix selection of abort codes Sasha Levin
2022-05-30 13:24 ` [PATCH AUTOSEL 5.18 154/159] afs: Adjust ACK interpretation to try and cope with NAT Sasha Levin
2022-05-30 13:24 ` [PATCH AUTOSEL 5.18 155/159] eth: tg3: silence the GCC 12 array-bounds warning Sasha Levin
2022-05-30 13:24 ` [PATCH AUTOSEL 5.18 157/159] selftests/bpf: fix btf_dump/btf_dump due to recent clang change 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=20220530132425.1929512-118-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=colin.king@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fntoth@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@rempel-privat.de \
    --cc=lukas@wunner.de \
    --cc=martyn.welch@collabora.com \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=oneukum@suse.com \
    --cc=pabeni@redhat.com \
    --cc=paskripkin@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=steve.glendinning@shawell.net \
    /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).