libpci: Fix intel_sanity_check() function
Subsystems (2)
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
@@ -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
Hello!
Quoted 10 lines
Function
intel_sanity_check()callsconf1_read()which accessd->domainfield. Butintel_sanity_check()does not initialize this field and soconf1_read()access some random data on stack.Tests showed that
intel_sanity_check()always fails as ind->domainis stored some non-zero number.Fix this issue by properly initializing struct
pci_devd and explicitly setd->domainto zero inintel_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
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
@@ -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
Martin Mareš
AppliedHi!
Quoted 9 lines
Function
intel_sanity_check()callsconf1_read()which accessd->domainfield. Butintel_sanity_check()does not initialize this field and soconf1_read()access some random data on stack.Tests showed that
intel_sanity_check()always fails as ind->domainis stored some non-zero number.Fix this issue by zeroing struct
pci_devd inintel_sanity_check()as sanity check is verifying PCI devices at domain 0.
Thanks, applied.
Martin