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