Blame SOURCES/kvm-slirp-Correct-size-check-in-m_inc.patch

357786
From 44dfd8eea4b562e77587cdd1b2ae6b6decc870f9 Mon Sep 17 00:00:00 2001
44d016
From: Xiao Wang <jasowang@redhat.com>
357786
Date: Wed, 8 Aug 2018 07:52:57 +0200
357786
Subject: [PATCH 2/5] slirp: Correct size check in m_inc()
44d016
44d016
RH-Author: Xiao Wang <jasowang@redhat.com>
357786
Message-id: <1533714777-24827-3-git-send-email-jasowang@redhat.com>
357786
Patchwork-id: 81674
357786
O-Subject: [RHEL-7.6/7.5z qemu-kvm-rhev 2/2] slirp: Correct size check in m_inc()
357786
Bugzilla: 1586255
44d016
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
44d016
RH-Acked-by: wexu@redhat.com
44d016
RH-Acked-by: Thomas Huth <thuth@redhat.com>
44d016
44d016
From: Peter Maydell <peter.maydell@linaro.org>
44d016
44d016
The data in an mbuf buffer is not necessarily at the start of the
44d016
allocated buffer. (For instance m_adj() allows data to be trimmed
44d016
from the start by just advancing the pointer and reducing the length.)
44d016
This means that the allocated buffer size (m->m_size) and the
44d016
amount of space from the m_data pointer to the end of the
44d016
buffer (M_ROOM(m)) are not necessarily the same.
44d016
44d016
Commit 864036e251f54c9 tried to change the m_inc() function from
44d016
taking the new allocated-buffer-size to taking the new room-size,
44d016
but forgot to change the initial "do we already have enough space"
44d016
check. This meant that if we were trying to extend a buffer which
44d016
had a leading gap between the buffer start and the data, we might
44d016
incorrectly decide it didn't need to be extended, and then
44d016
overrun the end of the buffer, causing memory corruption and
44d016
an eventual crash.
44d016
44d016
Change the "already big enough?" condition from checking the
44d016
argument against m->m_size to checking against M_ROOM().
44d016
This only makes a difference for the callsite in m_cat();
44d016
the other three callsites all start with a freshly allocated
44d016
mbuf from m_get(), which will have m->m_size == M_ROOM(m).
44d016
44d016
Fixes: 864036e251f54c9
44d016
Fixes: https://bugs.launchpad.net/qemu/+bug/1785670
44d016
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
44d016
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
44d016
Message-id: 20180807114501.12370-1-peter.maydell@linaro.org
44d016
Tested-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
44d016
(cherry picked from commit 09b94ac0f29db3b022a77a5aa50dc9e37032689d)
44d016
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
44d016
---
44d016
 slirp/mbuf.c | 2 +-
44d016
 1 file changed, 1 insertion(+), 1 deletion(-)
44d016
44d016
diff --git a/slirp/mbuf.c b/slirp/mbuf.c
44d016
index 0c189e1..1b78683 100644
44d016
--- a/slirp/mbuf.c
44d016
+++ b/slirp/mbuf.c
44d016
@@ -154,7 +154,7 @@ m_inc(struct mbuf *m, int size)
44d016
     int datasize;
44d016
 
44d016
     /* some compilers throw up on gotos.  This one we can fake. */
44d016
-    if (m->m_size > size) {
44d016
+    if (M_ROOM(m) > size) {
44d016
         return;
44d016
     }
44d016
 
44d016
-- 
44d016
1.8.3.1
44d016