Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Feb 2018 11:14:38 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329561 - head/sys/netipsec
Message-ID:  <201802191114.w1JBEchL022617@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Mon Feb 19 11:14:38 2018
New Revision: 329561
URL: https://svnweb.freebsd.org/changeset/base/329561

Log:
  Check packet length to do not make out of bounds access. Also save ah_nxt
  value to use it later, since ah pointer can become invalid.
  
  Reported by:	Maxime Villard <max at m00nbsd dot net>
  MFC after:	5 days

Modified:
  head/sys/netipsec/xform_ah.c

Modified: head/sys/netipsec/xform_ah.c
==============================================================================
--- head/sys/netipsec/xform_ah.c	Mon Feb 19 10:59:19 2018	(r329560)
+++ head/sys/netipsec/xform_ah.c	Mon Feb 19 11:14:38 2018	(r329561)
@@ -582,6 +582,16 @@ ah_input(struct mbuf *m, struct secasvar *sav, int ski
 		error = EACCES;
 		goto bad;
 	}
+	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. */
@@ -626,6 +636,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);
@@ -650,7 +663,7 @@ ah_input(struct mbuf *m, struct secasvar *sav, int ski
 
 	/* These are passed as-is to the callback. */
 	xd->sav = sav;
-	xd->nxt = ah->ah_nxt;
+	xd->nxt = hl;
 	xd->protoff = protoff;
 	xd->skip = skip;
 	xd->cryptoid = cryptoid;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802191114.w1JBEchL022617>