From nobody Tue Apr 30 12:59:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486460665250756.7879734788403; Tue, 7 Feb 2017 01:44:25 -0800 (PST) Received: from localhost ([::1]:52901 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cb2Jy-0007rq-CY for importer@patchew.org; Tue, 07 Feb 2017 04:44:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cb2J8-0007Zp-1L for qemu-devel@nongnu.org; Tue, 07 Feb 2017 04:43:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cb2J4-00044H-T1 for qemu-devel@nongnu.org; Tue, 07 Feb 2017 04:43:30 -0500 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:35822) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cb2J4-00043f-Lq for qemu-devel@nongnu.org; Tue, 07 Feb 2017 04:43:26 -0500 Received: by mail-lf0-x241.google.com with SMTP id v186so6159789lfa.2 for ; Tue, 07 Feb 2017 01:43:25 -0800 (PST) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id v2sm1108792lja.31.2017.02.07.01.43.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Feb 2017 01:43:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:from:to:cc:subject:date; bh=8W+XKyignuCsN9r3In8g2YCNZwL1zkhkj/cOgD9AU3k=; b=mcSKxK69g5kVcLWNkJd1RXPw4De6iTU3M6qSNB4L8wM3pffD2ByYV/2sQVefKfMC57 2vHywcxoBkzJXMUCL4Pz1NYYvCLzjQGp7STcHxK72SqNQfNsIurjlZ5hiarGUOROkjkL i7nyM+J6QdHRgT5dEMQGU01gJGeLh48LXi9pikJdRtTmhRbyhMOQlCl0xh57xmzLva24 /UNCdhjB6LmKUpWpnex0/vju76Y1g0dMwbZmw3L9uk0F9xU11jGFerAPak+e6CcFOhPz oeumv+VdOi324X5jSVweDWDcHYuP+UudJwCBqTiQ6yv3s9AOsfpIEHGh1dMShx28Y8/X uaXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:from:to:cc:subject:date; bh=8W+XKyignuCsN9r3In8g2YCNZwL1zkhkj/cOgD9AU3k=; b=nZ1vN8+VpCmoF3FMoG6yhyZiSThoeaH8ak3toojEKyYHHZMA/L0HeCSMxubmXAmFvd ZfnX0vSNz8/j7r5Z3Q/AvGpTyWANvCh3uvC98zo5e+69uKdQw26PTlQVSeNJG+5jzet1 bM7zjWjn89HdvFi9pr0vZ4sZLxQVTjtjUIgR5ylhC7BmBWba/nVoxiMZmX1DGYBuX3Df +UlWTQd8bA3GMcALxI6W2CI9+XM8yejl4FET6NWVtCLpNNr/H/SkNZMnslpDor1M5Agf qKJgCi8ddx0x6HhA5iewoiWl5uLQY0qc1w5U22gHtLMQu5FQG5qK+nhV//L1cAq16hSB v9sw== X-Gm-Message-State: AIkVDXI73/xrRtRE8UZO+V9IP1cAyr/rDHjS2T/HJd8uR3T5qr5+efxNN6OTDf9PtzzNAg== X-Received: by 10.46.9.20 with SMTP id 20mr5898400ljj.0.1486460603761; Tue, 07 Feb 2017 01:43:23 -0800 (PST) Message-ID: <589996bb.02482e0a.10629.5b0e@mx.google.com> X-Google-Original-Message-ID: <1486460588-117125-1-git-send-email-Qiang(liqiang6-s@360.cn)> From: Li Qiang X-Google-Original-From: Li Qiang(liqiang6-s@360.cn) To: dmitry@daynix.com, jasowang@redhat.com, qemu-devel@nongnu.org Date: Tue, 7 Feb 2017 01:43:08 -0800 X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::241 Subject: [Qemu-devel] [PATCH] net: e1000e: fix an infinite loop issue 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: Li Qiang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Li Qiang This issue is the same as e1000 network card in this commit: e1000: eliminate infinite loops on out-of-bounds transfer start. Signed-off-by: Li Qiang --- hw/net/e1000e_core.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index 2b11499..53f2b1d 100644 --- a/hw/net/e1000e_core.c +++ b/hw/net/e1000e_core.c @@ -914,7 +914,8 @@ e1000e_start_xmit(E1000ECore *core, const E1000E_TxRing= *txr) struct e1000_tx_desc desc; bool ide =3D false; const E1000E_RingInfo *txi =3D txr->i; - uint32_t cause =3D E1000_ICS_TXQE; + uint32_t tdh_start =3D core->mac[txi->dh], cause =3D E1000_ICS_TXQE; + =20 if (!(core->mac[TCTL] & E1000_TCTL_EN)) { trace_e1000e_tx_disabled(); @@ -933,6 +934,14 @@ e1000e_start_xmit(E1000ECore *core, const E1000E_TxRin= g *txr) cause |=3D e1000e_txdesc_writeback(core, base, &desc, &ide, txi->i= dx); =20 e1000e_ring_advance(core, txi, 1); + + /* + * The following avoid infinite loop, just as the e1000 + */ + if (core->mac[txi->dh] =3D=3D tdh_start || + tdh_start >=3D core->mac[txi->dlen] / E1000_RING_DESC_LEN) { + break; + } } =20 if (!ide || !e1000e_intrmgr_delay_tx_causes(core, &cause)) { @@ -1500,6 +1509,7 @@ e1000e_write_packet_to_guest(E1000ECore *core, struct= NetRxPkt *pkt, size_t desc_size; size_t desc_offset =3D 0; size_t iov_ofs =3D 0; + uint32_t rdh_start; =20 struct iovec *iov =3D net_rx_pkt_get_iovec(pkt); size_t size =3D net_rx_pkt_get_total_len(pkt); @@ -1509,6 +1519,7 @@ e1000e_write_packet_to_guest(E1000ECore *core, struct= NetRxPkt *pkt, bool do_ps =3D e1000e_do_ps(core, pkt, &ps_hdr_len); =20 rxi =3D rxr->i; + rdh_start =3D core->mac[rxi->dh]; =20 do { hwaddr ba[MAX_PS_BUFFERS]; @@ -1605,6 +1616,10 @@ e1000e_write_packet_to_guest(E1000ECore *core, struc= t NetRxPkt *pkt, e1000e_ring_advance(core, rxi, core->rx_desc_len / E1000_MIN_RX_DESC_LEN); =20 + if (core->mac[rxi->dh] =3D=3D rdh_start || + rdh_start >=3D core->mac[rxi->dlen] / E1000_RING_DESC_LEN) { + break; + } } while (desc_offset < total_size); =20 e1000e_update_rx_stats(core, size, total_size); --=20 1.8.3.1