9ae3a8
From b25ccac372f3289d7b0b5500064fe0a38eb32d6f Mon Sep 17 00:00:00 2001
9ae3a8
From: Xiao Wang <jasowang@redhat.com>
9ae3a8
Date: Wed, 8 Aug 2018 08:44:36 +0200
9ae3a8
Subject: [PATCH 4/4] slirp: Correct size check in m_inc()
9ae3a8
9ae3a8
RH-Author: Xiao Wang <jasowang@redhat.com>
9ae3a8
Message-id: <1533717876-2330-1-git-send-email-jasowang@redhat.com>
9ae3a8
Patchwork-id: 81676
9ae3a8
O-Subject: [RHEL-7.6/7.5z qemu-kvm PATCH] slirp: Correct size check in m_inc()
9ae3a8
Bugzilla: 1586253
9ae3a8
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
9ae3a8
RH-Acked-by: wexu@redhat.com
9ae3a8
RH-Acked-by: Thomas Huth <thuth@redhat.com>
9ae3a8
9ae3a8
From: Peter Maydell <peter.maydell@linaro.org>
9ae3a8
9ae3a8
Notes:
9ae3a8
- Conflict since we lacks 6da5de1ee87e ("slirp: reformat m_inc
9ae3a8
  routine"), and its backport has various other dependicies.
9ae3a8
- This is a fixup for CVE-2018-11806 fix
9ae3a8
9ae3a8
The data in an mbuf buffer is not necessarily at the start of the
9ae3a8
allocated buffer. (For instance m_adj() allows data to be trimmed
9ae3a8
from the start by just advancing the pointer and reducing the length.)
9ae3a8
This means that the allocated buffer size (m->m_size) and the
9ae3a8
amount of space from the m_data pointer to the end of the
9ae3a8
buffer (M_ROOM(m)) are not necessarily the same.
9ae3a8
9ae3a8
Commit 864036e251f54c9 tried to change the m_inc() function from
9ae3a8
taking the new allocated-buffer-size to taking the new room-size,
9ae3a8
but forgot to change the initial "do we already have enough space"
9ae3a8
check. This meant that if we were trying to extend a buffer which
9ae3a8
had a leading gap between the buffer start and the data, we might
9ae3a8
incorrectly decide it didn't need to be extended, and then
9ae3a8
overrun the end of the buffer, causing memory corruption and
9ae3a8
an eventual crash.
9ae3a8
9ae3a8
Change the "already big enough?" condition from checking the
9ae3a8
argument against m->m_size to checking against M_ROOM().
9ae3a8
This only makes a difference for the callsite in m_cat();
9ae3a8
the other three callsites all start with a freshly allocated
9ae3a8
mbuf from m_get(), which will have m->m_size == M_ROOM(m).
9ae3a8
9ae3a8
Fixes: 864036e251f54c9
9ae3a8
Fixes: https://bugs.launchpad.net/qemu/+bug/1785670
9ae3a8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9ae3a8
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
9ae3a8
Message-id: 20180807114501.12370-1-peter.maydell@linaro.org
9ae3a8
Tested-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
9ae3a8
(cherry picked from commit c22098c74a09164797fae6511c5eaf68f32c4dd8)
9ae3a8
Signed-off-by: Jason Wang <jasowang@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 slirp/mbuf.c | 6 ++++--
9ae3a8
 1 file changed, 4 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
diff --git a/slirp/mbuf.c b/slirp/mbuf.c
9ae3a8
index ced2033..63f071f 100644
9ae3a8
--- a/slirp/mbuf.c
9ae3a8
+++ b/slirp/mbuf.c
9ae3a8
@@ -154,8 +154,10 @@ m_inc(struct mbuf *m, int size)
9ae3a8
 {
9ae3a8
 	int datasize;
9ae3a8
 
9ae3a8
-	/* some compiles throw up on gotos.  This one we can fake. */
9ae3a8
-        if(m->m_size>size) return;
9ae3a8
+    /* some compilers throw up on gotos.  This one we can fake. */
9ae3a8
+    if (M_ROOM(m) > size) {
9ae3a8
+        return;
9ae3a8
+    }
9ae3a8
 
9ae3a8
         if (m->m_flags & M_EXT) {
9ae3a8
 	  datasize = m->m_data - m->m_ext;
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8