Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2172659iof; Tue, 7 Jun 2022 22:08:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJ5GGoQFQkSOIHQhjBSvuOG4m3Ru6PymT1Z8vDlR5WA4dvaSkVbTeGrWL6ejizDwMpEjZ6 X-Received: by 2002:a63:2c8a:0:b0:3fa:6b31:5918 with SMTP id s132-20020a632c8a000000b003fa6b315918mr27627871pgs.485.1654664903189; Tue, 07 Jun 2022 22:08:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654664903; cv=none; d=google.com; s=arc-20160816; b=CTKLiivTIV50OLIgZ6sXg/FgYt43N/juxzxzETGXwbvo/QR3fznuz3TCP4I+bT5Xmr L/CADTdjIEpDNUEiIIN+dPGD8+4yvNhyY2nZTNsuafK/dHAZ3gymmGd4Bm1VcqvHUFGF gevr+GZyfVXmOTtcmVIhdaluAcADUQ0YPGEWyL3TE1QlBOMuvPU7TD3KMKNgRtjAduWb 5WJ2GO9LJyArICAwDxdUgwYpfBCGl25uqf4cYf7eaE4n0OsUisuZF4OcHt8pqsBMZ2Ej 3277k+g+VGtqDPKiQaXl5o+20kBmZ8+2kJNs0W2BXzwvbXrT0W6yea09VlQqkOJOnzhy 9Aig== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FVzVLFqrGGA0cLptCn83gQFxQaGxPwN44eAn8zE9RYI=; b=y7RUJBCL2GTeWRJDcYf7dUSdT3kdD/krXFp5toyML/jWzbDNJP+ZTnVByB8Cgd3MXj w2nLZ5HMUkH2GAHkNuhEA1CSBt/WsFKlDCKmFf+fr5K4sJVsex61XXVk+SpT/cWObL39 ct+rJfEzcy2y54j5C7JH6kN5FlkPbF9Y1rDn6ixkFw6WUQ9okZ9dqDGwVeRi2guSy29N 7X/hcn5GH1d/lAWv5MRQvnsiFmxWopFZVFz7tiSUs9bTL2p57JNuKGKOG+/DylTXZPha yuWe9Ezsbfqc4w64Mk7Gn9fncQ+9zW+2hVvNblIsJR0ck+kXqIBx8kQ4fY7U9eDB46eS ecWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fMTP545x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b71-20020a621b4a000000b0051b291c277asi24738244pfb.36.2022.06.07.22.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:08:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fMTP545x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BE19C3B4EED; Tue, 7 Jun 2022 21:35:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384095AbiFGWOx (ORCPT + 99 others); Tue, 7 Jun 2022 18:14:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380117AbiFGVLb (ORCPT ); Tue, 7 Jun 2022 17:11:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C0A2178A4; Tue, 7 Jun 2022 11:53:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0FB2EB81F6D; Tue, 7 Jun 2022 18:53:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BD70C385A2; Tue, 7 Jun 2022 18:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627991; bh=67f36S+4rjT+JdsrzBc14AqQKTdEkAdczFOtEskmpRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fMTP545xExRWOgun2l5fN5CCI5ZJ4mdLF3QRC///R4TslD17sQG0/TcFAPZ0ozlPW 097f61iRXIhuY8Cp9gjzO0I9gtf6XIglocR+8XkrUsCoSqC3bVDWO6VRyvSj+FcZLG bX1gF28Ek/j7eSWWelFp5bcdlMKwie7j35QtHXoE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Oliver Neukum , Martyn Welch , Andrew Lunn , "David S. Miller" , Sasha Levin , Oleksij Rempel , Ferry Toth Subject: [PATCH 5.18 168/879] usbnet: Run unregister_netdev() before unbind() again Date: Tue, 7 Jun 2022 18:54:46 +0200 Message-Id: <20220607165007.586261372@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lukas Wunner [ 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 # LAN9514/9512/9500 Tested-by: Ferry Toth # LAN9514 Signed-off-by: Lukas Wunner Acked-by: Oliver Neukum Cc: Martyn Welch Cc: Andrew Lunn Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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