[Slirp] [PATCH] slirp: use correct size while emulating IRC commands
Philippe Mathieu-Daudé
philmd at redhat.com
Wed Jan 8 12:31:44 UTC 2020
On 1/8/20 1:23 PM, P J P wrote:
> From: Prasad J Pandit <pjp at fedoraproject.org>
>
> 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 correct
> M_ROOM(m) size to avoid OOB access.
>
> Reported-by: Vishnu Dev TJ <vishnudevtj at gmail.com>
> Signed-off-by: Prasad J Pandit <pjp at fedoraproject.org>
> ---
> src/tcp_subr.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/src/tcp_subr.c b/src/tcp_subr.c
> index 382aa38..b3af5b5 100644
> --- a/src/tcp_subr.c
> +++ b/src/tcp_subr.c
> @@ -763,7 +763,8 @@ int 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->m_size, "DCC CHAT chat %lu %u%c\n",
> + m->m_len += snprintf(bptr, M_ROOM(m) - m->m_len,
Why not use M_FREEROOM() instead?
> + "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,
> @@ -773,8 +774,8 @@ int 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->m_size, "DCC SEND %s %lu %u %u%c\n", buff,
> + m->m_len += snprintf(bptr, M_ROOM(m) - m->m_len,
> + "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,
> @@ -784,8 +785,8 @@ int 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->m_size, "DCC MOVE %s %lu %u %u%c\n", buff,
> + m->m_len += snprintf(bptr, M_ROOM(m) - m->m_len,
> + "DCC MOVE %s %lu %u %u%c\n", buff,
> (unsigned long)ntohl(so->so_faddr.s_addr),
> ntohs(so->so_fport), n1, 1);
> }
>
More information about the Slirp
mailing list