From patchwork Wed May 17 09:10:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 682912 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp251174wrt; Wed, 17 May 2023 02:12:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6bhQdO4yewsgoUgJvDdrxr6tI9KOVs7VJwWYBOgarnbyJpqXpmCQZAxVTqzt4ppdZtYx1T X-Received: by 2002:a05:6214:c6a:b0:5b3:e172:b63e with SMTP id t10-20020a0562140c6a00b005b3e172b63emr52707265qvj.22.1684314755031; Wed, 17 May 2023 02:12:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684314755; cv=none; d=google.com; s=arc-20160816; b=SxFUzdUZhOkdPqzEus0QF7QqiVtkTV275djLjj6Jb6CMtbA4rhK3J8YlRd2MYscrZs fuv1v5Wx0djr+uKGcd9RsqoTXt69PIb3jOMg7Xqz0BmOwz5BuA0/b0fNDK8fT67WpW5H B/WbHcXVJvqaSO6lmRzxElKUuFM23M/W/TBpEPV/BkYEOpZz9MaVu8AZDYz6wvKMetee KwmK5ZKpjL67LTbz8/X8iPiL5+DwRikE/nzsHN9ZrivMW7UOqS/wcqhL7UMshkh0DWaU 11hCFp6aAx26DUcBuRRMJqY5YoKEu19lwZeqVRMA+RNb+/fWcMumN15bQnKU9aIU99Qv EWRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=Qvem2rHcMg9zrJFA4/Y5bQTC1esOyIAEA7wGjjPNjH8=; b=sqwisbChvyNCHGeOT+KgtRTOCF7ii8okLJ6/FUA/KgbvgHynwbkqqN9pOgCKWX9T+s V1wYe9awcM6u/HW0N4/KOnL6JabOkJbhFYkBHnSiGlbmc+x3cTe4zqQYMxauZ7Qo8uGp 4WeS2jmle9MtG+RziEMonMLS/n/SlpHqwqxAjAhouP6u6mweLJOVWMeW23nnnPHUB3Ig UF2bF/DWUY823JRgxEO49/jypSivthXNokzlpLMcL6VvEoaoqhlibxvZZ9oduBM+jHVM 5kxWfbqstIQ0FsTHkB+0cRIm/7cJrto53JIYnGzOdvdBfqmbr1QD3U0kep3acd5Q4/a5 tnxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a2-20020a056214062200b0061b5a6032b2si12743245qvx.571.2023.05.17.02.12.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 May 2023 02:12:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzDBO-0000Bh-9e; Wed, 17 May 2023 05:10:54 -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 1pzDBM-00008H-9H; Wed, 17 May 2023 05:10:52 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzDBK-0006NX-BK; Wed, 17 May 2023 05:10:52 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 0B206682D; Wed, 17 May 2023 12:10:44 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 744AA5EF9; Wed, 17 May 2023 12:10:43 +0300 (MSK) Received: (nullmailer pid 3626687 invoked by uid 1000); Wed, 17 May 2023 09:10:42 -0000 From: Michael Tokarev To: qemu-stable@nongnu.org Cc: qemu-devel@nongnu.org, Peter Maydell , Thomas Huth Subject: [PATCH v7.2.3 07/30] hw/net/msf2-emac: Don't modify descriptor in-place in emac_store_desc() Date: Wed, 17 May 2023 12:10:19 +0300 Message-Id: <20230517091042.3626593-7-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Peter Maydell The msf2-emac ethernet controller has functions emac_load_desc() and emac_store_desc() which read and write the in-memory descriptor blocks and handle conversion between guest and host endianness. As currently written, emac_store_desc() does the endianness conversion in-place; this means that it effectively consumes the input EmacDesc struct, because on a big-endian host the fields will be overwritten with the little-endian versions of their values. Unfortunately, in all the callsites the code continues to access fields in the EmacDesc struct after it has called emac_store_desc() -- specifically, it looks at the d.next field. The effect of this is that on a big-endian host networking doesn't work because the address of the next descriptor is corrupted. We could fix this by making the callsite avoid using the struct; but it's more robust to have emac_store_desc() leave its input alone. (emac_load_desc() also does an in-place conversion, but here this is fine, because the function is supposed to be initializing the struct.) Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Thomas Huth Message-id: 20230424151919.1333299-1-peter.maydell@linaro.org (cherry picked from commit d565f58b38424e9a390a7ea33ff7477bab693fda) Signed-off-by: Michael Tokarev --- hw/net/msf2-emac.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/hw/net/msf2-emac.c b/hw/net/msf2-emac.c index 7ccd3e5142..db3a04deb1 100644 --- a/hw/net/msf2-emac.c +++ b/hw/net/msf2-emac.c @@ -118,14 +118,18 @@ static void emac_load_desc(MSF2EmacState *s, EmacDesc *d, hwaddr desc) d->next = le32_to_cpu(d->next); } -static void emac_store_desc(MSF2EmacState *s, EmacDesc *d, hwaddr desc) +static void emac_store_desc(MSF2EmacState *s, const EmacDesc *d, hwaddr desc) { - /* Convert from host endianness into LE. */ - d->pktaddr = cpu_to_le32(d->pktaddr); - d->pktsize = cpu_to_le32(d->pktsize); - d->next = cpu_to_le32(d->next); - - address_space_write(&s->dma_as, desc, MEMTXATTRS_UNSPECIFIED, d, sizeof *d); + EmacDesc outd; + /* + * Convert from host endianness into LE. We use a local struct because + * calling code may still want to look at the fields afterwards. + */ + outd.pktaddr = cpu_to_le32(d->pktaddr); + outd.pktsize = cpu_to_le32(d->pktsize); + outd.next = cpu_to_le32(d->next); + + address_space_write(&s->dma_as, desc, MEMTXATTRS_UNSPECIFIED, &outd, sizeof outd); } static void msf2_dma_tx(MSF2EmacState *s)