From owner-svn-src-stable-12@freebsd.org Sun Jun 14 05:25:07 2020 Return-Path: Delivered-To: svn-src-stable-12@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 34AD232F021; Sun, 14 Jun 2020 05:25:07 +0000 (UTC) (envelope-from hselasky@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49l2wM0bNkz3gF8; Sun, 14 Jun 2020 05:25:07 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EA1A8276BB; Sun, 14 Jun 2020 05:25:06 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 05E5P6ZW061061; Sun, 14 Jun 2020 05:25:06 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 05E5P6TB061059; Sun, 14 Jun 2020 05:25:06 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <202006140525.05E5P6TB061059@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Sun, 14 Jun 2020 05:25:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r362166 - stable/12/sys/dev/usb/net X-SVN-Group: stable-12 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: stable/12/sys/dev/usb/net X-SVN-Commit-Revision: 362166 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Jun 2020 05:25:07 -0000 Author: hselasky Date: Sun Jun 14 05:25:06 2020 New Revision: 362166 URL: https://svnweb.freebsd.org/changeset/base/362166 Log: MFC r362056: Add missing range checks when receiving USB ethernet packets. Found by: Ilja Van Sprundel, IOActive Sponsored by: Mellanox Technologies Modified: stable/12/sys/dev/usb/net/if_cdceem.c stable/12/sys/dev/usb/net/if_muge.c stable/12/sys/dev/usb/net/if_smsc.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/usb/net/if_cdceem.c ============================================================================== --- stable/12/sys/dev/usb/net/if_cdceem.c Sun Jun 14 05:08:15 2020 (r362165) +++ stable/12/sys/dev/usb/net/if_cdceem.c Sun Jun 14 05:25:06 2020 (r362166) @@ -426,9 +426,10 @@ cdceem_handle_data(struct usb_xfer *xfer, uint16_t hdr struct usb_ether *ue; struct ifnet *ifp; struct mbuf *m; - int actlen, off; uint32_t computed_crc, received_crc; - uint16_t pktlen; + int pktlen; + int actlen; + int off; off = *offp; sc = usbd_xfer_softc(xfer); @@ -442,7 +443,7 @@ cdceem_handle_data(struct usb_xfer *xfer, uint16_t hdr (hdr & CDCEEM_DATA_CRC) ? "valid" : "absent", pktlen); - if (pktlen < ETHER_HDR_LEN) { + if (pktlen < (ETHER_HDR_LEN + 4)) { CDCEEM_WARN(sc, "bad ethernet frame length %d, should be at least %d", pktlen, ETHER_HDR_LEN); @@ -466,6 +467,14 @@ cdceem_handle_data(struct usb_xfer *xfer, uint16_t hdr } pktlen -= 4; /* Subtract the CRC. */ + + if (pktlen > m->m_len) { + CDCEEM_WARN(sc, "buffer too small %d vs %d bytes", + pktlen, m->m_len); + if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); + m_freem(m); + return; + } usbd_copy_out(pc, off, mtod(m, uint8_t *), pktlen); off += pktlen; @@ -512,7 +521,7 @@ cdceem_bulk_read_callback(struct usb_xfer *xfer, usb_e pc = usbd_xfer_get_frame(xfer, 0); off = 0; - while (off < actlen) { + while ((off + sizeof(hdr)) <= actlen) { usbd_copy_out(pc, off, &hdr, sizeof(hdr)); CDCEEM_DEBUG(sc, "hdr = %#x", hdr); off += sizeof(hdr); Modified: stable/12/sys/dev/usb/net/if_muge.c ============================================================================== --- stable/12/sys/dev/usb/net/if_muge.c Sun Jun 14 05:08:15 2020 (r362165) +++ stable/12/sys/dev/usb/net/if_muge.c Sun Jun 14 05:25:06 2020 (r362166) @@ -1166,9 +1166,9 @@ muge_bulk_read_callback(struct usb_xfer *xfer, usb_err struct ifnet *ifp = uether_getifp(ue); struct mbuf *m; struct usb_page_cache *pc; - uint16_t pktlen; uint32_t rx_cmd_a, rx_cmd_b; uint16_t rx_cmd_c; + int pktlen; int off; int actlen; @@ -1246,7 +1246,14 @@ muge_bulk_read_callback(struct usb_xfer *xfer, usb_err 1); goto tr_setup; } - + if (pktlen > m->m_len) { + muge_dbg_printf(sc, + "buffer too small %d vs %d bytes", + pktlen, m->m_len); + if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); + m_freem(m); + goto tr_setup; + } usbd_copy_out(pc, off, mtod(m, uint8_t *), pktlen); Modified: stable/12/sys/dev/usb/net/if_smsc.c ============================================================================== --- stable/12/sys/dev/usb/net/if_smsc.c Sun Jun 14 05:08:15 2020 (r362165) +++ stable/12/sys/dev/usb/net/if_smsc.c Sun Jun 14 05:25:06 2020 (r362166) @@ -973,7 +973,7 @@ smsc_bulk_read_callback(struct usb_xfer *xfer, usb_err struct mbuf *m; struct usb_page_cache *pc; uint32_t rxhdr; - uint16_t pktlen; + int pktlen; int off; int actlen; @@ -999,6 +999,9 @@ smsc_bulk_read_callback(struct usb_xfer *xfer, usb_err /* The frame header is always aligned on a 4 byte boundary */ off = ((off + 0x3) & ~0x3); + if ((off + sizeof(rxhdr)) > actlen) + goto tr_setup; + usbd_copy_out(pc, off, &rxhdr, sizeof(rxhdr)); off += (sizeof(rxhdr) + ETHER_ALIGN); rxhdr = le32toh(rxhdr); @@ -1027,7 +1030,13 @@ smsc_bulk_read_callback(struct usb_xfer *xfer, usb_err if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); goto tr_setup; } - + if (pktlen > m->m_len) { + smsc_dbg_printf(sc, "buffer too small %d vs %d bytes", + pktlen, m->m_len); + if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1); + m_freem(m); + goto tr_setup; + } usbd_copy_out(pc, off, mtod(m, uint8_t *), pktlen); /* Check if RX TCP/UDP checksumming is being offloaded */