Skip to contentSkip to conversation

libpci: Fix intel_sanity_check() function

PATCH Superseded Pali Rohár 2 participants 4 messages Dec 21, 2021 – Dec 26, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libpci: Fix intel_sanity_check() function

Function intel_sanity_check() calls conf1_read() which access d->domain field. But intel_sanity_check() does not initialize this field and so conf1_read() access some random data on stack.

Tests showed that intel_sanity_check() always fails as in d->domain is stored some non-zero number.

Fix this issue by properly initializing struct pci_dev d and explicitly set d->domain to zero in intel_sanity_check() as sanity check is verifying PCI devices at domain 0.

---
 lib/i386-ports.c | 2 ++
 1 file changed, 2 insertions(+)
lib/i386-ports.c +2 -0
index b3b752cb1f3f..b5e09dab6002 100644
@@ -72,7 +72,9 @@ intel_sanity_check(struct pci_access *a, struct pci_methods *m)
 {
   struct pci_dev d;
 
+  memset(&d, 0, sizeof(d));
   a->debug("...sanity check");
+  d.domain = 0;
   d.bus = 0;
   d.func = 0;
   for (d.dev = 0; d.dev < 32; d.dev++)
Signature · 1 line
2.20.1
#1 lore raw

Hello!

Quoted 10 lines

Function intel_sanity_check() calls conf1_read() which access d->domain field. But intel_sanity_check() does not initialize this field and so conf1_read() access some random data on stack.

Tests showed that intel_sanity_check() always fails as in d->domain is stored some non-zero number.

Fix this issue by properly initializing struct pci_dev d and explicitly set d->domain to zero in intel_sanity_check() as sanity check is verifying PCI devices at domain 0.

Thanks for finding the bug, but it makes little sense to initialize the fields twice (once by memset, second time by zeroing out individual members). Just keep the memset.

Martin

#2 lore raw

PATCH v2 1/1 libpci: Fix intel_sanity_check() function

Function intel_sanity_check() calls conf1_read() which access d->domain field. But intel_sanity_check() does not initialize this field and so conf1_read() access some random data on stack.

Tests showed that intel_sanity_check() always fails as in d->domain is stored some non-zero number.

Fix this issue by zeroing struct pci_dev d in intel_sanity_check() as sanity check is verifying PCI devices at domain 0.
---
v2: Remove explicit set of d->domain to zero.

---
 lib/i386-ports.c | 1 +
 1 file changed, 1 insertion(+)
lib/i386-ports.c +1 -0
index b3b752cb1f3f..2f90aa4cee0a 100644
@@ -72,6 +72,7 @@ intel_sanity_check(struct pci_access *a, struct pci_methods *m)
 {
   struct pci_dev d;
 
+  memset(&d, 0, sizeof(d));
   a->debug("...sanity check");
   d.bus = 0;
   d.func = 0;
Signature · 1 line
2.20.1
#3 lore raw

Hi!

Quoted 9 lines

Function intel_sanity_check() calls conf1_read() which access d->domain field. But intel_sanity_check() does not initialize this field and so conf1_read() access some random data on stack.

Tests showed that intel_sanity_check() always fails as in d->domain is stored some non-zero number.

Fix this issue by zeroing struct pci_dev d in intel_sanity_check() as sanity check is verifying PCI devices at domain 0.

Thanks, applied.

Martin