thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
Blob Blame History Raw
From 172ca2ea0735849d004be7ff27dd3e79f79ce00e Mon Sep 17 00:00:00 2001
From: Jon Maloy <jmaloy@redhat.com>
Date: Sat, 20 Jun 2020 13:30:54 -0400
Subject: [PATCH 1/3] 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: <20200620133054.3334982-2-jmaloy@redhat.com>
Patchwork-id: 97673
O-Subject: [RHEL-7.9 qemu-kvm PATCH 1/1] Fix use-afte-free in ip_reass() (CVE-2020-1983)
Bugzilla: 1837565
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 9e95b40e97..011f01ed71 100644
--- a/slirp/ip_input.c
+++ b/slirp/ip_input.c
@@ -329,10 +329,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) {
@@ -356,12 +356,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