Commit bb8d4133 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Jesse Barnes
Browse files

x86/PCI: Prevent mmconfig memory corruption

commit ff097ddd

 (x86/PCI: MMCONFIG: manage pci_mmcfg_region as a
list, not a table) introduced a nasty memory corruption when
pci_mmcfg_list is empty.

pci_mmcfg_check_end_bus_number() dereferences pci_mmcfg_list.prev even
when the list is empty. The following write hits some variable near to

Further down a similar problem exists, where cfg-> is
dereferenced unconditionally and a comparison with some variable near
to pci_mmcfg_list happens.

Add a check for the last element into the for_each_entry() loop and
remove all the other crappy logic which is just a leftover of the old
array based code which was replaced by the list conversion.

Reported-by: default avatarIngo Molnar <>
Signed-off-by: default avatarThomas Gleixner <>
Cc: Bjorn Helgaas <>
Cc: Yinghai Lu <>
Signed-off-by: default avatarJesse Barnes <>
parent cbbc0de7
......@@ -303,22 +303,17 @@ static void __init pci_mmcfg_check_end_bus_number(void)
struct pci_mmcfg_region *cfg, *cfgx;
/* last one*/
cfg = list_entry(pci_mmcfg_list.prev, typeof(*cfg), list);
if (cfg)
if (cfg->end_bus < cfg->start_bus)
cfg->end_bus = 255;
if (list_is_singular(&pci_mmcfg_list))
/* don't overlap please */
/* Fixup overlaps */
list_for_each_entry(cfg, &pci_mmcfg_list, list) {
if (cfg->end_bus < cfg->start_bus)
cfg->end_bus = 255;
/* Don't access the list head ! */
if (cfg-> == &pci_mmcfg_list)
cfgx = list_entry(cfg->, typeof(*cfg), list);
if (cfg != cfgx && cfg->end_bus >= cfgx->start_bus)
if (cfg->end_bus >= cfgx->start_bus)
cfg->end_bus = cfgx->start_bus - 1;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment