public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v4] ShellPkg/Pci: Add valid check for PCI extended config space parser
@ 2021-03-17 16:01 IanX Kuo
  2021-03-19  3:07 ` [edk2-devel] " Gao, Zhichao
  0 siblings, 1 reply; 2+ messages in thread
From: IanX Kuo @ 2021-03-17 16:01 UTC (permalink / raw)
  To: devel; +Cc: VincentX Ke

From: VincentX Ke <vincentx.ke@intel.com>

Bugzilla: 3262 (https://bugzilla.tianocore.org/show_bug.cgi?id=3262)

No need to print PCIe details while CapabilityId is 0xFFFF.
Limit the NextCapabilityOffset to PCI/PCIe configuration space.

Signed-off-by: VincentX Ke <vincentx.ke@intel.com>
---
 ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c
index a2f04d8db5..1e5dc75e27 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c
@@ -2038,12 +2038,14 @@ LocatePciCapability (
 
   @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 explain.
 **/
 VOID
 PciExplainPciExpress (
   IN  PCI_CAPABILITY_PCIEXP                  *PciExpressCap,
   IN  UINT8                                  *ExtendedConfigSpace,
+  IN  UINTN                                  ExtendedConfigSize,
   IN CONST UINT16                            ExtendedCapability
   );
 
@@ -2921,6 +2923,7 @@ ShellCommandRunPci (
         PciExplainPciExpress (
           (PCI_CAPABILITY_PCIEXP *) ((UINT8 *) &ConfigSpace + PcieCapabilityPtr),
           ExtendedConfigSpace,
+          ExtendedConfigSize,
           ExtendedCapability
           );
       }
@@ -5698,12 +5701,14 @@ PrintPciExtendedCapabilityDetails(
 
   @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 explain.
 **/
 VOID
 PciExplainPciExpress (
   IN  PCI_CAPABILITY_PCIEXP                  *PciExpressCap,
   IN  UINT8                                  *ExtendedConfigSpace,
+  IN  UINTN                                  ExtendedConfigSize,
   IN CONST UINT16                            ExtendedCapability
   )
 {
@@ -5786,7 +5791,7 @@ PciExplainPciExpress (
   }
 
   ExtHdr = (PCI_EXP_EXT_HDR*)ExtendedConfigSpace;
-  while (ExtHdr->CapabilityId != 0 && ExtHdr->CapabilityVersion != 0) {
+  while (ExtHdr->CapabilityId != 0 && ExtHdr->CapabilityVersion != 0 && ExtHdr->CapabilityId != 0xFFFF) {
     //
     // Process this item
     //
@@ -5800,7 +5805,8 @@ PciExplainPciExpress (
     //
     // Advance to the next item if it exists
     //
-    if (ExtHdr->NextCapabilityOffset != 0) {
+    if (ExtHdr->NextCapabilityOffset != 0 &&
+       (ExtHdr->NextCapabilityOffset <= (UINT32) (ExtendedConfigSize + EFI_PCIE_CAPABILITY_BASE_OFFSET - sizeof (PCI_EXP_EXT_HDR)))) {
       ExtHdr = (PCI_EXP_EXT_HDR*)(ExtendedConfigSpace + ExtHdr->NextCapabilityOffset - EFI_PCIE_CAPABILITY_BASE_OFFSET);
     } else {
       break;
-- 
2.18.0.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-devel] [PATCH v4] ShellPkg/Pci: Add valid check for PCI extended config space parser
  2021-03-17 16:01 [PATCH v4] ShellPkg/Pci: Add valid check for PCI extended config space parser IanX Kuo
@ 2021-03-19  3:07 ` Gao, Zhichao
  0 siblings, 0 replies; 2+ messages in thread
From: Gao, Zhichao @ 2021-03-19  3:07 UTC (permalink / raw)
  To: devel@edk2.groups.io, Kuo, IanX; +Cc: Ke, VincentX, Laszlo Ersek, Ni, Ray

Hi Ian/Vincent,

It is better to add the reviewers/maintainers in the CC list. And also add the one who already give the comment.
You can do this with 'git send-email -cc xxx.com' or add Cc: Name <email_address> in the commit message.

Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>

Thanks,
Zhichao

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of IanX
> Kuo
> Sent: Thursday, March 18, 2021 12:02 AM
> To: devel@edk2.groups.io
> Cc: Ke, VincentX <vincentx.ke@intel.com>
> Subject: [edk2-devel] [PATCH v4] ShellPkg/Pci: Add valid check for PCI
> extended config space parser
> 
> From: VincentX Ke <vincentx.ke@intel.com>
> 
> Bugzilla: 3262 (https://bugzilla.tianocore.org/show_bug.cgi?id=3262)
> 
> No need to print PCIe details while CapabilityId is 0xFFFF.
> Limit the NextCapabilityOffset to PCI/PCIe configuration space.
> 
> Signed-off-by: VincentX Ke <vincentx.ke@intel.com>
> ---
>  ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c
> index a2f04d8db5..1e5dc75e27 100644
> --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c
> +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c
> @@ -2038,12 +2038,14 @@ LocatePciCapability (
>     @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
> explain. **/ VOID PciExplainPciExpress (   IN  PCI_CAPABILITY_PCIEXP
> *PciExpressCap,   IN  UINT8                                  *ExtendedConfigSpace,+  IN
> UINTN                                  ExtendedConfigSize,   IN CONST UINT16
> ExtendedCapability   ); @@ -2921,6 +2923,7 @@ ShellCommandRunPci (
>          PciExplainPciExpress (           (PCI_CAPABILITY_PCIEXP *) ((UINT8 *)
> &ConfigSpace + PcieCapabilityPtr),           ExtendedConfigSpace,+
> ExtendedConfigSize,           ExtendedCapability           );       }@@ -5698,12
> +5701,14 @@ PrintPciExtendedCapabilityDetails(
>     @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
> explain. **/ VOID PciExplainPciExpress (   IN  PCI_CAPABILITY_PCIEXP
> *PciExpressCap,   IN  UINT8                                  *ExtendedConfigSpace,+  IN
> UINTN                                  ExtendedConfigSize,   IN CONST UINT16
> ExtendedCapability   ) {@@ -5786,7 +5791,7 @@ PciExplainPciExpress (
>    }    ExtHdr = (PCI_EXP_EXT_HDR*)ExtendedConfigSpace;-  while (ExtHdr-
> >CapabilityId != 0 && ExtHdr->CapabilityVersion != 0) {+  while (ExtHdr-
> >CapabilityId != 0 && ExtHdr->CapabilityVersion != 0 && ExtHdr-
> >CapabilityId != 0xFFFF) {     //     // Process this item     //@@ -5800,7 +5805,8
> @@ PciExplainPciExpress (
>      //     // Advance to the next item if it exists     //-    if (ExtHdr-
> >NextCapabilityOffset != 0) {+    if (ExtHdr->NextCapabilityOffset != 0 &&+
> (ExtHdr->NextCapabilityOffset <= (UINT32) (ExtendedConfigSize +
> EFI_PCIE_CAPABILITY_BASE_OFFSET - sizeof (PCI_EXP_EXT_HDR))))
> {       ExtHdr = (PCI_EXP_EXT_HDR*)(ExtendedConfigSpace + ExtHdr-
> >NextCapabilityOffset - EFI_PCIE_CAPABILITY_BASE_OFFSET);     } else
> {       break;--
> 2.18.0.windows.1
> 
> 
> 
> -=-=-=-=-=-=
> 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/1768756
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub [zhichao.gao@intel.com]
> -=-=-=-=-=-=
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-19  3:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-17 16:01 [PATCH v4] ShellPkg/Pci: Add valid check for PCI extended config space parser IanX Kuo
2021-03-19  3:07 ` [edk2-devel] " Gao, Zhichao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox