From owner-dev-commits-src-all@freebsd.org Wed Jun 2 12:24:50 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E09C76418D9; Wed, 2 Jun 2021 12:24:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Fw7Wk5Jsdz3Frk; Wed, 2 Jun 2021 12:24:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9ABAD16D95; Wed, 2 Jun 2021 12:24:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 152COoMS019143; Wed, 2 Jun 2021 12:24:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 152COoPi019142; Wed, 2 Jun 2021 12:24:50 GMT (envelope-from git) Date: Wed, 2 Jun 2021 12:24:50 GMT Message-Id: <202106021224.152COoPi019142@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Hans Petter Selasky Subject: git: 9f98b3ea746f - stable/13 - Fix for use-after-free by if_ioctl() calls from user-space in USB drivers by detaching the ifnet before the miibus. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9f98b3ea746f97b61d37f1c11d0e7abb3cd81305 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jun 2021 12:24:51 -0000 The branch stable/13 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=9f98b3ea746f97b61d37f1c11d0e7abb3cd81305 commit 9f98b3ea746f97b61d37f1c11d0e7abb3cd81305 Author: Hans Petter Selasky AuthorDate: 2021-01-12 17:51:09 +0000 Commit: Hans Petter Selasky CommitDate: 2021-06-02 11:25:19 +0000 Fix for use-after-free by if_ioctl() calls from user-space in USB drivers by detaching the ifnet before the miibus. PR: 252608 Suggested by: jhb@ Sponsored by: Mellanox Technologies // NVIDIA Networking (cherry picked from commit 4eac63af23ddafc2b1dfb2aad2896f4513c37cdd) --- sys/dev/usb/net/uhso.c | 2 +- sys/dev/usb/net/usb_ethernet.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sys/dev/usb/net/uhso.c b/sys/dev/usb/net/uhso.c index c72fa8d7a36b..4ff5fcc075d3 100644 --- a/sys/dev/usb/net/uhso.c +++ b/sys/dev/usb/net/uhso.c @@ -691,10 +691,10 @@ uhso_detach(device_t self) free_unr(uhso_ifnet_unit, sc->sc_ifp->if_dunit); mtx_lock(&sc->sc_mtx); uhso_if_stop(sc); + mtx_unlock(&sc->sc_mtx); bpfdetach(sc->sc_ifp); if_detach(sc->sc_ifp); if_free(sc->sc_ifp); - mtx_unlock(&sc->sc_mtx); usbd_transfer_unsetup(sc->sc_if_xfer, UHSO_IFNET_MAX); } diff --git a/sys/dev/usb/net/usb_ethernet.c b/sys/dev/usb/net/usb_ethernet.c index e1eb2c247b5a..33659049f970 100644 --- a/sys/dev/usb/net/usb_ethernet.c +++ b/sys/dev/usb/net/usb_ethernet.c @@ -319,6 +319,12 @@ uether_ifdetach(struct usb_ether *ue) /* drain any callouts */ usb_callout_drain(&ue->ue_watchdog); + /* + * Detach ethernet first to stop miibus calls from + * user-space: + */ + ether_ifdetach(ifp); + /* detach miibus */ if (ue->ue_miibus != NULL) { mtx_lock(&Giant); /* device_xxx() depends on this */ @@ -326,9 +332,6 @@ uether_ifdetach(struct usb_ether *ue) mtx_unlock(&Giant); } - /* detach ethernet */ - ether_ifdetach(ifp); - /* free interface instance */ if_free(ifp);