From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 0F4C7941D8C for ; Wed, 23 Oct 2024 17:00:08 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=5TtvqPRQuJiwDHCgjODCiUhVdNC5z6GNeork6HrqYSA=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240830; t=1729702808; v=1; x=1729962007; b=QGE1WZGkv3D2XOHHmnL3968tZtGQA1dJnNcUvuf8uGtESfEv2avZovQYD8t7g5+5DYpgTUZR Sob7UswhSyQ2quY+gIJYu9p+HrHOjJZB0B2AkUtfiMOFKut/Wcwu51zRMMMiCSNoDHagI3KOVnQ YlPTAAdgEPIRmb7TmxWShqWjAA5IDTuZO+YAzbqjuJwhnkDbdn9+wgFNA3PWvh1PHDLLZNvPFay aDp1cPXFd11trcTXBMP7frj9THL/EH29BrwEREKJeXgQIICd8YKHBxb4GSTT9dSj9lVsXZpSyRJ 4goD3BoyjfC49/aJ03b6Ihx8S/zPvzic864ni/XdBpWYA== X-Received: by 127.0.0.2 with SMTP id y2KyYY7687511xPAu81Bg7pu; Wed, 23 Oct 2024 10:00:07 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by mx.groups.io with SMTP id smtpd.web10.16868.1729060153561682878 for ; Tue, 15 Oct 2024 23:29:13 -0700 X-CSE-ConnectionGUID: RL/Ybsb0QOaLlLP+5ZiZSw== X-CSE-MsgGUID: UgR2ENWhR+yv4xkalDglVw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="28278906" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="28278906" X-Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2024 23:29:13 -0700 X-CSE-ConnectionGUID: PvTL7DaHSUCIvO5xnKXIHA== X-CSE-MsgGUID: SoMBNvZxSh+DBbPZmg893w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,207,1725346800"; d="scan'208";a="108869948" X-Received: from shwdeopenlab108.ccr.corp.intel.com ([10.239.55.64]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2024 23:29:11 -0700 From: Foster Nong To: devel@edk2.groups.io Cc: Foster Nong , Michael D Kinney , Liming Gao , Ray Ni Subject: [edk2-devel] [PATCH V1 1/2] MdeModulePkg: Check legal BarIndex/NumberofBars Date: Wed, 16 Oct 2024 14:28:41 +0800 Message-Id: <20241016062842.2128-1-foster.nong@intel.com> MIME-Version: 1.0 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 Resent-Date: Wed, 23 Oct 2024 10:00:06 -0700 Resent-From: foster.nong@intel.com Reply-To: devel@edk2.groups.io,foster.nong@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: SsMbbS44x5IbHzLSuJvfaV6Px7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240830 header.b=QGE1WZGk; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4868 In current PCIE Resizable BAR feature, add below check: 1. Check Register Number of Resizable BARs is legal. 2. Check Register Register BAR Index is legal. Signed-off-by: Foster Nong Cc: Michael D Kinney Cc: Liming Gao Cc: Ray Ni --- MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c | 41 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c b/MdeModulePkg/Bus/Pci= /PciBusDxe/PciLib.c index 84fc0161a1..f15dd6468d 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c @@ -1800,7 +1800,6 @@ PciProgramResizableBar ( UINT32 Index;=0D UINT32 Offset;=0D INTN Bit;=0D - UINTN ResizableBarNumbe= r;=0D EFI_STATUS Status;=0D PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR_ENTRY Entries[PCI_MAX_B= AR];=0D =0D @@ -1812,19 +1811,39 @@ PciProgramResizableBar ( PciIoDevice->ResizableBarOffset,=0D PciIoDevice->ResizableBarNumber=0D ));=0D + if (PciIoDevice->ResizableBarNumber > PCI_MAX_BAR || PciIoDevice->Resiza= bleBarNumber =3D=3D 0) {=0D + DEBUG ((DEBUG_ERROR, "ERROR: Resizable BAR register ResizableBarNumber= =3D0x%X is illegal\n", PciIoDevice->ResizableBarNumber));=0D + return EFI_DEVICE_ERROR;=0D + }=0D =0D - ResizableBarNumber =3D MIN (PciIoDevice->ResizableBarNumber, PCI_MAX_BAR= );=0D - PciIo =3D &PciIoDevice->PciIo;=0D - Status =3D PciIo->Pci.Read (=0D - PciIo,=0D - EfiPciIoWidthUint8,=0D - PciIoDevice->ResizableBarOffset + size= of (PCI_EXPRESS_EXTENDED_CAPABILITIES_HEADER),=0D - sizeof (PCI_EXPRESS_EXTENDED_CAPABILIT= IES_RESIZABLE_BAR_ENTRY) * ResizableBarNumber,=0D - (VOID *)(&Entries)=0D - );=0D + PciIo =3D &PciIoDevice->PciIo;=0D + Status =3D PciIo->Pci.Read (=0D + PciIo,=0D + EfiPciIoWidthUint8,=0D + PciIoDevice->ResizableBarOffset + sizeof (PCI_EXPR= ESS_EXTENDED_CAPABILITIES_HEADER),=0D + sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABL= E_BAR_ENTRY) * PciIoDevice->ResizableBarNumber,=0D + (VOID *)(&Entries)=0D + );=0D ASSERT_EFI_ERROR (Status);=0D =0D - for (Index =3D 0; Index < ResizableBarNumber; Index++) {=0D + for (Index =3D 0; Index < PciIoDevice->ResizableBarNumber; Index++) {=0D + //=0D + // BAR index: encoded value=0D + // 0 BAR located at offset 10h=0D + // 1 BAR located at offset 14h=0D + // 2 BAR located at offset 18h=0D + // 3 BAR located at offset 1ch=0D + // 4 BAR located at offset 20h=0D + // 5 BAR located at offset 24h=0D + // Others Reserved.=0D + // Do not configure anything if some BAR info is wrong.=0D + //=0D + if (Entries[Index].ResizableBarControl.Bits.BarIndex >=3D PCI_MAX_BAR = ) {=0D + DEBUG ((DEBUG_ERROR, "ERROR: Resizable BAR Entry[%x].BarIndex=3D%x i= s illegal\n", Index, Entries[Index].ResizableBarControl.Bits.BarIndex));=0D + return EFI_DEVICE_ERROR;=0D + }=0D + }=0D + for (Index =3D 0; Index < PciIoDevice->ResizableBarNumber; Index++) {=0D //=0D // When the bit of Capabilities Set, indicates that the Function suppo= rts=0D // operating with the BAR sized to (2^Bit) MB.=0D --=20 2.37.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#120664): https://edk2.groups.io/g/devel/message/120664 Mute This Topic: https://groups.io/mt/109174499/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-