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

902636
From dfbfcf02738640ab83f7970e636b72b78f166675 Mon Sep 17 00:00:00 2001
902636
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
902636
Date: Fri, 17 Jan 2020 12:07:58 +0100
902636
Subject: [PATCH 3/4] 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
902636
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
902636
Message-id: <20200117120758.1076549-4-marcandre.lureau@redhat.com>
902636
Patchwork-id: 93401
902636
O-Subject: [RHEL-AV-8.1.0 qemu-kvm + RHEL-AV-8.2.0 qemu-kvm PATCH 3/3] slirp: use correct size while emulating commands
902636
Bugzilla: 1791568
902636
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
d8ab4a
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
016a62
RH-Acked-by: Stefan Hajnoczi <stefanha@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
902636
(cherry picked from commit 82ebe9c370a0e2970fb5695aa19aa5214a6a1c80)
902636
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
016a62
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
d8ab4a
---
902636
 slirp/src/tcp_subr.c | 9 ++++-----
902636
 1 file changed, 4 insertions(+), 5 deletions(-)
d8ab4a
902636
diff --git a/slirp/src/tcp_subr.c b/slirp/src/tcp_subr.c
902636
index cedbfb2..954d1a6 100644
902636
--- a/slirp/src/tcp_subr.c
902636
+++ b/slirp/src/tcp_subr.c
902636
@@ -696,7 +696,7 @@ int tcp_emu(struct socket *so, struct mbuf *m)
902636
             n4 = (laddr & 0xff);
d8ab4a
 
902636
             m->m_len = bptr - m->m_data; /* Adjust length */
902636
-            m->m_len += snprintf(bptr, m->m_size - m->m_len,
902636
+            m->m_len += snprintf(bptr, M_FREEROOM(m),
902636
                                  "ORT %d,%d,%d,%d,%d,%d\r\n%s", n1, n2, n3, n4,
902636
                                  n5, n6, x == 7 ? buff : "");
902636
             return 1;
902636
@@ -731,8 +731,7 @@ int tcp_emu(struct socket *so, struct mbuf *m)
902636
             n4 = (laddr & 0xff);
d8ab4a
 
902636
             m->m_len = bptr - m->m_data; /* Adjust length */
902636
-            m->m_len +=
902636
-                snprintf(bptr, m->m_size - m->m_len,
902636
+            m->m_len += snprintf(bptr, M_FREEROOM(m),
902636
                          "27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%s",
902636
                          n1, n2, n3, n4, n5, n6, x == 7 ? buff : "");
d8ab4a
 
902636
@@ -758,8 +757,8 @@ int tcp_emu(struct socket *so, struct mbuf *m)
902636
         if (m->m_data[m->m_len - 1] == '\0' && lport != 0 &&
902636
             (so = tcp_listen(slirp, INADDR_ANY, 0, so->so_laddr.s_addr,
902636
                              htons(lport), SS_FACCEPTONCE)) != NULL)
902636
-            m->m_len =
902636
-                snprintf(m->m_data, m->m_size, "%d", ntohs(so->so_fport)) + 1;
902636
+            m->m_len = snprintf(m->m_data, M_ROOM(m),
902636
+                                "%d", ntohs(so->so_fport)) + 1;
902636
         return 1;
d8ab4a
 
902636
     case EMU_IRC:
d8ab4a
-- 
d8ab4a
1.8.3.1
d8ab4a