From nobody Tue Feb 10 23:54:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1682223871; cv=none; d=zohomail.com; s=zohoarc; b=g6jMFJGcl2zjwueOyEQWkWFBAbzLf1umOX+AU8dgJtYu8nla+GcFvCLdoQd5p3iuJy78JdHKOjLSQsB1QjZGQGzboL/3JAQOkmvXpdlccM/optBHTajs+A5+GBPGi650gCz+EgpP3ToABOvFdujhdeEyQ2j/5aOXIFIi8fQSPAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682223871; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject; bh=VY0RJ2zeL4ADYhynCOJEmTANyW901p2WIKUi3FWJhB8=; b=jQtMO6rplGx2f1DcMZ0KnQl+XFF7QI6dtg6CnoIk7rTdSth3rioTz7GPVAw12fhsvYIXkwcC1DvqIANVgNrm/Sv8M6nWHaRcsBTqnoGCe1GxuD/nvAJOUM98dPHyEcXk0Vs6kPC81hqE7bZaEzwTPCUwYdfofcN/+B5tsszzBQs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168222387189012.940481758945225; Sat, 22 Apr 2023 21:24:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pqRBy-0001rO-Vh; Sun, 23 Apr 2023 00:19:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pqRBx-0001r6-3x for qemu-devel@nongnu.org; Sun, 23 Apr 2023 00:19:13 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pqRBv-0000lV-HE for qemu-devel@nongnu.org; Sun, 23 Apr 2023 00:19:12 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5208be24dcbso2628830a12.1 for ; Sat, 22 Apr 2023 21:19:11 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:4457:c267:5e09:481b]) by smtp.gmail.com with ESMTPSA id f1-20020a170902ff0100b001a5059861adsm4596996plj.224.2023.04.22.21.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Apr 2023 21:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1682223550; x=1684815550; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VY0RJ2zeL4ADYhynCOJEmTANyW901p2WIKUi3FWJhB8=; b=WwfTgwtHW/4kdfL7zuElcSaFlK3/hg07Vh93AixJSw5nwRaMD1aSWw+SH/LiyVAty6 5MoeCsySVH9D1hJNqz5V6Nt2fXa0UGODNEbBWxsyOnlyWhV9hlTQrryi3FdDh/XeOTeX TmEmWX5p6lXcCoUUJIzLrZAmWRGeMARhIuAMEkhdxy+H0CEECcX9YBQSZcHtD1rOHO2a S2j0f61coaZ+qLNyhPmAnC0I/Lmy6H2XJi9Myv6ITiBmyb7t6IuKVlU9nj4ze+l3u/xN VAof0sK+AASKSM2zeLiSt1d4yOUh6h4CzDA+GI9j1u423m93gNzU0EmBB4PyY+8Og+v0 BADA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682223550; x=1684815550; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VY0RJ2zeL4ADYhynCOJEmTANyW901p2WIKUi3FWJhB8=; b=dbGqaiMI5ArXcZlYU8IhgCtnqKcmmUxpoAhZm1ctd6hDl6iGjmRL4A3HrXkv93+9/m 4tfCngbuJvY78qhkg38ZhTCVivvL5bGzv1bzWYxzhPxLl22TZFKXDq3DsKlIj4VKnT9v aj5BOGemBsco3hkhQDERMk3zZ3MJ6kolVu6W2iNrC3Eocf5KKU+qyv4RjKbc7qc+9jj9 0QEI4XJkIE2Z+EYiJhVJgeDz4NxG3AOv4lGPq7/ACMlyph/Aw4tPt7320qeVc82Cviyc izfulvts8hCWaF7ott+OB1TxoPZU71DlAfpoRL7U3zkX3vGmn4GHlDL0A4EPWfJgv5uy OddQ== X-Gm-Message-State: AAQBX9cwwIXmA0ZLAR08TriW/fNGG07ATLAL3vXDZsH0w586qkLSyStZ TKZxOmISRz6zIt9213ptUt0M3A== X-Google-Smtp-Source: AKy350Ykka3HsFBZxEgYqt6vJ8dScXS07G6BKQD+G+eDL5rA2yRytVdDWKsQMvB63QbL7XeSsnW8mg== X-Received: by 2002:a17:902:c405:b0:1a6:f5d5:b80a with SMTP id k5-20020a170902c40500b001a6f5d5b80amr13837198plk.38.1682223550363; Sat, 22 Apr 2023 21:19:10 -0700 (PDT) From: Akihiko Odaki To: Cc: Sriram Yagnaraman , Jason Wang , Dmitry Fleytman , "Michael S . Tsirkin" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Thomas Huth , Wainer dos Santos Moschetta , Beraldo Leal , Cleber Rosa , Laurent Vivier , Paolo Bonzini , qemu-devel@nongnu.org, Tomasz Dzieciol , Akihiko Odaki Subject: [PATCH v3 08/47] e1000e: Always copy ethernet header Date: Sun, 23 Apr 2023 13:17:54 +0900 Message-Id: <20230423041833.5302-9-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230423041833.5302-1-akihiko.odaki@daynix.com> References: <20230423041833.5302-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::536; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20221208.gappssmtp.com) X-ZM-MESSAGEID: 1682223872656100001 Content-Type: text/plain; charset="utf-8" e1000e_receive_internal() used to check the iov length to determine copy the iovs to a contiguous buffer, but the check is flawed in two ways: - It does not ensure that iovcnt > 0. - It does not take virtio-net header into consideration. The size of this copy is just 18 octets, which can be even less than the code size required for checks. This (wrong) optimization is probably not worth so just remove it. Fixes: 6f3fbe4ed0 ("net: Introduce e1000e device emulation") Signed-off-by: Akihiko Odaki --- hw/net/e1000e_core.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index c2d864a504..f3335194d8 100644 --- a/hw/net/e1000e_core.c +++ b/hw/net/e1000e_core.c @@ -1686,12 +1686,9 @@ static ssize_t e1000e_receive_internal(E1000ECore *core, const struct iovec *iov, int iov= cnt, bool has_vnet) { - static const int maximum_ethernet_hdr_len =3D (ETH_HLEN + 4); - uint32_t n =3D 0; uint8_t min_buf[ETH_ZLEN]; struct iovec min_iov; - uint8_t *filter_buf; size_t size, orig_size; size_t iov_ofs =3D 0; E1000E_RxRing rxr; @@ -1714,7 +1711,6 @@ e1000e_receive_internal(E1000ECore *core, const struc= t iovec *iov, int iovcnt, net_rx_pkt_unset_vhdr(core->rx_pkt); } =20 - filter_buf =3D iov->iov_base + iov_ofs; orig_size =3D iov_size(iov, iovcnt); size =3D orig_size - iov_ofs; =20 @@ -1723,15 +1719,13 @@ e1000e_receive_internal(E1000ECore *core, const str= uct iovec *iov, int iovcnt, iov_to_buf(iov, iovcnt, iov_ofs, min_buf, size); memset(&min_buf[size], 0, sizeof(min_buf) - size); e1000x_inc_reg_if_not_full(core->mac, RUC); - min_iov.iov_base =3D filter_buf =3D min_buf; + min_iov.iov_base =3D min_buf; min_iov.iov_len =3D size =3D sizeof(min_buf); iovcnt =3D 1; iov =3D &min_iov; iov_ofs =3D 0; - } else if (iov->iov_len < maximum_ethernet_hdr_len) { - /* This is very unlikely, but may happen. */ - iov_to_buf(iov, iovcnt, iov_ofs, min_buf, maximum_ethernet_hdr_len= ); - filter_buf =3D min_buf; + } else { + iov_to_buf(iov, iovcnt, iov_ofs, min_buf, ETH_HLEN + 4); } =20 /* Discard oversized packets if !LPE and !SBP. */ @@ -1740,9 +1734,9 @@ e1000e_receive_internal(E1000ECore *core, const struc= t iovec *iov, int iovcnt, } =20 net_rx_pkt_set_packet_type(core->rx_pkt, - get_eth_packet_type(PKT_GET_ETH_HDR(filter_buf))); + get_eth_packet_type(PKT_GET_ETH_HDR(min_buf))); =20 - if (!e1000e_receive_filter(core, filter_buf, size)) { + if (!e1000e_receive_filter(core, min_buf, size)) { trace_e1000e_rx_flt_dropped(); return orig_size; } --=20 2.40.0