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 C116E7803DE for ; Wed, 23 Oct 2024 17:00:13 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=SdVsyaYO3g3Yp4qeDaGeRQiqBog+AMOu96/8p4czJ9g=; 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=1729702813; v=1; x=1729962012; b=NF1RSEJH33l/C8yt4wDyhyzA52B/RuUhp5lQGJz/8tleIb2PjGqeRotJUs9rnzP3+vpPfmzB aQvTmiTpCWa4m2stIdVb8hlJkZ/GqBRyLyYcmtDtdUDGat6hwIIGhvFiiaosdJmUZPw3FJNqPPI 02wb4OrUPEs6QPsKZQQb14Rypa8481w0cblGZhc51rdNgEUh/Lf25J4DFkInd7cDW5XPIc/RfSp xCEgmotUpPbtSA5AEmHy/Av7Oi9nTZ71dAU8ZjG9tVqsWmKaOvoVhUXswQWMaK9MFOwPiQ1ZjTC PPObGnJtwUUg1e3iZbxzo5CZv1Iq/5aOalDsPvHuW8iWg== X-Received: by 127.0.0.2 with SMTP id CN1XYY7687511xETTkSC7fHs; Wed, 23 Oct 2024 10:00:12 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by mx.groups.io with SMTP id smtpd.web10.12510.1729212931247833055 for ; Thu, 17 Oct 2024 17:55:31 -0700 X-CSE-ConnectionGUID: Ata5ztepTMCpvdMDE0EOkw== X-CSE-MsgGUID: Jquc3uySQym+SLmqVcxVKQ== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="39364008" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="39364008" X-Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 17:55:31 -0700 X-CSE-ConnectionGUID: T9lwfiP2Ry+7zHkHnWCutQ== X-CSE-MsgGUID: UhAcYUGSQ/2V60sIEKu12g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="82676854" X-Received: from shwdeopenlab108.ccr.corp.intel.com ([10.239.55.64]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 17:55:29 -0700 From: Foster Nong To: devel@edk2.groups.io Cc: Foster Nong , Michael D Kinney , Liming Gao , Ray Ni Subject: [edk2-devel] [PATCH v2 1/2] MdeModulePkg: Check legal BarIndex/NumberofBars Date: Fri, 18 Oct 2024 08:55:08 +0800 Message-Id: <20241018005509.2913-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: Rm0dZv0SwxvuBB7R3bcYz6k7x7686176AA= 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=NF1RSEJH; 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 | 43 ++++++++++++++++++------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c b/MdeModulePkg/Bus/Pci= /PciBusDxe/PciLib.c index 84fc0161a1..dc5fd27665 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 @@ -1813,18 +1812,40 @@ PciProgramResizableBar ( PciIoDevice->ResizableBarNumber=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 + if ((PciIoDevice->ResizableBarNumber > PCI_MAX_BAR) || (PciIoDevice->Res= izableBarNumber =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 + 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 +=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 (#120666): https://edk2.groups.io/g/devel/message/120666 Mute This Topic: https://groups.io/mt/109174501/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-