All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-3.0] slirp: Correct size check in m_inc()
@ 2018-08-07 11:45 Peter Maydell
  2018-08-07 11:54 ` Samuel Thibault
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Peter Maydell @ 2018-08-07 11:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: patches, Samuel Thibault, Jan Kiszka, Prasad J Pandit,
	Dr . David Alan Gilbert, liqsub1

The data in an mbuf buffer is not necessarily at the start of the
allocated buffer. (For instance m_adj() allows data to be trimmed
from the start by just advancing the pointer and reducing the length.)
This means that the allocated buffer size (m->m_size) and the
amount of space from the m_data pointer to the end of the
buffer (M_ROOM(m)) are not necessarily the same.

Commit 864036e251f54c9 tried to change the m_inc() function from
taking the new allocated-buffer-size to taking the new room-size,
but forgot to change the initial "do we already have enough space"
check. This meant that if we were trying to extend a buffer which
had a leading gap between the buffer start and the data, we might
incorrectly decide it didn't need to be extended, and then
overrun the end of the buffer, causing memory corruption and
an eventual crash.

Change the "already big enough?" condition from checking the
argument against m->m_size to checking against M_ROOM().
This only makes a difference for the callsite in m_cat();
the other three callsites all start with a freshly allocated
mbuf from m_get(), which will have m->m_size == M_ROOM(m).

Fixes: 864036e251f54c9
Fixes: https://bugs.launchpad.net/qemu/+bug/1785670
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 slirp/mbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/slirp/mbuf.c b/slirp/mbuf.c
index 0c189e1a7bf..1b7868355a3 100644
--- a/slirp/mbuf.c
+++ b/slirp/mbuf.c
@@ -154,7 +154,7 @@ m_inc(struct mbuf *m, int size)
     int datasize;
 
     /* some compilers throw up on gotos.  This one we can fake. */
-    if (m->m_size > size) {
+    if (M_ROOM(m) > size) {
         return;
     }
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-08-10  9:14 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-07 11:45 [Qemu-devel] [PATCH for-3.0] slirp: Correct size check in m_inc() Peter Maydell
2018-08-07 11:54 ` Samuel Thibault
2018-08-07 12:52 ` Dr. David Alan Gilbert
2018-08-07 12:58   ` Daniel P. Berrangé
2018-08-07 13:07     ` Thomas Huth
2018-08-07 13:09       ` Daniel P. Berrangé
2018-08-07 13:47         ` Peter Maydell
2018-08-07 15:47           ` Markus Armbruster
2018-08-07 15:58             ` Peter Maydell
2018-08-07 13:45 ` Peter Maydell
2018-08-09 11:12 ` Dr. David Alan Gilbert
2018-08-09 11:25   ` Peter Maydell
2018-08-09 11:32     ` Dr. David Alan Gilbert
2018-08-09 21:54       ` Samuel Thibault
2018-08-10  9:02         ` Peter Maydell
2018-08-10  9:08           ` Samuel Thibault
2018-08-10  9:13             ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.