From patchwork Sun Jan 13 17:59:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 10761367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5DA6813BF for ; Sun, 13 Jan 2019 18:02:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CF8C2882E for ; Sun, 13 Jan 2019 18:02:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AF5428884; Sun, 13 Jan 2019 18:02:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AFC8C2882E for ; Sun, 13 Jan 2019 18:02:58 +0000 (UTC) Received: from localhost ([127.0.0.1]:50471 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gik66-0007rK-5E for patchwork-qemu-devel@patchwork.kernel.org; Sun, 13 Jan 2019 13:02:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gik5F-0007VL-12 for qemu-devel@nongnu.org; Sun, 13 Jan 2019 13:02:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gik5D-0004ln-RX for qemu-devel@nongnu.org; Sun, 13 Jan 2019 13:02:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48816) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gik5D-0004h6-LU for qemu-devel@nongnu.org; Sun, 13 Jan 2019 13:02:03 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBD3387628; Sun, 13 Jan 2019 18:01:54 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A495C600C8; Sun, 13 Jan 2019 18:01:51 +0000 (UTC) From: P J P To: QEMU Developers Date: Sun, 13 Jan 2019 23:29:48 +0530 Message-Id: <20190113175948.21076-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 13 Jan 2019 18:01:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2] slirp: check data length while emulating ident function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , Jan Kiszka , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Samuel Thibault , Kira <864786842@qq.com> Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Prasad J Pandit 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 --- slirp/tcp_subr.c | 4 ++++ 1 file changed, 4 insertions(+) Update v2: return 1 instead of 0 -> https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg02182.html diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c index fa61349cbb..8b1bd8c8c0 100644 --- a/slirp/tcp_subr.c +++ b/slirp/tcp_subr.c @@ -635,6 +635,10 @@ 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;