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 483C4D80689 for ; Wed, 23 Oct 2024 17:00:09 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=dMQioGOpP3Wt3VLNXc3TipImVS59F1suRq9o3I5y/c4=; c=relaxed/simple; d=groups.io; h=From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language: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-Language:Content-Type:Content-Transfer-Encoding; s=20240830; t=1729702809; v=1; x=1729962007; b=fIxBtioDSZfTQxBO0ay1yNt8Cctz6TUnKwoYk3+7byFPqUrBLQbZlH8Y6GnMx9zXbQsEnR7E LEYIwaFX4TNdrWy7uUycVz1t4spcAsDnk3kXWgkt+lNBUmt1F0uCa6fx+xNa/Y7YTFNiwgCLcgA bdf7gA/5hu0gSgXpGXWTSYB9wxEUqBwE6VNKfy2s6G1aTL2L4zLVdFVXCRw5WkJkWGDMad2Usrj vVFnOFInTMqs3DRiJCtkQHy7IlgXwrD0AGZRvw6DWx5lRTmRcSP5DgV3l1qPS9hu6uCT08tYZQd 9dLktfWrL/af84q5VIsxFsn5x7ITyKiNiNiDDX+wJ4vig== X-Received: by 127.0.0.2 with SMTP id UW4KYY7687511xvR2UJRZX6U; Wed, 23 Oct 2024 10:00:07 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by mx.groups.io with SMTP id smtpd.web11.12782.1729213029099959074 for ; Thu, 17 Oct 2024 17:57:09 -0700 X-CSE-ConnectionGUID: a5Y1s7vyQjytxAGWXy7Y6g== X-CSE-MsgGUID: bnJlTbctQfyddDGkPnUZ7A== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="32657834" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="32657834" X-Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 17:57:09 -0700 X-CSE-ConnectionGUID: ayG/417HSUuIjHneUhY0HQ== X-CSE-MsgGUID: dFc/743GRiuRt5Kk3lI7Yw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="79147242" X-Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by orviesa007.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 17 Oct 2024 17:57:05 -0700 X-Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 17 Oct 2024 17:57:04 -0700 X-Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 17 Oct 2024 17:57:03 -0700 X-Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Thu, 17 Oct 2024 17:57:03 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.46) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 17 Oct 2024 17:57:03 -0700 X-Received: from DS7PR11MB6199.namprd11.prod.outlook.com (2603:10b6:8:99::9) by LV8PR11MB8699.namprd11.prod.outlook.com (2603:10b6:408:1ff::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.26; Fri, 18 Oct 2024 00:56:59 +0000 X-Received: from DS7PR11MB6199.namprd11.prod.outlook.com ([fe80::7f98:7924:e2d7:a682]) by DS7PR11MB6199.namprd11.prod.outlook.com ([fe80::7f98:7924:e2d7:a682%4]) with mapi id 15.20.8069.016; Fri, 18 Oct 2024 00:56:59 +0000 From: "Nong, Foster" To: "devel@edk2.groups.io" CC: "Kinney, Michael D" , Liming Gao , "Ni, Ray" Subject: Re: [edk2-devel] [PATCH v2 1/2] MdeModulePkg: Check legal BarIndex/NumberofBars Thread-Topic: [PATCH v2 1/2] MdeModulePkg: Check legal BarIndex/NumberofBars Thread-Index: AQHbIPh4pYrqJkzKEUGiinJ1x48k2rKLr00Q Date: Fri, 18 Oct 2024 00:56:59 +0000 Message-ID: References: <20241018005509.2913-1-foster.nong@intel.com> In-Reply-To: <20241018005509.2913-1-foster.nong@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DS7PR11MB6199:EE_|LV8PR11MB8699:EE_ x-ms-office365-filtering-correlation-id: 720a3cf2-993b-4e8f-2d6d-08dcef0fc597 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: =?us-ascii?Q?os8T24gHHhrpbF75SMUM8YY/80tJOvyi3ePyUxSvONIdDVDUH/cBWOLCEC8i?= =?us-ascii?Q?O3Qt9UuS6NgO0jirtn2YZ0LMLC3fXn4xLibHz4wspJQANAJ+vZcvwlWZKtSk?= =?us-ascii?Q?nvyy0IDAWOwaQzLD5R6g9sIPeHwdD0OrQa4BF4EQMKPQGbb3/hafd1ugIbIY?= =?us-ascii?Q?Zuz6MQ7TUkgNIU3LPaVwCEzL+Omkd3dCVU0ubuyB402y2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UTFcncKRssdRbQU+dupDU+xyygGjzL?= =?us-ascii?Q?A4nQ9YS7n8d3WDZvI3lJgpC/jADVH3ojmE+nvb05Os6VX5U3zzAlKaHXKKl1?= =?us-ascii?Q?Xi92nRrdImR9rsTBp+APdJ8T2J07JT4qQw2RsUJo9mqfVuriY6CRT7b7V2p1?= =?us-ascii?Q?bneeGBtm0goI/tp92JyJibOnrt7wUNxBZp+GE00t6GardqDmVmJqOVZZewJG?= =?us-ascii?Q?0Rylo/gvUmuFw5pwE4Lc9sk2RPUL59XLIHfoLC3dFLkeKQ=3D=3D?= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?l/1yHOIsuUt5w49T7cSU5B0aMqk60c2koIcVM9opXtOETh+elWsqJO4NyDs8?= =?us-ascii?Q?bdZ9tlQiLbrz6exnYx/rUS1YBAOzDZLlG0JSGRNP1n199TI3WhSkhBxi5P/x?= =?us-ascii?Q?ZShAXVVENItQHNCzngOz4A2VzTPQeld14BMIpv/ZtRD4v2HRIaHmjIAeXAEw?= =?us-ascii?Q?LXQ1D7DXz0Bg/zTHm4M7FpsDOjAHISSCCiRryrrdLDfggJAw/m5xtj6Y/URS?= =?us-ascii?Q?Y3huK6r7BUFD8sSlMTSRACu1+0kKU+J3SzwizJKyI9nisjRMt9D0xrN+ELko?= =?us-ascii?Q?A6EKlgl2tJf82OZeYRo5uVNeJDK/5rap4tApBevaDV2e+ebKie/rIeOSoab/?= =?us-ascii?Q?4snCNm6IRHBdzS/Nfilc9xBHHVdr6zTjggpW8BZHiEBkpnRDduI2wXvcNpvC?= =?us-ascii?Q?znfrriHkMCzbmNo4HeJebz7KCwunlbGWFor7etCdvisZo+vG+bYRLKtsnacQ?= =?us-ascii?Q?GYSTK8qkEb7yv6JTAzkg6S7GJ+EXX9tOmX+rCJsg5bTp9EgP3Opro26yEnwY?= =?us-ascii?Q?tYjlNJf9DUNWP17gaJ1GZL0hOKUrNsKqMsi0PfpTTd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cQ6dK4nuJczgc3l4yIaz/L+rbjwlYjDjlC5wHu1XBaxjA+2JGbVo/TYi259?= =?us-ascii?Q?YdxDL4gfKjuupOD+H3ncCQTgVqyCBxt92QCc3VJ5Mi6S7+N1LgsHETTtpJYL?= =?us-ascii?Q?XZFCR2L1418G0V+vYtV23RbscFF6iEMTbTc5Hd0G?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DS7PR11MB6199.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 720a3cf2-993b-4e8f-2d6d-08dcef0fc597 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Oct 2024 00:56:59.8092 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 8b06ng984JFcu4+Y0kEgr0qPqJaeXcIljpXMTDwjfDqBe11ngcYMgkz/J5Xs96LGnIKPoFwNBJQ5AGRV30GP8A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR11MB8699 X-OriginatorOrg: intel.com 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:07 -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: w0eBfXKGWcCYlqC2mbgF3El6x7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" 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=fIxBtioD; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none) V2 is fix the coding style issue. Below is PR. https://github.com/tianocore/edk2/pull/6342 -----Original Message----- From: Nong, Foster =20 Sent: Friday, October 18, 2024 8:55 AM To: devel@edk2.groups.io Cc: Nong, Foster ; Kinney, Michael D ; Liming Gao ; Ni, Ray Subject: [PATCH v2 1/2] MdeModulePkg: Check legal BarIndex/NumberofBars 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; UINT32 Offset; INTN Bit; - UINTN ResizableBarNumbe= r; EFI_STATUS Status; PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR_ENTRY Entries[PCI_MAX_B= AR]; =20 @@ -1813,18 +1812,40 @@ PciProgramResizableBar ( PciIoDevice->ResizableBarNumber )); =20 - ResizableBarNumber =3D MIN (PciIoDevice->ResizableBarNumber, PCI_MAX_BAR= ); - PciIo =3D &PciIoDevice->PciIo; - Status =3D PciIo->Pci.Read ( - PciIo, - EfiPciIoWidthUint8, - PciIoDevice->ResizableBarOffset + size= of (PCI_EXPRESS_EXTENDED_CAPABILITIES_HEADER), - sizeof (PCI_EXPRESS_EXTENDED_CAPABILIT= IES_RESIZABLE_BAR_ENTRY) * ResizableBarNumber, - (VOID *)(&Entries) - ); + if ((PciIoDevice->ResizableBarNumber > PCI_MAX_BAR) || (PciIoDevice->Res= izableBarNumber =3D=3D 0)) { + DEBUG ((DEBUG_ERROR, "ERROR: Resizable BAR register ResizableBarNumber= =3D0x%X is illegal\n", PciIoDevice->ResizableBarNumber)); + return EFI_DEVICE_ERROR; + } + + PciIo =3D &PciIoDevice->PciIo; + Status =3D PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint8, + PciIoDevice->ResizableBarOffset + sizeof (PCI_EXPR= ESS_EXTENDED_CAPABILITIES_HEADER), + sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABL= E_BAR_ENTRY) * PciIoDevice->ResizableBarNumber, + (VOID *)(&Entries) + ); ASSERT_EFI_ERROR (Status); =20 - for (Index =3D 0; Index < ResizableBarNumber; Index++) { + for (Index =3D 0; Index < PciIoDevice->ResizableBarNumber; Index++) { + // + // BAR index: encoded value + // 0 BAR located at offset 10h + // 1 BAR located at offset 14h + // 2 BAR located at offset 18h + // 3 BAR located at offset 1ch + // 4 BAR located at offset 20h + // 5 BAR located at offset 24h + // Others Reserved. + // Do not configure anything if some BAR info is wrong. + // + if (Entries[Index].ResizableBarControl.Bits.BarIndex >=3D PCI_MAX_BAR = ) { + DEBUG ((DEBUG_ERROR, "ERROR: Resizable BAR Entry[%x].BarIndex=3D%x i= s illegal\n", Index, Entries[Index].ResizableBarControl.Bits.BarIndex)); + return EFI_DEVICE_ERROR; + } + } + + for (Index =3D 0; Index < PciIoDevice->ResizableBarNumber; Index++) { // // When the bit of Capabilities Set, indicates that the Function suppo= rts // operating with the BAR sized to (2^Bit) MB. --=20 2.37.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#120668): https://edk2.groups.io/g/devel/message/120668 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-