c461a1
From 896665af83060fb673fc12081083f53a10a19dc5 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:36 +0100
c461a1
Subject: [PATCH 2/3] slirp: use correct size while emulating IRC 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-3-philmd@redhat.com>
c461a1
Patchwork-id: 93396
c461a1
O-Subject: [RHEL-7.7.z qemu-kvm + RHEL-7.8 qemu-kvm + RHEL-7.9 qemu-kvm PATCH v2 2/3] slirp: use correct size while emulating IRC 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 IRC DCC commands, tcp_emu() uses 'mbuf' size
c461a1
'm->m_size' to write DCC commands via snprintf(3). This may
c461a1
lead to OOB write access, because 'bptr' points somewhere in
c461a1
the middle of 'mbuf' buffer, not at the start. Use M_FREEROOM(m)
c461a1
size to avoid OOB access.
c461a1
c461a1
Reported-by: Vishnu Dev TJ <vishnudevtj@gmail.com>
c461a1
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
c461a1
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
c461a1
Message-Id: <20200109094228.79764-2-ppandit@redhat.com>
c461a1
(cherry picked from libslirp commit ce131029d6d4a405cb7d3ac6716d03e58fb4a5d9)
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 | 6 +++---
c461a1
 1 file changed, 3 insertions(+), 3 deletions(-)
c461a1
c461a1
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
c461a1
index 70a4c83..321c2a4 100644
c461a1
--- a/slirp/tcp_subr.c
c461a1
+++ b/slirp/tcp_subr.c
c461a1
@@ -728,7 +728,7 @@ tcp_emu(struct socket *so, struct mbuf *m)
c461a1
 				return 1;
c461a1
 			}
c461a1
 			m->m_len = bptr - m->m_data; /* Adjust length */
c461a1
-                        m->m_len += snprintf(bptr, m->m_size,
c461a1
+                        m->m_len += snprintf(bptr, M_FREEROOM(m),
c461a1
                                              "DCC CHAT chat %lu %u%c\n",
c461a1
                                              (unsigned long)ntohl(so->so_faddr.s_addr),
c461a1
                                              ntohs(so->so_fport), 1);
c461a1
@@ -739,7 +739,7 @@ tcp_emu(struct socket *so, struct mbuf *m)
c461a1
 				return 1;
c461a1
 			}
c461a1
 			m->m_len = bptr - m->m_data; /* Adjust length */
c461a1
-                        m->m_len += snprintf(bptr, m->m_size,
c461a1
+                        m->m_len += snprintf(bptr, M_FREEROOM(m),
c461a1
                                              "DCC SEND %s %lu %u %u%c\n", buff,
c461a1
                                              (unsigned long)ntohl(so->so_faddr.s_addr),
c461a1
                                              ntohs(so->so_fport), n1, 1);
c461a1
@@ -750,7 +750,7 @@ tcp_emu(struct socket *so, struct mbuf *m)
c461a1
 				return 1;
c461a1
 			}
c461a1
 			m->m_len = bptr - m->m_data; /* Adjust length */
c461a1
-                        m->m_len += snprintf(bptr, m->m_size,
c461a1
+                        m->m_len += snprintf(bptr, M_FREEROOM(m),
c461a1
                                              "DCC MOVE %s %lu %u %u%c\n", buff,
c461a1
                                              (unsigned long)ntohl(so->so_faddr.s_addr),
c461a1
                                              ntohs(so->so_fport), n1, 1);
c461a1
-- 
c461a1
1.8.3.1
c461a1