From 172ca2ea0735849d004be7ff27dd3e79f79ce00e Mon Sep 17 00:00:00 2001 From: Jon Maloy 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 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 RH-Acked-by: Stefano Garzarella RH-Acked-by: Stefan Hajnoczi From: Marc-André Lureau 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 Signed-off-by: Marc-André Lureau Reviewed-by: Samuel Thibault (cherry picked from libslirp commit 9bd6c5913271eabcb7768a58197ed3301fe19f2d) Conflicts: - Fixed indentation issues Signed-off-by: Jon Maloy Signed-off-by: Jon Maloy --- 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