Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP7:GA
qemu-testsuite.20748
0116-tcp_emu-fix-unsafe-snprintf-usages.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0116-tcp_emu-fix-unsafe-snprintf-usages.patch of Package qemu-testsuite.20748
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com> Date: Mon, 27 Jan 2020 10:24:14 +0100 Subject: tcp_emu: fix unsafe snprintf() usages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Git-commit: 68ccb8021a838066f0951d4b2817eb6b6f10a843 References: bsc#1163018, CVE-2020-8608 Various calls to snprintf() assume that snprintf() returns "only" the number of bytes written (excluding terminating NUL). https://pubs.opengroup.org/onlinepubs/9699919799/functions/snprintf.html#tag_16_159_04 "Upon successful completion, the snprintf() function shall return the number of bytes that would be written to s had n been sufficiently large excluding the terminating null byte." Before patch ce131029, if there isn't enough room in "m_data" for the "DCC ..." message, we overflow "m_data". After the patch, if there isn't enough room for the same, we don't overflow "m_data", but we set "m_len" out-of-bounds. The next time an access is bounded by "m_len", we'll have a buffer overflow then. Use slirp_fmt*() to fix potential OOB memory access. Reported-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Message-Id: <20200127092414.169796-7-marcandre.lureau@redhat.com> [Since porting from a quite different now libslirp, quite a bit changed] Signed-off-by: Bruce Rogers <brogers@suse.com> --- slirp/slirp.h | 1 + slirp/tcp_subr.c | 43 +++++++++++++++++++++---------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/slirp/slirp.h b/slirp/slirp.h index b80725a0d6d1c9d0bb54978f638c..09f218d85e14f0123d939253a62a 100644 --- a/slirp/slirp.h +++ b/slirp/slirp.h @@ -70,6 +70,7 @@ typedef char *caddr_t; #include "debug.h" +#include "util.h" #include "qemu/queue.h" #include "qemu/sockets.h" diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index fe801b6b54252f0062123cb93481..6acbfc643403c2428aebd096cbf4 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -658,8 +658,7 @@ tcp_emu(struct socket *so, struct mbuf *m) NTOHS(n1); NTOHS(n2); m_inc(m, snprintf(NULL, 0, "%d,%d\r\n", n1, n2) + 1); - m->m_len = snprintf(m->m_data, M_ROOM(m), "%d,%d\r\n", n1, n2); - assert(m->m_len < M_ROOM(m)); + m->m_len = slirp_fmt(m->m_data, M_ROOM(m), "%d,%d\r\n", n1, n2); } else { *eol = '\r'; } @@ -699,9 +698,9 @@ tcp_emu(struct socket *so, struct mbuf *m) n4 = (laddr & 0xff); m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += snprintf(bptr, M_FREEROOM(m), - "ORT %d,%d,%d,%d,%d,%d\r\n%s", - n1, n2, n3, n4, n5, n6, x==7?buff:""); + m->m_len += slirp_fmt(bptr, M_FREEROOM(m), + "ORT %d,%d,%d,%d,%d,%d\r\n%s", + n1, n2, n3, n4, n5, n6, x==7?buff:""); return 1; } else if ((bptr = (char *)strstr(m->m_data, "27 Entering")) != NULL) { /* @@ -732,9 +731,9 @@ tcp_emu(struct socket *so, struct mbuf *m) n4 = (laddr & 0xff); m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += snprintf(bptr, M_FREEROOM(m), - "27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%s", - n1, n2, n3, n4, n5, n6, x==7?buff:""); + m->m_len += slirp_fmt(bptr, M_FREEROOM(m), + "27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%s", + n1, n2, n3, n4, n5, n6, x==7?buff:""); return 1; } @@ -758,8 +757,8 @@ tcp_emu(struct socket *so, struct mbuf *m) if (m->m_data[m->m_len-1] == '\0' && lport != 0 && (so = tcp_listen(slirp, INADDR_ANY, 0, so->so_laddr.s_addr, htons(lport), SS_FACCEPTONCE)) != NULL) - m->m_len = snprintf(m->m_data, M_ROOM(m), "%d", - ntohs(so->so_fport)) + 1; + m->m_len = slirp_fmt0(m->m_data, M_ROOM(m), "%d", + ntohs(so->so_fport)); return 1; case EMU_IRC: @@ -779,10 +778,10 @@ tcp_emu(struct socket *so, struct mbuf *m) return 1; } m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += snprintf(bptr, M_FREEROOM(m), - "DCC CHAT chat %lu %u%c\n", - (unsigned long)ntohl(so->so_faddr.s_addr), - ntohs(so->so_fport), 1); + m->m_len += slirp_fmt(bptr, M_FREEROOM(m), + "DCC CHAT chat %lu %u%c\n", + (unsigned long)ntohl(so->so_faddr.s_addr), + ntohs(so->so_fport), 1); } else if (sscanf(bptr, "DCC SEND %256s %u %u %u", buff, &laddr, &lport, &n1) == 4) { if ((so = tcp_listen(slirp, INADDR_ANY, 0, htonl(laddr), htons(lport), @@ -790,10 +789,10 @@ tcp_emu(struct socket *so, struct mbuf *m) return 1; } m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += snprintf(bptr, M_FREEROOM(m), - "DCC SEND %s %lu %u %u%c\n", buff, - (unsigned long)ntohl(so->so_faddr.s_addr), - ntohs(so->so_fport), n1, 1); + m->m_len += slirp_fmt(bptr, M_FREEROOM(m), + "DCC SEND %s %lu %u %u%c\n", buff, + (unsigned long)ntohl(so->so_faddr.s_addr), + ntohs(so->so_fport), n1, 1); } else if (sscanf(bptr, "DCC MOVE %256s %u %u %u", buff, &laddr, &lport, &n1) == 4) { if ((so = tcp_listen(slirp, INADDR_ANY, 0, htonl(laddr), htons(lport), @@ -801,10 +800,10 @@ tcp_emu(struct socket *so, struct mbuf *m) return 1; } m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += snprintf(bptr, M_FREEROOM(m), - "DCC MOVE %s %lu %u %u%c\n", buff, - (unsigned long)ntohl(so->so_faddr.s_addr), - ntohs(so->so_fport), n1, 1); + m->m_len += slirp_fmt(bptr, M_FREEROOM(m), + "DCC MOVE %s %lu %u %u%c\n", buff, + (unsigned long)ntohl(so->so_faddr.s_addr), + ntohs(so->so_fport), n1, 1); } return 1;
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor