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;
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to