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

169b9a
From 2c90d2f3ad8d299df7df7c055c66fa6711397f4a Mon Sep 17 00:00:00 2001
6e672b
From: Xiao Wang <jasowang@redhat.com>
6e672b
Date: Mon, 30 Jul 2018 06:31:57 +0200
6e672b
Subject: [PATCH 8/8] slirp: correct size computation while concatenating mbuf
6e672b
6e672b
RH-Author: Xiao Wang <jasowang@redhat.com>
6e672b
Message-id: <1532932317-6100-3-git-send-email-jasowang@redhat.com>
6e672b
Patchwork-id: 81543
6e672b
O-Subject: [RHEL7.6/7.5.z qemu-kvm PATCH 2/2] slirp: correct size computation while concatenating mbuf
169b9a
Bugzilla: 1586253
6e672b
RH-Acked-by: wexu@redhat.com
6e672b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
6e672b
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
6e672b
6e672b
From: Prasad J Pandit <pjp@fedoraproject.org>
6e672b
6e672b
Upstream: 70f2e64e4dde slirp: Convert mbufs to use g_malloc() and g_free()
6e672b
Notes: Conflict since we lacks 70f2e64e4dde
6e672b
       ("slirp: Convert mbufs to use g_malloc() and g_free()")
6e672b
6e672b
While reassembling incoming fragmented datagrams, 'm_cat' routine
6e672b
extends the 'mbuf' buffer, if it has insufficient room. It computes
6e672b
a wrong buffer size, which leads to overwriting adjacent heap buffer
6e672b
area. Correct this size computation in m_cat.
6e672b
6e672b
Reported-by: ZDI Disclosures <zdi-disclosures@trendmicro.com>
6e672b
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
6e672b
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
6e672b
Signed-off-by: Jason Wang <jasowang@redhat.com>
6e672b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
6e672b
---
6e672b
 slirp/mbuf.c | 11 +++++------
6e672b
 slirp/mbuf.h |  8 +++-----
6e672b
 2 files changed, 8 insertions(+), 11 deletions(-)
6e672b
6e672b
diff --git a/slirp/mbuf.c b/slirp/mbuf.c
6e672b
index 5565fd1..ced2033 100644
6e672b
--- a/slirp/mbuf.c
6e672b
+++ b/slirp/mbuf.c
6e672b
@@ -139,7 +139,7 @@ m_cat(struct mbuf *m, struct mbuf *n)
6e672b
 	 * If there's no room, realloc
6e672b
 	 */
6e672b
 	if (M_FREEROOM(m) < n->m_len)
6e672b
-		m_inc(m,m->m_size+MINCSIZE);
6e672b
+		m_inc(m, m->m_len + n->m_len);
6e672b
 
6e672b
 	memcpy(m->m_data+m->m_len, n->m_data, n->m_len);
6e672b
 	m->m_len += n->m_len;
6e672b
@@ -148,7 +148,7 @@ m_cat(struct mbuf *m, struct mbuf *n)
6e672b
 }
6e672b
 
6e672b
 
6e672b
-/* make m size bytes large */
6e672b
+/* make m 'size' bytes large from m_data */
6e672b
 void
6e672b
 m_inc(struct mbuf *m, int size)
6e672b
 {
6e672b
@@ -159,12 +159,12 @@ m_inc(struct mbuf *m, int size)
6e672b
 
6e672b
         if (m->m_flags & M_EXT) {
6e672b
 	  datasize = m->m_data - m->m_ext;
6e672b
-	  m->m_ext = (char *)realloc(m->m_ext,size);
6e672b
+	  m->m_ext = (char *)realloc(m->m_ext, size + datasize);
6e672b
 	  m->m_data = m->m_ext + datasize;
6e672b
         } else {
6e672b
 	  char *dat;
6e672b
 	  datasize = m->m_data - m->m_dat;
6e672b
-	  dat = (char *)malloc(size);
6e672b
+	  dat = (char *)malloc(size + datasize);
6e672b
 	  memcpy(dat, m->m_dat, m->m_size);
6e672b
 
6e672b
 	  m->m_ext = dat;
6e672b
@@ -172,8 +172,7 @@ m_inc(struct mbuf *m, int size)
6e672b
 	  m->m_flags |= M_EXT;
6e672b
         }
6e672b
 
6e672b
-        m->m_size = size;
6e672b
-
6e672b
+        m->m_size = size + datasize;
6e672b
 }
6e672b
 
6e672b
 
6e672b
diff --git a/slirp/mbuf.h b/slirp/mbuf.h
6e672b
index b144f1c..32e5120 100644
6e672b
--- a/slirp/mbuf.h
6e672b
+++ b/slirp/mbuf.h
6e672b
@@ -33,8 +33,6 @@
6e672b
 #ifndef _MBUF_H_
6e672b
 #define _MBUF_H_
6e672b
 
6e672b
-#define MINCSIZE 4096	/* Amount to increase mbuf if too small */
6e672b
-
6e672b
 /*
6e672b
  * Macros for type conversion
6e672b
  * mtod(m,t) -	convert mbuf pointer to data pointer of correct type
6e672b
@@ -72,11 +70,11 @@ struct mbuf {
6e672b
 	struct	mbuf *m_prevpkt;	/* Flags aren't used in the output queue */
6e672b
 	int	m_flags;		/* Misc flags */
6e672b
 
6e672b
-	int	m_size;			/* Size of data */
6e672b
+	int	m_size;			/* Size of mbuf, from m_dat or m_ext */
6e672b
 	struct	socket *m_so;
6e672b
 
6e672b
-	caddr_t	m_data;			/* Location of data */
6e672b
-	int	m_len;			/* Amount of data in this mbuf */
6e672b
+	caddr_t	m_data;			/* Current location of data */
6e672b
+	int	m_len;			/* Amount of data in this mbuf, from m_data */
6e672b
 
6e672b
 	Slirp *slirp;
6e672b
 	bool	arp_requested;
6e672b
-- 
6e672b
1.8.3.1
6e672b