From patchwork Wed Jun 8 10:37:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 9164209 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D368760467 for ; Wed, 8 Jun 2016 10:37:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5C1E262FF for ; Wed, 8 Jun 2016 10:37:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9A3828047; Wed, 8 Jun 2016 10:37:36 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ED8C1262FF for ; Wed, 8 Jun 2016 10:37:35 +0000 (UTC) Received: from localhost ([::1]:55911 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAare-00020e-MX for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Jun 2016 06:37:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50145) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAarQ-00020S-F0 for qemu-devel@nongnu.org; Wed, 08 Jun 2016 06:37:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAarL-0004r0-77 for qemu-devel@nongnu.org; Wed, 08 Jun 2016 06:37:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45661) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAarL-0004qt-0l for qemu-devel@nongnu.org; Wed, 08 Jun 2016 06:37:15 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4F897DCEA; Wed, 8 Jun 2016 10:37:11 +0000 (UTC) Received: from javelin.localdomain (vpn1-7-194.sin2.redhat.com [10.67.7.194]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u58Ab5Xf022082 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 8 Jun 2016 06:37:08 -0400 From: P J P To: Jason Wang Date: Wed, 8 Jun 2016 16:07:04 +0530 Message-Id: <1465382224-6791-1-git-send-email-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 08 Jun 2016 10:37:14 +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] net: mipsnet: check transmit buffer size before sending 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: Peter Maydell , Li Qiang , Prasad J Pandit , Qemu Developers , Leon Alrae , Aurelien Jarno 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 When processing MIPSnet I/O port write operation, it uses a transmit buffer tx_buffer[MAX_ETH_FRAME_SIZE=1514]. Two indices 's->tx_written' and 's->tx_count' are used to control data written to this buffer. If the two were to be equal before writing, it'd lead to an OOB write access beyond tx_buffer. Add check to avoid it. Reported-by: Li Qiang Signed-off-by: Prasad J Pandit --- hw/net/mipsnet.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) Update as per: -> https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg02089.html diff --git a/hw/net/mipsnet.c b/hw/net/mipsnet.c index 740cd98..450e42d 100644 --- a/hw/net/mipsnet.c +++ b/hw/net/mipsnet.c @@ -180,10 +180,12 @@ static void mipsnet_ioport_write(void *opaque, hwaddr addr, break; case MIPSNET_TX_DATA_BUFFER: s->tx_buffer[s->tx_written++] = val; - if (s->tx_written == s->tx_count) { + if ((s->tx_written >= MAX_ETH_FRAME_SIZE) + || (s->tx_written == s->tx_count)) { /* Send buffer. */ - trace_mipsnet_send(s->tx_count); - qemu_send_packet(qemu_get_queue(s->nic), s->tx_buffer, s->tx_count); + trace_mipsnet_send(s->tx_written); + qemu_send_packet(qemu_get_queue(s->nic), + s->tx_buffer, s->tx_written); s->tx_count = s->tx_written = 0; s->intctl |= MIPSNET_INTCTL_TXDONE; s->busy = 1;