From nobody Tue Feb 10 20:08:41 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=1682505491; cv=none; d=zohomail.com; s=zohoarc; b=kCPYRXpTv76/T02+8D7urFxjIh4XophMUmF/oFqPkqQmQBK9cGYxfMkY/5wChSlVDwGcUNRbFPiahc/NHy0UF1iRW6O7z5Scr0V/cherAjEt9ZyJSYR7/LP/usIRpACHJiNl8tv/RThj1fpcR/GUbXarY0+yQnJdq7jGKH42yAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682505491; 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=NNBRwTKoPfNm6mzC2ZqFXQ6r5NBvVjojYda1M3prEL8=; b=AqYL0PfOXy6a4+usEn8RNaR9+I4apGlWYeNa28tjGMLCgzEY3c9zsBCkocmYPqTtz5ZXi2MJl87LWXb6DlgZdQIhf/+mcv0ofdvfZ7qJSgC8/tm0vLzyT2+lyrFDjhEi4KoQDNAuYIoZEiNj9M8YnJu0VWENhMviNtO9qlLW6ME= 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 1682505491494726.0695623490951; Wed, 26 Apr 2023 03:38:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prcXE-0008Oi-Vx; Wed, 26 Apr 2023 06:38:05 -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 1prcX7-00081Y-9b for qemu-devel@nongnu.org; Wed, 26 Apr 2023 06:37:58 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1prcX5-0002vu-Ll for qemu-devel@nongnu.org; Wed, 26 Apr 2023 06:37:56 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-63b50a02bffso5717756b3a.2 for ; Wed, 26 Apr 2023 03:37:55 -0700 (PDT) Received: from alarm.u-tokyo.ac.jp ([157.82.194.15]) by smtp.gmail.com with ESMTPSA id m11-20020a63580b000000b0051322a5aa64sm9317919pgb.3.2023.04.26.03.37.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 03:37:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20221208.gappssmtp.com; s=20221208; t=1682505473; x=1685097473; 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=NNBRwTKoPfNm6mzC2ZqFXQ6r5NBvVjojYda1M3prEL8=; b=xbp7JSXw9OygpZBL6B/c1fxfo9gN4SrniVh441BTLn5CpfyxA5Peh9w3xTvdoTm5wn P1xYUEG2Ymutk8R8qDudag9KUpl+0sCpFTk7u0yB9dLuXmdEoBzUCgL5Q2T2ioEZoD/8 992fKe7D2ncfnOcBpYUPw+eO4fQzVIONH7PydqolflGl6W1jAhGTZ7xR4gfS6h33o29y s8PWQwhcQRzahUf5OyW+mkFQDIzOy2YO71KafX3e0KhBQJaERa4Rf8G5jX7KLfDR1gAW PDcZl4KODURv2raCPhVR4auGX+OBOa+y/Qhx+d2UcQrdrw0PmiHQdNalqZZ5ySlVxvtO uDdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682505473; x=1685097473; 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=NNBRwTKoPfNm6mzC2ZqFXQ6r5NBvVjojYda1M3prEL8=; b=DnNkXtqLQrTiy8Vyyo+5GBf8y0nx6+g2EEjKiWajgfAVICM5EYR+C7UzolGWNd84al Wenj3mNPpGqeHWheIzCxV06rk8a/zIwYVn4/J9AGVPpOyVIqt6X/8uRWmlVuXOMexgsC ljxxn3UoAvrQFro/0vir4Z9ZXt0vN9PAYj9rmEi7HDV5aPWHDOnvqXaIwfRlXv4P2fAb MwP//hL5XfVjN409O6CwfK7sxx3kJk2EWAnP4Y63823C1aCju5AvkPbCf82J0j9htGaR HicPXLSnp9MdCnqec5JndZqIuYOyNV+JI1UtgtJbl2K1UgsvZIDQmfwlbBuFQN3rT0H/ w4mA== X-Gm-Message-State: AAQBX9fjAFSg2jQHR8PFTgAHa4AWIEP8eIT59e5AcT/WlOaiKZVEwnac 5CFm/tyjojKFC+5rGtB3AUCB1A== X-Google-Smtp-Source: AKy350a7cphy69wXGmqwOnc01HtTYtJPprqWQZ4OxJezPtOECYIz3XMFasDz36KjC5B5NtKP+cb4MA== X-Received: by 2002:a05:6a20:4323:b0:ef:bf77:f76f with SMTP id h35-20020a056a20432300b000efbf77f76fmr26933146pzk.4.1682505473467; Wed, 26 Apr 2023 03:37:53 -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 v4 08/48] e1000e: Always copy ethernet header Date: Wed, 26 Apr 2023 19:36:36 +0900 Message-Id: <20230426103716.26279-9-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230426103716.26279-1-akihiko.odaki@daynix.com> References: <20230426103716.26279-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::42c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42c.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: 1682505492044100003 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 | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index c2d864a504..14b94db59c 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]; + uint8_t 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,24 +1711,21 @@ e1000e_receive_internal(E1000ECore *core, const str= uct 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 /* Pad to minimum Ethernet frame length */ - if (size < sizeof(min_buf)) { - iov_to_buf(iov, iovcnt, iov_ofs, min_buf, size); - memset(&min_buf[size], 0, sizeof(min_buf) - size); + if (size < sizeof(buf)) { + iov_to_buf(iov, iovcnt, iov_ofs, buf, size); + memset(&buf[size], 0, sizeof(buf) - size); e1000x_inc_reg_if_not_full(core->mac, RUC); - min_iov.iov_base =3D filter_buf =3D min_buf; - min_iov.iov_len =3D size =3D sizeof(min_buf); + min_iov.iov_base =3D buf; + min_iov.iov_len =3D size =3D sizeof(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, 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(buf))); =20 - if (!e1000e_receive_filter(core, filter_buf, size)) { + if (!e1000e_receive_filter(core, buf, size)) { trace_e1000e_rx_flt_dropped(); return orig_size; } --=20 2.40.0