Blob Blame History Raw
From 06b7f03c663268ad662892c91925724f5ae9eb9b Mon Sep 17 00:00:00 2001
From: Jon Maloy <jmaloy@redhat.com>
Date: Sat, 20 Jun 2020 15:19:21 -0400
Subject: [PATCH 2/2] Fix use-afte-free in ip_reass() (CVE-2020-1983)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

RH-Author: Jon Maloy <jmaloy@redhat.com>
Message-id: <20200620151921.3353831-2-jmaloy@redhat.com>
Patchwork-id: 97682
O-Subject: [RHEL-7.9 qemu-kvm-ma PATCH 1/1] Fix use-afte-free in ip_reass() (CVE-2020-1983)
Bugzilla: 1837568
RH-Acked-by: Thomas Huth <thuth@redhat.com>
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

The q pointer is updated when the mbuf data is moved from m_dat to
m_ext.

m_ext buffer may also be realloc()'ed and moved during m_cat():
q should also be updated in this case.

Reported-by: Aviv Sasson <asasson@paloaltonetworks.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

(cherry picked from libslirp commit 9bd6c5913271eabcb7768a58197ed3301fe19f2d)
Conflicts:
	- Fixed indentation issues
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
---
 slirp/ip_input.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/slirp/ip_input.c b/slirp/ip_input.c
index 7cf01336bf..9d2d79dfff 100644
--- a/slirp/ip_input.c
+++ b/slirp/ip_input.c
@@ -333,10 +333,10 @@ insert:
 	/*
 	 * Reassembly is complete; concatenate fragments.
 	 */
-    q = fp->frag_link.next;
+	q = fp->frag_link.next;
 	m = dtom(slirp, q);
 
-	int was_ext = m->m_flags & M_EXT;
+	int delta = (char *)q - (m->m_flags & M_EXT ? m->m_ext : m->m_dat);
 
 	q = (struct ipasfrag *) q->ipf_next;
 	while (q != (struct ipasfrag*)&fp->frag_link) {
@@ -360,12 +360,11 @@ insert:
 	 * the old buffer (in the mbuf), so we must point ip
 	 * into the new buffer.
 	 */
-	if (!was_ext && m->m_flags & M_EXT) {
-	  int delta = (char *)q - m->m_dat;
+	if (m->m_flags & M_EXT) {
 	  q = (struct ipasfrag *)(m->m_ext + delta);
 	}
 
-    ip = fragtoip(q);
+	ip = fragtoip(q);
 	ip->ip_len = next;
 	ip->ip_tos &= ~1;
 	ip->ip_src = fp->ipq_src;
-- 
2.18.2