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

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