summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern A. Zeeb <bz@FreeBSD.org>2011-04-09 11:03:04 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2011-04-09 11:03:04 +0000
commitc63ad9fc169db569bb262e5aeebe9d3eec1da882 (patch)
tree81d52a398658c2e3aee45783bb7a308b666cb96c
parent5dee384d20b305248237b8966a3324c013e96c05 (diff)
Notes
-rw-r--r--sys/netinet6/ipcomp_input.c27
-rw-r--r--sys/netipsec/xform_ipcomp.c21
2 files changed, 47 insertions, 1 deletions
diff --git a/sys/netinet6/ipcomp_input.c b/sys/netinet6/ipcomp_input.c
index be97fd1d6678..76a839ea45e8 100644
--- a/sys/netinet6/ipcomp_input.c
+++ b/sys/netinet6/ipcomp_input.c
@@ -117,8 +117,21 @@ ipcomp4_input(m, off)
goto fail;
}
ipcomp = mtod(md, struct ipcomp *);
- ip = mtod(m, struct ip *);
nxt = ipcomp->comp_nxt;
+
+ /*
+ * Check that the next header of the IPComp is not IPComp again, before
+ * doing any real work. Given it is not possible to do double
+ * compression it means someone is playing tricks on us.
+ */
+ if (nxt == IPPROTO_IPCOMP) {
+ ipseclog((LOG_ERR, "IPv4 IPComp input: "
+ "recursive compression detected."));
+ ipsecstat.in_inval++;
+ goto fail;
+ }
+
+ ip = mtod(m, struct ip *);
#ifdef _IP_VHL
hlen = IP_VHL_HL(ip->ip_vhl) << 2;
#else
@@ -269,6 +282,18 @@ ipcomp6_input(mp, offp, proto)
ip6 = mtod(m, struct ip6_hdr *);
nxt = ipcomp->comp_nxt;
+ /*
+ * Check that the next header of the IPComp is not IPComp again, before
+ * doing any real work. Given it is not possible to do double
+ * compression it means someone is playing tricks on us.
+ */
+ if (nxt == IPPROTO_IPCOMP) {
+ ipseclog((LOG_ERR, "IPv6 IPComp input: "
+ "recursive compression detected."));
+ ipsecstat.in_inval++;
+ goto fail;
+ }
+
cpi = ntohs(ipcomp->comp_cpi);
if (cpi >= IPCOMP_CPI_NEGOTIATE_MIN) {
diff --git a/sys/netipsec/xform_ipcomp.c b/sys/netipsec/xform_ipcomp.c
index 50baac424477..6b5415279fdb 100644
--- a/sys/netipsec/xform_ipcomp.c
+++ b/sys/netipsec/xform_ipcomp.c
@@ -139,10 +139,31 @@ ipcomp_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff)
struct tdb_crypto *tc;
struct cryptodesc *crdc;
struct cryptop *crp;
+ struct ipcomp *ipcomp;
+ caddr_t addr;
int hlen = IPCOMP_HLENGTH;
IPSEC_SPLASSERT_SOFTNET(__func__);
+ /*
+ * Check that the next header of the IPComp is not IPComp again, before
+ * doing any real work. Given it is not possible to do double
+ * compression it means someone is playing tricks on us.
+ */
+ if (m->m_len < skip + hlen && (m = m_pullup(m, skip + hlen)) == NULL) {
+ ipcompstat.ipcomps_hdrops++; /*XXX*/
+ DPRINTF(("%s: m_pullup failed\n", __func__));
+ return (ENOBUFS);
+ }
+ addr = (caddr_t) mtod(m, struct ip *) + skip;
+ ipcomp = (struct ipcomp *)addr;
+ if (ipcomp->comp_nxt == IPPROTO_IPCOMP) {
+ m_freem(m);
+ ipcompstat.ipcomps_pdrops++; /* XXX have our own stats? */
+ DPRINTF(("%s: recursive compression detected\n", __func__));
+ return (EINVAL);
+ }
+
/* Get crypto descriptors */
crp = crypto_getreq(1);
if (crp == NULL) {