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

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