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

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