summaryrefslogtreecommitdiffstats
path: root/NetworkPkg/SnpDxe/Snp.c
diff options
context:
space:
mode:
authorMichael Kubacki <michael.kubacki@microsoft.com>2020-04-08 20:02:05 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-04-17 17:34:33 +0000
commitdf4f154da9cb193b8e539157d1ed1a851cf1488e (patch)
tree24d04f4e94ab14722ecedc5e2ae9c4e63e9d183e /NetworkPkg/SnpDxe/Snp.c
parentca08f3d4533caf152170fe9ec0ce585e452d995e (diff)
downloadedk2-df4f154da9cb193b8e539157d1ed1a851cf1488e.tar.gz
edk2-df4f154da9cb193b8e539157d1ed1a851cf1488e.tar.bz2
edk2-df4f154da9cb193b8e539157d1ed1a851cf1488e.zip
NetworkPkg/SnpDxe: Prevent invalid PCI BAR access
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1563 SnpDxe initializes values for MemoryBarIndex and IoBarIndex to 0 and 1 respectively even if calls to PciIo->GetBarAttributes never return success. Later, if the BAR is used to perform IO/Mem reads/writes, a potentially non-existent BAR index may be accessed. This change initializes the values to an invalid BAR index (PCI_MAX_BAR) so the condition can be explicitly checked to avoid an invalid BAR access. Cc: Siyuan Fu <siyuan.fu@intel.com> Cc: Maciej Rabeda <maciej.rabeda@linux.intel.com> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Siyuan Fu <siyuan.fu@intel.com> Reviewed-by: Maciej Rabeda <maciej.rabeda@linux.intel.com>
Diffstat (limited to 'NetworkPkg/SnpDxe/Snp.c')
-rw-r--r--NetworkPkg/SnpDxe/Snp.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/NetworkPkg/SnpDxe/Snp.c b/NetworkPkg/SnpDxe/Snp.c
index fe022e16ea..69e74132ed 100644
--- a/NetworkPkg/SnpDxe/Snp.c
+++ b/NetworkPkg/SnpDxe/Snp.c
@@ -466,8 +466,8 @@ SimpleNetworkDriverStart (
// the IO BAR. Save the index of the BAR into the adapter info structure.
// for regular 32bit BARs, 0 is memory mapped, 1 is io mapped
//
- Snp->MemoryBarIndex = 0;
- Snp->IoBarIndex = 1;
+ Snp->MemoryBarIndex = PCI_MAX_BAR;
+ Snp->IoBarIndex = PCI_MAX_BAR;
FoundMemoryBar = FALSE;
FoundIoBar = FALSE;
for (BarIndex = 0; BarIndex < PCI_MAX_BAR; BarIndex++) {