From owner-svn-src-stable@freebsd.org Wed Mar 7 05:47:49 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 98D7FF2E5F0; Wed, 7 Mar 2018 05:47:49 +0000 (UTC) (envelope-from gordon@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 328857EFB5; Wed, 7 Mar 2018 05:47:49 +0000 (UTC) (envelope-from gordon@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 278701D5A9; Wed, 7 Mar 2018 05:47:49 +0000 (UTC) (envelope-from gordon@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w275lmjK083355; Wed, 7 Mar 2018 05:47:48 GMT (envelope-from gordon@FreeBSD.org) Received: (from gordon@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w275lm2e083354; Wed, 7 Mar 2018 05:47:48 GMT (envelope-from gordon@FreeBSD.org) Message-Id: <201803070547.w275lm2e083354@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gordon set sender to gordon@FreeBSD.org using -f From: Gordon Tetlow Date: Wed, 7 Mar 2018 05:47:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r330565 - stable/10/sys/netipsec X-SVN-Group: stable-10 X-SVN-Commit-Author: gordon X-SVN-Commit-Paths: stable/10/sys/netipsec X-SVN-Commit-Revision: 330565 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@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Mar 2018 05:47:49 -0000 Author: gordon Date: Wed Mar 7 05:47:48 2018 New Revision: 330565 URL: https://svnweb.freebsd.org/changeset/base/330565 Log: Port r329561 to stable/10. There were structural changes preventing MFC. Check packet length to not make an out of bounds access. Also, save ah_nxt value to use later, since the ah pointer can become invalid. Reviewed by: ae@ Approved by: so Security: CVE-2018-6916 Security: FreeBSD-SA-18:01.ipsec Modified: stable/10/sys/netipsec/xform_ah.c Modified: stable/10/sys/netipsec/xform_ah.c ============================================================================== --- stable/10/sys/netipsec/xform_ah.c Wed Mar 7 04:11:14 2018 (r330564) +++ stable/10/sys/netipsec/xform_ah.c Wed Mar 7 05:47:48 2018 (r330565) @@ -599,6 +599,16 @@ ah_input(struct mbuf *m, struct secasvar *sav, int ski m_freem(m); return EACCES; } + if (skip + authsize + rplen > m->m_pkthdr.len) { + DPRINTF(("%s: bad mbuf length %u (expecting %lu)" + " for packet in SA %s/%08lx\n", __func__, + m->m_pkthdr.len, (u_long) (skip + authsize + rplen), + ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)), + (u_long) ntohl(sav->spi))); + AHSTAT_INC(ahs_badauthl); + error = EACCES; + goto bad; + } AHSTAT_ADD(ahs_ibytes, m->m_pkthdr.len - skip - hl); /* Get crypto descriptors. */ @@ -664,6 +674,9 @@ ah_input(struct mbuf *m, struct secasvar *sav, int ski /* Zeroize the authenticator on the packet. */ m_copyback(m, skip + rplen, authsize, ipseczeroes); + /* Save ah_nxt, since ah pointer can become invalid after "massage" */ + hl = ah->ah_nxt; + /* "Massage" the packet headers for crypto processing. */ error = ah_massage_headers(&m, sav->sah->saidx.dst.sa.sa_family, skip, ahx->type, 0); @@ -688,7 +701,7 @@ ah_input(struct mbuf *m, struct secasvar *sav, int ski tc->tc_spi = sav->spi; tc->tc_dst = sav->sah->saidx.dst; tc->tc_proto = sav->sah->saidx.proto; - tc->tc_nxt = ah->ah_nxt; + tc->tc_nxt = hl; tc->tc_protoff = protoff; tc->tc_skip = skip; tc->tc_ptr = (caddr_t) mtag; /* Save the mtag we've identified. */