133 lines
5.9 KiB
Diff
133 lines
5.9 KiB
Diff
|
From 2655fffed7a9e765bcb4701dd876e9dab975f289 Mon Sep 17 00:00:00 2001
|
||
|
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
|
||
|
Date: Wed, 8 Jan 2020 00:58:48 +0100
|
||
|
Subject: [PATCH] tcp_emu: Fix oob access
|
||
|
|
||
|
The main loop only checks for one available byte, while we sometimes
|
||
|
need two bytes.
|
||
|
|
||
|
2.24.1
|
||
|
|
||
|
From 82ebe9c370a0e2970fb5695aa19aa5214a6a1c80 Mon Sep 17 00:00:00 2001
|
||
|
From: Prasad J Pandit <pjp@fedoraproject.org>
|
||
|
Date: Thu, 9 Jan 2020 15:12:28 +0530
|
||
|
Subject: [PATCH] slirp: use correct size while emulating commands
|
||
|
|
||
|
While emulating services in tcp_emu(), it uses 'mbuf' size
|
||
|
'm->m_size' to write commands via snprintf(3). Use M_FREEROOM(m)
|
||
|
size to avoid possible OOB access.
|
||
|
|
||
|
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
|
||
|
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
|
||
|
Message-Id: <20200109094228.79764-3-ppandit@redhat.com>
|
||
|
|
||
|
2.24.1
|
||
|
|
||
|
From ce131029d6d4a405cb7d3ac6716d03e58fb4a5d9 Mon Sep 17 00:00:00 2001
|
||
|
From: Prasad J Pandit <pjp@fedoraproject.org>
|
||
|
Date: Thu, 9 Jan 2020 15:12:27 +0530
|
||
|
Subject: [PATCH] slirp: use correct size while emulating IRC commands
|
||
|
|
||
|
While emulating IRC DCC commands, tcp_emu() uses 'mbuf' size
|
||
|
'm->m_size' to write DCC commands via snprintf(3). This may
|
||
|
lead to OOB write access, because 'bptr' points somewhere in
|
||
|
the middle of 'mbuf' buffer, not at the start. Use M_FREEROOM(m)
|
||
|
size to avoid OOB access.
|
||
|
|
||
|
Reported-by: Vishnu Dev TJ <vishnudevtj@gmail.com>
|
||
|
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
|
||
|
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
|
||
|
Message-Id: <20200109094228.79764-2-ppandit@redhat.com>
|
||
|
|
||
|
---
|
||
|
CHANGELOG.md | 1 +
|
||
|
src/tcp_subr.c | 7 +++++++
|
||
|
2 files changed, 8 insertions(+)
|
||
|
|
||
|
diff -up ./slirp4netns-21fdece2737dc24ffa3f01a341b8a6854f8b13b4/vendor/libslirp/src/tcp_subr.c.CVE-2020-7039 ./slirp4netns-21fdece2737dc24ffa3f01a341b8a6854f8b13b4/vendor/libslirp/src/tcp_subr.c
|
||
|
--- slirp4netns-21fdece2737dc24ffa3f01a341b8a6854f8b13b4/vendor/libslirp/src/tcp_subr.c.CVE-2020-7039 2020-01-16 11:13:43.472696979 +0100
|
||
|
+++ slirp4netns-21fdece2737dc24ffa3f01a341b8a6854f8b13b4/vendor/libslirp/src/tcp_subr.c 2020-01-16 11:13:43.474697002 +0100
|
||
|
@@ -692,7 +692,7 @@ int tcp_emu(struct socket *so, struct mb
|
||
|
n4 = (laddr & 0xff);
|
||
|
|
||
|
m->m_len = bptr - m->m_data; /* Adjust length */
|
||
|
- m->m_len += snprintf(bptr, m->m_size - m->m_len,
|
||
|
+ 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 : "");
|
||
|
return 1;
|
||
|
@@ -727,8 +727,7 @@ int tcp_emu(struct socket *so, struct mb
|
||
|
n4 = (laddr & 0xff);
|
||
|
|
||
|
m->m_len = bptr - m->m_data; /* Adjust length */
|
||
|
- m->m_len +=
|
||
|
- snprintf(bptr, m->m_size - m->m_len,
|
||
|
+ 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 : "");
|
||
|
|
||
|
@@ -754,8 +753,8 @@ int tcp_emu(struct socket *so, struct mb
|
||
|
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->m_size, "%d", ntohs(so->so_fport)) + 1;
|
||
|
+ m->m_len = snprintf(m->m_data, M_ROOM(m),
|
||
|
+ "%d", ntohs(so->so_fport)) + 1;
|
||
|
return 1;
|
||
|
|
||
|
case EMU_IRC:
|
||
|
@@ -774,7 +773,8 @@ int tcp_emu(struct socket *so, struct mb
|
||
|
return 1;
|
||
|
}
|
||
|
m->m_len = bptr - m->m_data; /* Adjust length */
|
||
|
- m->m_len += snprintf(bptr, m->m_size, "DCC CHAT chat %lu %u%c\n",
|
||
|
+ 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);
|
||
|
} else if (sscanf(bptr, "DCC SEND %256s %u %u %u", buff, &laddr, &lport,
|
||
|
@@ -784,8 +784,8 @@ int tcp_emu(struct socket *so, struct mb
|
||
|
return 1;
|
||
|
}
|
||
|
m->m_len = bptr - m->m_data; /* Adjust length */
|
||
|
- m->m_len +=
|
||
|
- snprintf(bptr, m->m_size, "DCC SEND %s %lu %u %u%c\n", buff,
|
||
|
+ 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);
|
||
|
} else if (sscanf(bptr, "DCC MOVE %256s %u %u %u", buff, &laddr, &lport,
|
||
|
@@ -795,8 +795,8 @@ int tcp_emu(struct socket *so, struct mb
|
||
|
return 1;
|
||
|
}
|
||
|
m->m_len = bptr - m->m_data; /* Adjust length */
|
||
|
- m->m_len +=
|
||
|
- snprintf(bptr, m->m_size, "DCC MOVE %s %lu %u %u%c\n", buff,
|
||
|
+ 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);
|
||
|
}
|
||
|
@@ -882,6 +882,9 @@ int tcp_emu(struct socket *so, struct mb
|
||
|
break;
|
||
|
|
||
|
case 5:
|
||
|
+ if (bptr == m->m_data + m->m_len - 1)
|
||
|
+ return 1; /* We need two bytes */
|
||
|
+
|
||
|
/*
|
||
|
* The difference between versions 1.0 and
|
||
|
* 2.0 is here. For future versions of
|
||
|
@@ -897,6 +900,10 @@ int tcp_emu(struct socket *so, struct mb
|
||
|
/* This is the field containing the port
|
||
|
* number that RA-player is listening to.
|
||
|
*/
|
||
|
+
|
||
|
+ if (bptr == m->m_data + m->m_len - 1)
|
||
|
+ return 1; /* We need two bytes */
|
||
|
+
|
||
|
lport = (((uint8_t *)bptr)[0] << 8) + ((uint8_t *)bptr)[1];
|
||
|
if (lport < 6970)
|
||
|
lport += 256; /* don't know why */
|