From nobody Mon May 6 10:07:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+72997+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+72997+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1616037810; cv=none; d=zohomail.com; s=zohoarc; b=XtynkjH9BYTC/kCrzD11D+zhvRyuBYugeJiejuDZKWv+IeBfFlXYF/KH84WmBAYL1l8nkqIpONDF/32ZeNNgDuxgZFLwXCeAeiH9TVTxkpNcjzMOzvx6nCCA8audZUCBhWQCYdw6IM4pwATHhlhfTcknVB2LwtYIYeJjxnJqV5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616037810; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=zsVvKtw6+JDzGKEfDc2PZtIIboXn9MZPHTmIvxCIYBA=; b=LH4hfwqLPH3Po73GBKOdDicC3ls9SGSC8HPH8wZtIABn9Is4AtOWxYObQVNB+ZqvRpPAYccu/fz21Y7WhwfjTKhZERN03ITESn1E7qCAsiBCHIZoPQZzli4axV0ot7lxkSBJERVl4VPDeBR9bml/DagNlbnOBNEPCEV50TwY+fs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+72997+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1616037810468743.3922143678572; Wed, 17 Mar 2021 20:23:30 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vwKAYY1788612xQVaemxxeyE; Wed, 17 Mar 2021 20:23:30 -0700 X-Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web11.4421.1616037808352637240 for ; Wed, 17 Mar 2021 20:23:29 -0700 IronPort-SDR: JZCs/BLWtW0U21BqDtyI9w1TK5rTVhrCwetNGi1bzlDY7mI3Ij7Jj7QQ3C9YdxIu31sRmlO7Vb vzWYxu9Zh9Tw== X-IronPort-AV: E=McAfee;i="6000,8403,9926"; a="187228306" X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="187228306" X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 20:23:24 -0700 IronPort-SDR: jB4I2/hEQmcZ/lNGlbGo/a3CljVcG7/swIr6JlMRfIXueEL5lWCZ0c8tYR32Wj4ExkyCKerSJ/ 1DDs/9FuH3cA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,257,1610438400"; d="scan'208";a="605973917" X-Received: from ikuox-tiger-lake-client-platform.itwn.intel.com ([10.5.215.23]) by fmsmga005.fm.intel.com with ESMTP; 17 Mar 2021 20:23:22 -0700 From: "IanX Kuo" To: devel@edk2.groups.io Cc: VincentX Ke Subject: [edk2-devel] [PATCH v4] ShellPkg/Pci: Add valid check for PCI extended config space parser Date: Thu, 18 Mar 2021 00:01:54 +0800 Message-Id: <4f96766095369b1062be5ddae93208ac16ca958b.1616036135.git.vincentx.ke@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ianx.kuo@intel.com X-Gm-Message-State: Gpb6RIUeJNIAPfZyjvaI5vLDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1616037810; bh=qyfwL33vPpk/XzzntId3MHUpkutYwzXJwgcb3Ka2F8M=; h=Cc:Date:From:Reply-To:Subject:To; b=ZWuyBl+Gs6wQwWwMClYvoocCZR1qnHXUQg+i0NwyQln+uVp54Y1hNOKXRJ0TmfhoNzq EU8pa4XITwmC/gYxp86x1M7cEF8yGdrNERV/GstDbaoccu34lS0K+S7wAIVHcaAtZfYvb cSJFzoAQudHQ6ZDEihOy1Gtv4Bs6S7AFXwY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: VincentX Ke Bugzilla: 3262 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3262) No need to print PCIe details while CapabilityId is 0xFFFF. Limit the NextCapabilityOffset to PCI/PCIe configuration space. Signed-off-by: VincentX Ke Reviewed-by: Zhichao Gao --- ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/L= ibrary/UefiShellDebug1CommandsLib/Pci.c index a2f04d8db5..1e5dc75e27 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c @@ -2038,12 +2038,14 @@ LocatePciCapability ( =20 @param[in] PciExpressCap PCI Express capability buffer. @param[in] ExtendedConfigSpace PCI Express extended configuration space. + @param[in] ExtendedConfigSize PCI Express extended configuration size. @param[in] ExtendedCapability PCI Express extended capability ID to exp= lain. **/ VOID PciExplainPciExpress ( IN PCI_CAPABILITY_PCIEXP *PciExpressCap, IN UINT8 *ExtendedConfigSpace, + IN UINTN ExtendedConfigSize, IN CONST UINT16 ExtendedCapability ); =20 @@ -2921,6 +2923,7 @@ ShellCommandRunPci ( PciExplainPciExpress ( (PCI_CAPABILITY_PCIEXP *) ((UINT8 *) &ConfigSpace + PcieCapabili= tyPtr), ExtendedConfigSpace, + ExtendedConfigSize, ExtendedCapability ); } @@ -5698,12 +5701,14 @@ PrintPciExtendedCapabilityDetails( =20 @param[in] PciExpressCap PCI Express capability buffer. @param[in] ExtendedConfigSpace PCI Express extended configuration space. + @param[in] ExtendedConfigSize PCI Express extended configuration size. @param[in] ExtendedCapability PCI Express extended capability ID to exp= lain. **/ VOID PciExplainPciExpress ( IN PCI_CAPABILITY_PCIEXP *PciExpressCap, IN UINT8 *ExtendedConfigSpace, + IN UINTN ExtendedConfigSize, IN CONST UINT16 ExtendedCapability ) { @@ -5786,7 +5791,7 @@ PciExplainPciExpress ( } =20 ExtHdr =3D (PCI_EXP_EXT_HDR*)ExtendedConfigSpace; - while (ExtHdr->CapabilityId !=3D 0 && ExtHdr->CapabilityVersion !=3D 0) { + while (ExtHdr->CapabilityId !=3D 0 && ExtHdr->CapabilityVersion !=3D 0 &= & ExtHdr->CapabilityId !=3D 0xFFFF) { // // Process this item // @@ -5800,7 +5805,8 @@ PciExplainPciExpress ( // // Advance to the next item if it exists // - if (ExtHdr->NextCapabilityOffset !=3D 0) { + if (ExtHdr->NextCapabilityOffset !=3D 0 && + (ExtHdr->NextCapabilityOffset <=3D (UINT32) (ExtendedConfigSize + E= FI_PCIE_CAPABILITY_BASE_OFFSET - sizeof (PCI_EXP_EXT_HDR)))) { ExtHdr =3D (PCI_EXP_EXT_HDR*)(ExtendedConfigSpace + ExtHdr->NextCapa= bilityOffset - EFI_PCIE_CAPABILITY_BASE_OFFSET); } else { break; --=20 2.18.0.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 (#72997): https://edk2.groups.io/g/devel/message/72997 Mute This Topic: https://groups.io/mt/81421888/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-