From owner-svn-src-head@freebsd.org Fri Dec 8 18:43:32 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5CF7DE8B1F2; Fri, 8 Dec 2017 18:43:32 +0000 (UTC) (envelope-from shurd@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 mx1.freebsd.org (Postfix) with ESMTPS id 27BBB7E65A; Fri, 8 Dec 2017 18:43:32 +0000 (UTC) (envelope-from shurd@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vB8IhVn7064252; Fri, 8 Dec 2017 18:43:31 GMT (envelope-from shurd@FreeBSD.org) Received: (from shurd@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vB8IhVdA064251; Fri, 8 Dec 2017 18:43:31 GMT (envelope-from shurd@FreeBSD.org) Message-Id: <201712081843.vB8IhVdA064251@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: shurd set sender to shurd@FreeBSD.org using -f From: Stephen Hurd Date: Fri, 8 Dec 2017 18:43:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326702 - head/sys/net X-SVN-Group: head X-SVN-Commit-Author: shurd X-SVN-Commit-Paths: head/sys/net X-SVN-Commit-Revision: 326702 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Dec 2017 18:43:32 -0000 Author: shurd Date: Fri Dec 8 18:43:31 2017 New Revision: 326702 URL: https://svnweb.freebsd.org/changeset/base/326702 Log: Handle read-only mbufs in iflib ether pad function If ethernet padding is enabled, and a read-only mbuf is passed, it would modify the mbuf using m_append(). Instead, call m_dup() and append to the new packet. Reported by: Pyun YongHyeon Sponsored by: Limelight Networks Differential Revision: https://reviews.freebsd.org/D13414 Modified: head/sys/net/iflib.c Modified: head/sys/net/iflib.c ============================================================================== --- head/sys/net/iflib.c Fri Dec 8 18:04:43 2017 (r326701) +++ head/sys/net/iflib.c Fri Dec 8 18:43:31 2017 (r326702) @@ -3112,7 +3112,7 @@ calc_next_txd(iflib_txq_t txq, int cidx, uint8_t qid) * min_frame_size is the frame size (less CRC) to pad the mbuf to */ static __noinline int -iflib_ether_pad(device_t dev, struct mbuf *m_head, uint16_t min_frame_size) +iflib_ether_pad(device_t dev, struct mbuf **m_head, uint16_t min_frame_size) { /* * 18 is enough bytes to pad an ARP packet to 46 bytes, and @@ -3120,14 +3120,25 @@ iflib_ether_pad(device_t dev, struct mbuf *m_head, uin */ static char pad[18]; /* just zeros */ int n; + struct mbuf *new_head; - for (n = min_frame_size - m_head->m_pkthdr.len; + if (!M_WRITABLE(*m_head)) { + new_head = m_dup(*m_head, M_NOWAIT); + if (new_head == NULL) { + device_printf(dev, "cannot pad short frame, m_dup() failed"); + return ENOMEM; + } + m_freem(*m_head); + *m_head = new_head; + } + + for (n = min_frame_size - (*m_head)->m_pkthdr.len; n > 0; n -= sizeof(pad)) - if (!m_append(m_head, min(n, sizeof(pad)), pad)) + if (!m_append(*m_head, min(n, sizeof(pad)), pad)) break; if (n > 0) { - m_freem(m_head); + m_freem(*m_head); device_printf(dev, "cannot pad short frame\n"); DBG_COUNTER_INC(encap_pad_mbuf_fail); return (ENOBUFS); @@ -3189,13 +3200,13 @@ iflib_encap(iflib_txq_t txq, struct mbuf **m_headp) desc_tag = txq->ift_desc_tag; max_segs = scctx->isc_tx_nsegments; } - m_head = *m_headp; if ((sctx->isc_flags & IFLIB_NEED_ETHER_PAD) && __predict_false(m_head->m_pkthdr.len < scctx->isc_min_frame_size)) { - err = iflib_ether_pad(ctx->ifc_dev, m_head, scctx->isc_min_frame_size); + err = iflib_ether_pad(ctx->ifc_dev, m_headp, scctx->isc_min_frame_size); if (err) return err; } + m_head = *m_headp; pkt_info_zero(&pi); pi.ipi_mflags = (m_head->m_flags & (M_VLANTAG|M_BCAST|M_MCAST));