From patchwork Mon Sep 26 08:59:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 675053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 3sjJsY1r1sz9s65 for ; Mon, 26 Sep 2016 19:42:22 +1000 (AEST) Received: from localhost ([::1]:42797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1boSQW-0005M2-AW for incoming@patchwork.ozlabs.org; Mon, 26 Sep 2016 05:42:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1boRma-00088R-Ub for qemu-devel@nongnu.org; Mon, 26 Sep 2016 05:01:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1boRmV-0000Rq-OG for qemu-devel@nongnu.org; Mon, 26 Sep 2016 05:01:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38968) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1boRmV-0000RY-I4 for qemu-devel@nongnu.org; Mon, 26 Sep 2016 05:00:59 -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 F2C1F13A9A; Mon, 26 Sep 2016 09:00:58 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-6-89.pek2.redhat.com [10.72.6.89]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8Q8xaol023616; Mon, 26 Sep 2016 05:00:56 -0400 From: Jason Wang To: peter.maydell@linaro.org Date: Mon, 26 Sep 2016 16:59:33 +0800 Message-Id: <1474880375-22946-26-git-send-email-jasowang@redhat.com> In-Reply-To: <1474880375-22946-1-git-send-email-jasowang@redhat.com> References: <1474880375-22946-1-git-send-email-jasowang@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.29]); Mon, 26 Sep 2016 09:00:59 +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] [PULL 25/27] net: mcf: limit buffer descriptor count 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: Jason Wang , qemu-devel@nongnu.org, Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Prasad J Pandit ColdFire Fast Ethernet Controller uses buffer descriptors to manage data flow to/fro receive & transmit queues. While transmitting packets, it could continue to read buffer descriptors if a buffer descriptor has length of zero and has crafted values in bd.flags. Set upper limit to number of buffer descriptors. Reported-by: Li Qiang Signed-off-by: Prasad J Pandit Reviewed-by: Paolo Bonzini Signed-off-by: Jason Wang --- hw/net/mcf_fec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/net/mcf_fec.c b/hw/net/mcf_fec.c index 0ee8ad9..d31fea1 100644 --- a/hw/net/mcf_fec.c +++ b/hw/net/mcf_fec.c @@ -23,6 +23,7 @@ do { printf("mcf_fec: " fmt , ## __VA_ARGS__); } while (0) #define DPRINTF(fmt, ...) do {} while(0) #endif +#define FEC_MAX_DESC 1024 #define FEC_MAX_FRAME_SIZE 2032 typedef struct { @@ -149,7 +150,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s) uint32_t addr; mcf_fec_bd bd; int frame_size; - int len; + int len, descnt = 0; uint8_t frame[FEC_MAX_FRAME_SIZE]; uint8_t *ptr; @@ -157,7 +158,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s) ptr = frame; frame_size = 0; addr = s->tx_descriptor; - while (1) { + while (descnt++ < FEC_MAX_DESC) { mcf_fec_read_bd(&bd, addr); DPRINTF("tx_bd %x flags %04x len %d data %08x\n", addr, bd.flags, bd.length, bd.data);