Blame SOURCES/kvm-slirp-correct-size-computation-while-concatenating-m.patch

ae23c9
From 6de81cfc7762e4177473e188233988e5cebfd25b Mon Sep 17 00:00:00 2001
ae23c9
From: Xiao Wang <jasowang@redhat.com>
ae23c9
Date: Mon, 30 Jul 2018 08:06:27 +0200
ae23c9
Subject: [PATCH 266/268] slirp: correct size computation while concatenating
ae23c9
 mbuf
ae23c9
ae23c9
RH-Author: Xiao Wang <jasowang@redhat.com>
ae23c9
Message-id: <1532937987-25050-1-git-send-email-jasowang@redhat.com>
ae23c9
Patchwork-id: 81544
ae23c9
O-Subject: [RHEL-7.6/7.5z qemu-kvm-rhev] slirp: correct size computation while concatenating mbuf
ae23c9
Bugzilla: 1586255
ae23c9
RH-Acked-by: wexu@redhat.com
ae23c9
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
ae23c9
From: Prasad J Pandit <pjp@fedoraproject.org>
ae23c9
ae23c9
While reassembling incoming fragmented datagrams, 'm_cat' routine
ae23c9
extends the 'mbuf' buffer, if it has insufficient room. It computes
ae23c9
a wrong buffer size, which leads to overwriting adjacent heap buffer
ae23c9
area. Correct this size computation in m_cat.
ae23c9
ae23c9
Reported-by: ZDI Disclosures <zdi-disclosures@trendmicro.com>
ae23c9
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
ae23c9
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
ae23c9
(cherry picked from commit 864036e251f54c99d31df124aad7f34f01f5344c)
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 slirp/mbuf.c | 11 +++++------
ae23c9
 slirp/mbuf.h |  8 +++-----
ae23c9
 2 files changed, 8 insertions(+), 11 deletions(-)
ae23c9
ae23c9
diff --git a/slirp/mbuf.c b/slirp/mbuf.c
ae23c9
index 5ff2455..18cbf75 100644
ae23c9
--- a/slirp/mbuf.c
ae23c9
+++ b/slirp/mbuf.c
ae23c9
@@ -138,7 +138,7 @@ m_cat(struct mbuf *m, struct mbuf *n)
ae23c9
 	 * If there's no room, realloc
ae23c9
 	 */
ae23c9
 	if (M_FREEROOM(m) < n->m_len)
ae23c9
-		m_inc(m,m->m_size+MINCSIZE);
ae23c9
+		m_inc(m, m->m_len + n->m_len);
ae23c9
 
ae23c9
 	memcpy(m->m_data+m->m_len, n->m_data, n->m_len);
ae23c9
 	m->m_len += n->m_len;
ae23c9
@@ -147,7 +147,7 @@ m_cat(struct mbuf *m, struct mbuf *n)
ae23c9
 }
ae23c9
 
ae23c9
 
ae23c9
-/* make m size bytes large */
ae23c9
+/* make m 'size' bytes large from m_data */
ae23c9
 void
ae23c9
 m_inc(struct mbuf *m, int size)
ae23c9
 {
ae23c9
@@ -158,12 +158,12 @@ m_inc(struct mbuf *m, int size)
ae23c9
 
ae23c9
         if (m->m_flags & M_EXT) {
ae23c9
 	  datasize = m->m_data - m->m_ext;
ae23c9
-          m->m_ext = g_realloc(m->m_ext, size);
ae23c9
+	  m->m_ext = g_realloc(m->m_ext, size + datasize);
ae23c9
 	  m->m_data = m->m_ext + datasize;
ae23c9
         } else {
ae23c9
 	  char *dat;
ae23c9
 	  datasize = m->m_data - m->m_dat;
ae23c9
-          dat = g_malloc(size);
ae23c9
+	  dat = g_malloc(size + datasize);
ae23c9
 	  memcpy(dat, m->m_dat, m->m_size);
ae23c9
 
ae23c9
 	  m->m_ext = dat;
ae23c9
@@ -171,8 +171,7 @@ m_inc(struct mbuf *m, int size)
ae23c9
 	  m->m_flags |= M_EXT;
ae23c9
         }
ae23c9
 
ae23c9
-        m->m_size = size;
ae23c9
-
ae23c9
+        m->m_size = size + datasize;
ae23c9
 }
ae23c9
 
ae23c9
 
ae23c9
diff --git a/slirp/mbuf.h b/slirp/mbuf.h
ae23c9
index 893601f..33b8448 100644
ae23c9
--- a/slirp/mbuf.h
ae23c9
+++ b/slirp/mbuf.h
ae23c9
@@ -33,8 +33,6 @@
ae23c9
 #ifndef MBUF_H
ae23c9
 #define MBUF_H
ae23c9
 
ae23c9
-#define MINCSIZE 4096	/* Amount to increase mbuf if too small */
ae23c9
-
ae23c9
 /*
ae23c9
  * Macros for type conversion
ae23c9
  * mtod(m,t) -	convert mbuf pointer to data pointer of correct type
ae23c9
@@ -72,11 +70,11 @@ struct mbuf {
ae23c9
 	struct	mbuf *m_prevpkt;	/* Flags aren't used in the output queue */
ae23c9
 	int	m_flags;		/* Misc flags */
ae23c9
 
ae23c9
-	int	m_size;			/* Size of data */
ae23c9
+	int	m_size;			/* Size of mbuf, from m_dat or m_ext */
ae23c9
 	struct	socket *m_so;
ae23c9
 
ae23c9
-	caddr_t	m_data;			/* Location of data */
ae23c9
-	int	m_len;			/* Amount of data in this mbuf */
ae23c9
+	caddr_t	m_data;			/* Current location of data */
ae23c9
+	int	m_len;			/* Amount of data in this mbuf, from m_data */
ae23c9
 
ae23c9
 	Slirp *slirp;
ae23c9
 	bool	resolution_requested;
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9