Blame SOURCES/kvm-slirp-use-correct-size-while-emulating-commands.patch

c461a1
From 95cf6abd88bedca0533ababfdb6480c3174f3b81 Mon Sep 17 00:00:00 2001
c461a1
From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= <philmd@redhat.com>
c461a1
Date: Fri, 17 Jan 2020 12:00:37 +0100
c461a1
Subject: [PATCH 3/3] slirp: use correct size while emulating commands
c461a1
MIME-Version: 1.0
c461a1
Content-Type: text/plain; charset=UTF-8
c461a1
Content-Transfer-Encoding: 8bit
c461a1
c461a1
RH-Author: Philippe Mathieu-Daudé <philmd@redhat.com>
c461a1
Message-id: <20200117120037.12800-4-philmd@redhat.com>
c461a1
Patchwork-id: 93397
c461a1
O-Subject: [RHEL-7.7.z qemu-kvm + RHEL-7.8 qemu-kvm + RHEL-7.9 qemu-kvm PATCH v2 3/3] slirp: use correct size while emulating commands
c461a1
Bugzilla: 1791560
c461a1
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
c461a1
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
c461a1
RH-Acked-by: Thomas Huth <thuth@redhat.com>
c461a1
c461a1
From: Prasad J Pandit <pjp@fedoraproject.org>
c461a1
c461a1
While emulating services in tcp_emu(), it uses 'mbuf' size
c461a1
'm->m_size' to write commands via snprintf(3). Use M_FREEROOM(m)
c461a1
size to avoid possible OOB access.
c461a1
c461a1
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
c461a1
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
c461a1
Message-Id: <20200109094228.79764-3-ppandit@redhat.com>
c461a1
(cherry picked from libslirp commit 82ebe9c370a0e2970fb5695aa19aa5214a6a1c80)
c461a1
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
c461a1
c461a1
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
c461a1
---
c461a1
 slirp/tcp_subr.c | 8 ++++----
c461a1
 1 file changed, 4 insertions(+), 4 deletions(-)
c461a1
c461a1
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
c461a1
index 321c2a4..19e2245 100644
c461a1
--- a/slirp/tcp_subr.c
c461a1
+++ b/slirp/tcp_subr.c
c461a1
@@ -648,7 +648,7 @@ tcp_emu(struct socket *so, struct mbuf *m)
c461a1
 			n4 =  (laddr & 0xff);
c461a1
 
c461a1
 			m->m_len = bptr - m->m_data; /* Adjust length */
c461a1
-                        m->m_len += snprintf(bptr, m->m_size - m->m_len,
c461a1
+                        m->m_len += snprintf(bptr, M_FREEROOM(m),
c461a1
                                              "ORT %d,%d,%d,%d,%d,%d\r\n%s",
c461a1
                                              n1, n2, n3, n4, n5, n6, x==7?buff:"");
c461a1
 			return 1;
c461a1
@@ -681,7 +681,7 @@ tcp_emu(struct socket *so, struct mbuf *m)
c461a1
 			n4 =  (laddr & 0xff);
c461a1
 
c461a1
 			m->m_len = bptr - m->m_data; /* Adjust length */
c461a1
-			m->m_len += snprintf(bptr, m->m_size - m->m_len,
c461a1
+			m->m_len += snprintf(bptr, M_FREEROOM(m),
c461a1
                                              "27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%s",
c461a1
                                              n1, n2, n3, n4, n5, n6, x==7?buff:"");
c461a1
 
c461a1
@@ -707,8 +707,8 @@ tcp_emu(struct socket *so, struct mbuf *m)
c461a1
 		if (m->m_data[m->m_len-1] == '\0' && lport != 0 &&
c461a1
 		    (so = tcp_listen(slirp, INADDR_ANY, 0, so->so_laddr.s_addr,
c461a1
 		                     htons(lport), SS_FACCEPTONCE)) != NULL)
c461a1
-                    m->m_len = snprintf(m->m_data, m->m_size, "%d",
c461a1
-                                        ntohs(so->so_fport)) + 1;
c461a1
+                    m->m_len = snprintf(m->m_data, M_ROOM(m),
c461a1
+                                        "%d", ntohs(so->so_fport)) + 1;
c461a1
 		return 1;
c461a1
 
c461a1
 	 case EMU_IRC:
c461a1
-- 
c461a1
1.8.3.1
c461a1