From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 43973940F81 for ; Mon, 31 Jul 2023 03:25:14 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=fRsYgZNCWrDo2IH8PVQgDgyuHwprpqgHF0V5P1gc9/U=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:From:To:Cc:Subject:Date:Message-Id:MIME-Version:X-CM-TRANSID:X-Coremail-Antispam:X-Originating-IP:X-CM-SenderInfo:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:X-Gm-Message-State:Content-Transfer-Encoding; s=20140610; t=1690773912; v=1; b=BPPNjBQpgZMwtfLKVOrKUlyHM07eQlSzu4ix+MnChch8gw1pjOtzUfXvozpoqqD5Nat8yfVy UNgeA2rqhVUAOP4NRYCtAZjAaItgqPzUujOOzjQao5OD+3PNUc5EMX7lnpCPryYnsrkcee1gG7h iYfMjP9hg4/sKfAPhA4OZO0w= X-Received: by 127.0.0.2 with SMTP id RD8JYY7687511xieI7Eh7HhJ; Sun, 30 Jul 2023 20:25:12 -0700 X-Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.215]) by mx.groups.io with SMTP id smtpd.web11.166.1690773911642551098 for ; Sun, 30 Jul 2023 20:25:12 -0700 X-Received: from localhost.localdomain (unknown [219.141.235.82]) by zwqz-smtp-mta-g1-2 (Coremail) with SMTP id _____wBnfTx2KcdkAHDqBg--.47213S2; Mon, 31 Jul 2023 11:24:39 +0800 (CST) From: "wangy" To: devel@edk2.groups.io Cc: pedro.falcato@gmail.com, Yang Wang , Leif Lindholm , Ard Biesheuvel , Ran Wang Subject: [edk2-devel] [edk2-platforms][PATCH V3] Silicon/Synopsys/DesignWare: DwEmacSnpDxe: Fix bug in EmacGetDmaStatus Date: Mon, 31 Jul 2023 11:24:36 +0800 Message-Id: <3f5a13860d7c3a15d88cbf13c9e31301ec884f9c.1690772738.git.wangyzhaoz@163.com> MIME-Version: 1.0 X-CM-TRANSID: _____wBnfTx2KcdkAHDqBg--.47213S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxXr17Xr13tw1fWryrKryfJFb_yoW5GF4kpa 9IkrZrCrsxJFyrAF1YyF4qqF45GFZ3KrWqk347J39YqFnxJrn3uF1aqFW7J3WDGFy0yry3 WayYq34xGr95tw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pEasUJUUUUU= X-Originating-IP: [219.141.235.82] X-CM-SenderInfo: 5zdqw5p2kd06i6rwjhhfrp/1tbiJRi9JWNfs8SWjAAAs0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,wangyzhaoz@163.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: LEgGQ0n472C0QiW8nmkQWNesx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=BPPNjBQp; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=163.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: Yang Wang The EFI spec (see UEFI 2.10, 24.1.12) requires EFI_SIMPLE_NETWORK.GetStatus() to handle NULL InterruptStatus pointers by not reading nor clearing the interrupt status from the device. However, EmacGetDmaStatus (part of the DwEmacSnpDxe GetStatus() implementation) did not correctly handle NULL IrqStat, despite already being tagged as an OPTIONAL argument. This made calling GetStatus() with a NULL pointer (for example, the call in MnpRecycleTxBuf) either corrupt memory or straight-up crash. Make it EFI spec compliant, by adding proper NULL pointer checks around RI_SET_MSK and TI_SET_MSK retrieval/clearing. Cc: Leif Lindholm Cc: Ard Biesheuvel Signed-off-by: Yang Wang Acked-by: Pedro Falcato Reviewed-by: Ran Wang --- .../Drivers/DwEmacSnpDxe/EmacDxeUtil.c | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Silicon/Synopsys/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.c= b/Silicon/Synopsys/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.c index 3b982ce984..26d3ff6138 100755 --- a/Silicon/Synopsys/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.c +++ b/Silicon/Synopsys/DesignWare/Drivers/DwEmacSnpDxe/EmacDxeUtil.c @@ -500,24 +500,30 @@ EmacGetDmaStatus ( UINT32 ErrorBit;=0D UINT32 Mask =3D 0;=0D =0D + if (IrqStat !=3D NULL) {=0D + *IrqStat =3D 0;=0D + }=0D +=0D DmaStatus =3D MmioRead32 (MacBaseAddress +=0D DW_EMAC_DMAGRP_STATUS_OFST);=0D if (DmaStatus & DW_EMAC_DMAGRP_STATUS_NIS_SET_MSK) {=0D Mask |=3D DW_EMAC_DMAGRP_STATUS_NIS_SET_MSK;=0D // Rx interrupt=0D if (DmaStatus & DW_EMAC_DMAGRP_STATUS_RI_SET_MSK) {=0D - *IrqStat |=3D EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;=0D - Mask |=3D DW_EMAC_DMAGRP_STATUS_RI_SET_MSK;=0D - } else {=0D - *IrqStat &=3D ~EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;=0D + if (IrqStat !=3D NULL) {=0D + *IrqStat |=3D EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;=0D + Mask |=3D DW_EMAC_DMAGRP_STATUS_RI_SET_MSK;=0D + }=0D }=0D +=0D // Tx interrupt=0D if (DmaStatus & DW_EMAC_DMAGRP_STATUS_TI_SET_MSK) {=0D - *IrqStat |=3D EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;=0D - Mask |=3D DW_EMAC_DMAGRP_STATUS_TI_SET_MSK;=0D - } else {=0D - *IrqStat &=3D ~EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;=0D + if (IrqStat !=3D NULL) {=0D + *IrqStat |=3D EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;=0D + Mask |=3D DW_EMAC_DMAGRP_STATUS_TI_SET_MSK;=0D + }=0D }=0D +=0D // Tx Buffer=0D if (DmaStatus & DW_EMAC_DMAGRP_STATUS_TU_SET_MSK){=0D Mask |=3D DW_EMAC_DMAGRP_STATUS_TU_SET_MSK;=0D --=20 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107391): https://edk2.groups.io/g/devel/message/107391 Mute This Topic: https://groups.io/mt/100455239/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-