From nobody Wed Aug 17 17:02:22 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4M7DpQ63prz4YgrF; Wed, 17 Aug 2022 17:02:22 +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 4M7DpQ5WRRz3svm; Wed, 17 Aug 2022 17:02:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660755742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=e0XtIQZdKNMZFohMzrZZu6ZlE2NgiEsA+auX2eE9BdM=; b=R4juXSSQg/qwLaX8MotjI98+Um/Qkhm9y9w3dOclv8vamg2L+1OCA2O8dXeGDTR8GttIBS tsUt7RBfgnAoLkq6C42ibhuJzIxCZX/tAo1NlnEDsi2KPDFG/ELCYz6V9VKKb2dCtLIEq8 brOiRf365EvdIlVhp0ApTGkP1qdhjuAKdx67HEDjLj5XXcNhW08vdTRIQZ+rxz2rZ9xAK+ 4EBRGH2Qpmvs0xiQxG3FaNdhI3/2de2tasVTjGY4VbfDqCeokjFZXVVUT+5DCe0ixP/RlO +wWvb9g9dBzPP0zLaV/c3wXeIdfz1NfqM2b6o2ohwCbbAgb38AI61cSBeJWvAQ== 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 4M7DpQ4YDpzxB2; Wed, 17 Aug 2022 17:02:22 +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 27HH2M7a055801; Wed, 17 Aug 2022 17:02:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27HH2MXw055800; Wed, 17 Aug 2022 17:02:22 GMT (envelope-from git) Date: Wed, 17 Aug 2022 17:02:22 GMT Message-Id: <202208171702.27HH2MXw055800@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: fa46f3704b76 - main - bhyve e1000: Skip packets with a small header. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fa46f3704b7618f9d9493c126df781faf59040a8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660755742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=e0XtIQZdKNMZFohMzrZZu6ZlE2NgiEsA+auX2eE9BdM=; b=ejd5ck+ZQmdrd4Q4hjGtk5ko+Xcoaais453D6XL9Hv9zEW4Ts7X5RLGeGaCltIQu7VTlbX IVazeXHWHSohxfMfbPSr1MfIzvThK9UW4nek/1ZPHkO7VFFR2aY8wyPiqrO2eqN4YzHzJl R70iNQpZzaNDE2uvJ3N1tF9b14upJnmBO1KVb/yMZXxZ0wt6swhTY0+fVE8WIOiJFEeCs3 y8qOoVagkVkCEd8DMVERelQMjP/N7KIRWjZgOv8SHY/X7Aklu22SIiw9ea26SVt6kDmR2h UC+LxzBc+7nJpIss1gUa8fON0+t+UhLO7PITLmW8ZI84iscKfxBOqxwgHh1QPg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660755742; a=rsa-sha256; cv=none; b=QAZlrElcf7jvepz3c7vngRK2xRsf0SUP87+Pd5E9HqJWXp/RuZakK4dGzyOysS92ATyOuj 7447/16ZpXk7Yf9V0L0CR92nX67dfOUPFuIPPvJgYDqH9wO4NJmAzOmGib+xwOZujURE3G 0LWvdFaGDv3d79S07TrFSAePptWLrE7YszoaCnCOmW0mfx+CsjJt0wa3dGQLPIv22mvdnz /xWZEk/bUoE1PCMs6zhC2ywwGb8aKBVT9mIA9HDHzI8xJf2YYA922kyaKCrvOpJZ27FQ85 +BkXinrvMjJBdRo9Lb5F82+VOqBp0owaHYBQTdl6VbZ8phjx1Gsc5+PqUEyyLg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=fa46f3704b7618f9d9493c126df781faf59040a8 commit fa46f3704b7618f9d9493c126df781faf59040a8 Author: John Baldwin AuthorDate: 2022-08-17 17:01:16 +0000 Commit: John Baldwin CommitDate: 2022-08-17 17:01:16 +0000 bhyve e1000: Skip packets with a small header. Certain operations such as checksum insertion and VLAN insertion require the device model to rewrite the packet header. The first step in rewriting the packet header is to copy the existing packet header from the source packet. This copy is done by copying data from an iovec array that corresponds to the S/G entries described by transmit descriptors. However, if the total packet length is smaller than the headers that need to be copied as the initial template, this copy can overflow the iovec array and use garbage values as the source pointer to memcpy. The PR used a single descriptor with a length of 0 in its PoC. To fix, track the total packet length and drop requests to transmit packets whose payload is smaller than the required header length. While here, fix another issue where the final descriptor could have an invalid length (too short) that could underflow 'len' when stripping the checksum. Skip those requests instead, too. PR: 264372 Reported by: Robert Morris Reviewed by: grehan, markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D36182 --- usr.sbin/bhyve/pci_e82545.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/usr.sbin/bhyve/pci_e82545.c b/usr.sbin/bhyve/pci_e82545.c index 17abaa87240f..d3f61bf57b0d 100644 --- a/usr.sbin/bhyve/pci_e82545.c +++ b/usr.sbin/bhyve/pci_e82545.c @@ -233,7 +233,7 @@ struct ck_info { * Debug printf */ static int e82545_debug = 0; -#define WPRINTF(msg,params...) PRINTLN("e82545: " msg, params) +#define WPRINTF(msg,params...) PRINTLN("e82545: " msg, ##params) #define DPRINTF(msg,params...) if (e82545_debug) WPRINTF(msg, params) #define MIN(a,b) (((a)<(b))?(a):(b)) @@ -1086,15 +1086,18 @@ e82545_transmit(struct e82545_softc *sc, uint16_t head, uint16_t tail, union e1000_tx_udesc *dsc; int desc, dtype, len, ntype, iovcnt, tcp, tso; int mss, paylen, seg, tiovcnt, left, now, nleft, nnow, pv, pvoff; - unsigned hdrlen, vlen; + unsigned hdrlen, vlen, pktlen; uint32_t tcpsum, tcpseq; uint16_t ipcs, tcpcs, ipid, ohead; + bool invalid; ckinfo[0].ck_valid = ckinfo[1].ck_valid = 0; iovcnt = 0; ntype = 0; tso = 0; + pktlen = 0; ohead = head; + invalid = false; /* iovb[0/1] may be used for writable copy of headers. */ iov = &iovb[2]; @@ -1144,17 +1147,23 @@ e82545_transmit(struct e82545_softc *sc, uint16_t head, uint16_t tail, len = (dtype == E1000_TXD_TYP_L) ? dsc->td.lower.flags.length : dsc->dd.lower.data & 0xFFFFF; - if (len > 0) { - /* Strip checksum supplied by guest. */ - if ((dsc->td.lower.data & E1000_TXD_CMD_EOP) != 0 && - (dsc->td.lower.data & E1000_TXD_CMD_IFCS) == 0) + /* Strip checksum supplied by guest. */ + if ((dsc->td.lower.data & E1000_TXD_CMD_EOP) != 0 && + (dsc->td.lower.data & E1000_TXD_CMD_IFCS) == 0) { + if (len <= 2) { + WPRINTF("final descriptor too short (%d) -- dropped", + len); + invalid = true; + } else len -= 2; - if (iovcnt < I82545_MAX_TXSEGS) { - iov[iovcnt].iov_base = paddr_guest2host( - sc->esc_ctx, dsc->td.buffer_addr, len); - iov[iovcnt].iov_len = len; - } + } + + if (len > 0 && iovcnt < I82545_MAX_TXSEGS) { + iov[iovcnt].iov_base = paddr_guest2host(sc->esc_ctx, + dsc->td.buffer_addr, len); + iov[iovcnt].iov_len = len; iovcnt++; + pktlen += len; } /* @@ -1202,6 +1211,9 @@ e82545_transmit(struct e82545_softc *sc, uint16_t head, uint16_t tail, } } + if (invalid) + goto done; + if (iovcnt > I82545_MAX_TXSEGS) { WPRINTF("tx too many descriptors (%d > %d) -- dropped", iovcnt, I82545_MAX_TXSEGS); @@ -1295,8 +1307,13 @@ e82545_transmit(struct e82545_softc *sc, uint16_t head, uint16_t tail, } } + if (pktlen < hdrlen + vlen) { + WPRINTF("packet too small for writable header"); + goto done; + } + /* Allocate, fill and prepend writable header vector. */ - if (hdrlen != 0) { + if (hdrlen + vlen != 0) { hdr = __builtin_alloca(hdrlen + vlen); hdr += vlen; for (left = hdrlen, hdrp = hdr; left > 0;