From c894cd80e9b6c7c317da2dbeacf52a34dc5efdbb Mon Sep 17 00:00:00 2001 From: Xiao Wang Date: Fri, 22 Feb 2019 08:32:02 +0000 Subject: [PATCH] slirp: check data length while emulating ident function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RH-Author: Xiao Wang Message-id: <20190222083202.20283-1-jasowang@redhat.com> Patchwork-id: 84699 O-Subject: [RHEL8/rhel qemu-kvm PATCH] slirp: check data length while emulating ident function Bugzilla: 1669069 RH-Acked-by: Jens Freimann RH-Acked-by: Maxime Coquelin RH-Acked-by: Philippe Mathieu-Daudé From: Prasad J Pandit Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1669069 Brew Build: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20325086 Test status: Tested by myself Branch: rhel8/master-2.12.0 While emulating identification protocol, tcp_emu() does not check available space in the 'sc_rcv->sb_data' buffer. It could lead to heap buffer overflow issue. Add check to avoid it. Reported-by: Kira <864786842@qq.com> Signed-off-by: Prasad J Pandit Signed-off-by: Samuel Thibault (cherry picked from commit a7104eda7dab99d0cdbd3595c211864cba415905) Signed-off-by: Danilo C. L. de Paula --- slirp/tcp_subr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index da0d537..1c7eb28 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -638,6 +638,11 @@ tcp_emu(struct socket *so, struct mbuf *m) socklen_t addrlen = sizeof(struct sockaddr_in); struct sbuf *so_rcv = &so->so_rcv; + if (m->m_len > so_rcv->sb_datalen + - (so_rcv->sb_wptr - so_rcv->sb_data)) { + return 1; + } + memcpy(so_rcv->sb_wptr, m->m_data, m->m_len); so_rcv->sb_wptr += m->m_len; so_rcv->sb_rptr += m->m_len; -- 1.8.3.1