svn commit: r363921 - in releng: 11.3/sys/dev/usb/net 11.4/sys/dev/usb/net 12.1/sys/dev/usb/net
Gordon Tetlow
gordon at FreeBSD.org
Wed Aug 5 17:11:19 UTC 2020
Author: gordon
Date: Wed Aug 5 17:11:18 2020
New Revision: 363921
URL: https://svnweb.freebsd.org/changeset/base/363921
Log:
Fix memory corruption in USB network device drivers.
Approved by: so
Security: FreeBSD-SA-20:21.usb_net
Security: CVE-2020-7459
Modified:
releng/11.3/sys/dev/usb/net/if_smsc.c
releng/11.4/sys/dev/usb/net/if_smsc.c
releng/12.1/sys/dev/usb/net/if_cdceem.c
releng/12.1/sys/dev/usb/net/if_muge.c
releng/12.1/sys/dev/usb/net/if_smsc.c
Modified: releng/11.3/sys/dev/usb/net/if_smsc.c
==============================================================================
--- releng/11.3/sys/dev/usb/net/if_smsc.c Wed Aug 5 17:09:54 2020 (r363920)
+++ releng/11.3/sys/dev/usb/net/if_smsc.c Wed Aug 5 17:11:18 2020 (r363921)
@@ -970,7 +970,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;
@@ -996,6 +996,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);
@@ -1024,7 +1027,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 */
Modified: releng/11.4/sys/dev/usb/net/if_smsc.c
==============================================================================
--- releng/11.4/sys/dev/usb/net/if_smsc.c Wed Aug 5 17:09:54 2020 (r363920)
+++ releng/11.4/sys/dev/usb/net/if_smsc.c Wed Aug 5 17:11:18 2020 (r363921)
@@ -970,7 +970,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;
@@ -996,6 +996,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);
@@ -1024,7 +1027,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 */
Modified: releng/12.1/sys/dev/usb/net/if_cdceem.c
==============================================================================
--- releng/12.1/sys/dev/usb/net/if_cdceem.c Wed Aug 5 17:09:54 2020 (r363920)
+++ releng/12.1/sys/dev/usb/net/if_cdceem.c Wed Aug 5 17:11:18 2020 (r363921)
@@ -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: releng/12.1/sys/dev/usb/net/if_muge.c
==============================================================================
--- releng/12.1/sys/dev/usb/net/if_muge.c Wed Aug 5 17:09:54 2020 (r363920)
+++ releng/12.1/sys/dev/usb/net/if_muge.c Wed Aug 5 17:11:18 2020 (r363921)
@@ -1167,9 +1167,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;
@@ -1251,7 +1251,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: releng/12.1/sys/dev/usb/net/if_smsc.c
==============================================================================
--- releng/12.1/sys/dev/usb/net/if_smsc.c Wed Aug 5 17:09:54 2020 (r363920)
+++ releng/12.1/sys/dev/usb/net/if_smsc.c Wed Aug 5 17:11:18 2020 (r363921)
@@ -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 */
More information about the svn-src-releng
mailing list