diff options
author | ae <ae@FreeBSD.org> | 2018-02-24 13:04:02 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2018-02-24 13:04:02 +0000 |
commit | cd383464844c1e8f6c5f9b1d0cd955377cc24217 (patch) | |
tree | af3e949440bd5e7e0346381b9f234a4a41cdce8f | |
parent | ab3dc8d2bd32a7e006910dbbde5e0b521f35b862 (diff) | |
download | FreeBSD-src-cd383464844c1e8f6c5f9b1d0cd955377cc24217.zip FreeBSD-src-cd383464844c1e8f6c5f9b1d0cd955377cc24217.tar.gz |
MFC r329561:
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>
-rw-r--r-- | sys/netipsec/xform_ah.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/sys/netipsec/xform_ah.c b/sys/netipsec/xform_ah.c index 68dd6aa..6716e70 100644 --- a/sys/netipsec/xform_ah.c +++ b/sys/netipsec/xform_ah.c @@ -582,6 +582,16 @@ ah_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff) 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 skip, int protoff) /* 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); @@ -648,7 +661,7 @@ ah_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff) /* 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; |