From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7634DC2D0E4 for ; Mon, 23 Nov 2020 21:41:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 757112071E for ; Mon, 23 Nov 2020 21:41:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MN0fvZ8n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 757112071E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1khJam-0008WJ-6Q for qemu-devel@archiver.kernel.org; Mon, 23 Nov 2020 16:41:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1khJPs-0001C3-77 for qemu-devel@nongnu.org; Mon, 23 Nov 2020 16:30:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40360) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1khJPp-0008Rk-Ek for qemu-devel@nongnu.org; Mon, 23 Nov 2020 16:30:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606167028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pqEzxKrz7n+/jOv0VPcZZkU+AXGf1pIYnJ2aS97fEzE=; b=MN0fvZ8nMxTDE23iXky5zpdRPcNVymJmitfDgVJAjzy8FGVTPpiKZxlPpiXzXphWHA9Ckk o8eqvrEM3OJ+66bKVtQ1nVfVP7lP8wisD8+mUEcnY4avH53bi3HI3AUIkqia2u3uBN6UaY 2CdrMiwuyh4IBYOJGaUp2QHQZJ0cYAc= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-197-7Hlw9JqMN-m28rXhl6T_eQ-1; Mon, 23 Nov 2020 16:30:25 -0500 X-MC-Unique: 7Hlw9JqMN-m28rXhl6T_eQ-1 Received: by mail-ed1-f71.google.com with SMTP id y11so7092227edv.6 for ; Mon, 23 Nov 2020 13:30:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=pqEzxKrz7n+/jOv0VPcZZkU+AXGf1pIYnJ2aS97fEzE=; b=e1x1pO61HB9BX7dm17gOfLQXLkmqlpvD05bFOAT5hQczB7DjbXHAoYrjBvzxlaTvg3 po3otHIi5WGxioVUuVfRT3hCkidR6/ecMjGd5CFPCG9dsjw/nDtAtI1fxH49EdhL9p1y 1oVcqsgR/4TJnFJcpsiTsUKeb266XPFk3jDIEW17Yub6heKXc5CyH6qeIJEueK0JRf3J sTKcSy5dU+hNx8/o6nJ0RgTaMNrtOMkBVOVNETOOMk2TvNt22FG51WLhuawaDaSe2wyX IIL3O/tahA7yjXvi0TKWHFc6AYBSonm9rjWmdPUnU3E4iYTmSLWboDwaq6M/RbrcIx1x IWOA== X-Gm-Message-State: AOAM531xT+/ex8YtyGM/Tuq7E2l8bSQNGsR03xsm0V5/j69JzFCGb+qh PsJCtGKEwni5fgB6tmP0vVyY7v2wBtXF4aL5g9+AOEo0sktC2dpozH38O+uD6BPStOE6uvnJHMw BmTYjmgUiK4gYQZqLujFUZqFkG80vaOY= X-Received: by 2002:aa7:dc05:: with SMTP id b5mr1172812edu.47.1606167023414; Mon, 23 Nov 2020 13:30:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6JlUbawyvKISwU0kOXLBGIEeSJmY4ncUkOLXBWloKCKVB2xiyfxQYK3JMALHwaSS4vftJkuxDyv1bFNgIbpE= X-Received: by 2002:aa7:dc05:: with SMTP id b5mr1172790edu.47.1606167023138; Mon, 23 Nov 2020 13:30:23 -0800 (PST) MIME-Version: 1.0 References: <20201113103113.223239-1-mcascell@redhat.com> In-Reply-To: From: Mauro Matteo Cascella Date: Mon, 23 Nov 2020 22:30:12 +0100 Message-ID: Subject: Re: [PATCH v2] net/e1000e_core: adjust count if RDH exceeds RDT in e1000e_ring_advance() To: Jason Wang Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mcascell@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=216.205.24.124; envelope-from=mcascell@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gaoning.pgn@antgroup.com, 330cjfdn@gmail.com, Dmitry Fleytman , Laszlo Ersek , QEMU Developers Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Thu, Nov 19, 2020 at 6:57 AM Jason Wang wrote: > > > On 2020/11/18 =E4=B8=8B=E5=8D=884:53, Mauro Matteo Cascella wrote: > > On Wed, Nov 18, 2020 at 4:56 AM Jason Wang wrote: > >> > >> On 2020/11/13 =E4=B8=8B=E5=8D=886:31, Mauro Matteo Cascella wrote: > >>> The e1000e_write_packet_to_guest() function iterates over a set of > >>> receive descriptors by advancing rx descriptor head register (RDH) fr= om > >>> its initial value to rx descriptor tail register (RDT). The check in > >>> e1000e_ring_empty() is responsible for detecting whether RDH has reac= hed > >>> RDT, terminating the loop if that's the case. Additional checks have > >>> been added in the past to deal with bogus values submitted by the gue= st > >>> to prevent possible infinite loop. This is done by "wrapping around" = RDH > >>> at some point and detecting whether it assumes the original value dur= ing > >>> the loop. > >>> > >>> However, when e1000e is configured to use the packet split feature, R= DH is > >>> incremented by two instead of one, as the packet split descriptors ar= e > >>> 32 bytes while regular descriptors are 16 bytes. A malicious or buggy > >>> guest may set RDT to an odd value and transmit only null RX descripto= rs. > >>> This corner case would prevent RDH from ever matching RDT, leading to= an > >>> infinite loop. This patch adds a check in e1000e_ring_advance() to ma= ke sure > >>> RDH does not exceed RDT in a single incremental step, adjusting the c= ount > >>> value accordingly. > >> > >> Can this patch solve this issue in another way? > >> > >> https://patchew.org/QEMU/20201111130636.2208620-1-ppandit@redhat.com/ > >> > >> Thanks > >> > > Yes, it does work nicely. Still, I think this patch is useful to avoid > > possible inconsistent state in e1000e_ring_advance() when count > 1. > > > So if RDT is odd, it looks to me the following codes in > e1000e_write_packet_to_guest() needs to be fixed as well. > > > base =3D e1000e_ring_head_descr(core, rxi); > > pci_dma_read(d, base, &desc, core->rx_desc_len); > > Otherwise e1000e may try to read out of descriptor ring. Sorry, I'm not sure I understand what you mean. Isn't the base address computed from RDH? How can e1000e read out of the descriptor ring if RDT is odd? > > Thanks On Thu, Nov 19, 2020 at 6:57 AM Jason Wang wrote: > > > On 2020/11/18 =E4=B8=8B=E5=8D=884:53, Mauro Matteo Cascella wrote: > > On Wed, Nov 18, 2020 at 4:56 AM Jason Wang wrote: > >> > >> On 2020/11/13 =E4=B8=8B=E5=8D=886:31, Mauro Matteo Cascella wrote: > >>> The e1000e_write_packet_to_guest() function iterates over a set of > >>> receive descriptors by advancing rx descriptor head register (RDH) fr= om > >>> its initial value to rx descriptor tail register (RDT). The check in > >>> e1000e_ring_empty() is responsible for detecting whether RDH has reac= hed > >>> RDT, terminating the loop if that's the case. Additional checks have > >>> been added in the past to deal with bogus values submitted by the gue= st > >>> to prevent possible infinite loop. This is done by "wrapping around" = RDH > >>> at some point and detecting whether it assumes the original value dur= ing > >>> the loop. > >>> > >>> However, when e1000e is configured to use the packet split feature, R= DH is > >>> incremented by two instead of one, as the packet split descriptors ar= e > >>> 32 bytes while regular descriptors are 16 bytes. A malicious or buggy > >>> guest may set RDT to an odd value and transmit only null RX descripto= rs. > >>> This corner case would prevent RDH from ever matching RDT, leading to= an > >>> infinite loop. This patch adds a check in e1000e_ring_advance() to ma= ke sure > >>> RDH does not exceed RDT in a single incremental step, adjusting the c= ount > >>> value accordingly. > >> > >> Can this patch solve this issue in another way? > >> > >> https://patchew.org/QEMU/20201111130636.2208620-1-ppandit@redhat.com/ > >> > >> Thanks > >> > > Yes, it does work nicely. Still, I think this patch is useful to avoid > > possible inconsistent state in e1000e_ring_advance() when count > 1. > > > So if RDT is odd, it looks to me the following codes in > e1000e_write_packet_to_guest() needs to be fixed as well. > > > base =3D e1000e_ring_head_descr(core, rxi); > > pci_dma_read(d, base, &desc, core->rx_desc_len); > > Otherwise e1000e may try to read out of descriptor ring. > > Thanks > > > > > > Thank you, > --=20 Mauro Matteo Cascella Red Hat Product Security PGP-Key ID: BB3410B0