82861e
From 126c04acbabd7ad32c2b018fe10dfac2a3bc1210 Mon Sep 17 00:00:00 2001
82861e
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
82861e
Date: Sun, 28 Jul 2019 19:11:24 +0200
82861e
Subject: [PATCH] Fix heap overflow in ip_reass on big packet input
82861e
82861e
When the first fragment does not fit in the preallocated buffer, q will
82861e
already be pointing to the ext buffer, so we mustn't try to update it.
82861e
82861e
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
82861e
---
82861e
 src/ip_input.c | 4 +++-
82861e
 1 file changed, 3 insertions(+), 1 deletion(-)
82861e
82861e
diff -up ./slirp4netns-c4e1bc5a5e6987f3a352ca524f13320a2d483398/qemu/slirp/ip_input.c.CVE-2019-14378 ./slirp4netns-c4e1bc5a5e6987f3a352ca524f13320a2d483398/qemu/slirp/ip_input.c
82861e
--- slirp4netns-c4e1bc5a5e6987f3a352ca524f13320a2d483398/qemu/slirp/ip_input.c.CVE-2019-14378	2019-09-27 11:04:30.215413671 +0200
82861e
+++ slirp4netns-c4e1bc5a5e6987f3a352ca524f13320a2d483398/qemu/slirp/ip_input.c	2019-09-27 11:04:30.216413682 +0200
82861e
@@ -333,6 +333,8 @@ insert:
82861e
     q = fp->frag_link.next;
82861e
 	m = dtom(slirp, q);
82861e
 
82861e
+	int was_ext = m->m_flags & M_EXT;
82861e
+
82861e
 	q = (struct ipasfrag *) q->ipf_next;
82861e
 	while (q != (struct ipasfrag*)&fp->frag_link) {
82861e
 	  struct mbuf *t = dtom(slirp, q);
82861e
@@ -355,7 +357,7 @@ insert:
82861e
 	 * the old buffer (in the mbuf), so we must point ip
82861e
 	 * into the new buffer.
82861e
 	 */
82861e
-	if (m->m_flags & M_EXT) {
82861e
+	if (!was_ext && m->m_flags & M_EXT) {
82861e
 	  int delta = (char *)q - m->m_dat;
82861e
 	  q = (struct ipasfrag *)(m->m_ext + delta);
82861e
 	}