From 93bd2ade11f2bf91b0d61f57a822932fb9326aff Mon Sep 17 00:00:00 2001 From: emaste Date: Thu, 29 Nov 2018 20:14:09 +0000 Subject: [PATCH] MFC r340260: Avoid buffer underwrite in icmp_error icmp_error allocates either an mbuf (with pkthdr) or a cluster depending on the size of data to be quoted in the ICMP reply, but the calculation failed to account for the additional padding that m_align may apply. Include the ip header in the size passed to m_align. On 64-bit archs this will have the net effect of moving everything 4 bytes later in the mbuf or cluster. This will result in slightly pessimal alignment for the ICMP data copy. Also add an assertion that we do not move m_data before the beginning of the mbuf or cluster. Reported by: A reddit user Security: CVE-2018-17156 Sponsored by: The FreeBSD Foundation git-svn-id: svn://svn.freebsd.org/base/stable/10@341258 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/netinet/ip_icmp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index da51957b6..c20861716 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -299,7 +299,8 @@ stdreply: icmpelen = max(8, min(V_icmp_quotelen, ntohs(oip->ip_len) - oiphlen)); mac_netinet_icmp_reply(n, m); #endif icmplen = min(icmplen, M_TRAILINGSPACE(m) - sizeof(struct ip) - ICMP_MINLEN); - m_align(m, ICMP_MINLEN + icmplen); + m_align(m, sizeof(struct ip) + ICMP_MINLEN + icmplen); + m->m_data += sizeof(struct ip); m->m_len = ICMP_MINLEN + icmplen; /* XXX MRT make the outgoing packet use the same FIB @@ -341,6 +342,8 @@ stdreply: icmpelen = max(8, min(V_icmp_quotelen, ntohs(oip->ip_len) - oiphlen)); * reply should bypass as well. */ m->m_flags |= n->m_flags & M_SKIP_FIREWALL; + KASSERT(M_LEADINGSPACE(m) >= sizeof(struct ip), + ("insufficient space for ip header")); m->m_data -= sizeof(struct ip); m->m_len += sizeof(struct ip); m->m_pkthdr.len = m->m_len; -- 2.45.0