mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [patch] x86: pci: Prevent mmconfig memory corruption
@ 2010-02-25 15:42 Thomas Gleixner
  2010-02-25 15:48 ` Bjorn Helgaas
  2010-02-25 16:31 ` Jesse Barnes
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Gleixner @ 2010-02-25 15:42 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar, Jesse Barnes, Yinghai Lu, Bjorn Helgaas

commit ff097ddd4 (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
pci_mmcfg_list.

Further down a similar problem exists, where cfg->list.next 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: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: stable@kernel.org
---
 arch/x86/pci/mmconfig-shared.c |   17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

Index: linux-2.6/arch/x86/pci/mmconfig-shared.c
===================================================================
--- linux-2.6.orig/arch/x86/pci/mmconfig-shared.c
+++ linux-2.6/arch/x86/pci/mmconfig-shared.c
@@ -303,22 +303,17 @@ static void __init pci_mmcfg_check_end_b
 {
 	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))
-		return;
-
-	/* 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->list.next == &pci_mmcfg_list)
+			break;
+
 		cfgx = list_entry(cfg->list.next, 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;
 	}
 }

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

* Re: [patch] x86: pci: Prevent mmconfig memory corruption
  2010-02-25 15:42 [patch] x86: pci: Prevent mmconfig memory corruption Thomas Gleixner
@ 2010-02-25 15:48 ` Bjorn Helgaas
  2010-02-25 16:31 ` Jesse Barnes
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2010-02-25 15:48 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Ingo Molnar, Jesse Barnes, Yinghai Lu

On Thursday 25 February 2010 08:42:11 am Thomas Gleixner wrote:
> commit ff097ddd4 (x86/PCI: MMCONFIG: manage pci_mmcfg_region as a
> list, not a table) introduced a nasty memory corruption when
> pci_mmcfg_list is empty.

Ouch, I'm really sorry about that.  Thanks for fixing it.

Bjorn

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

* Re: [patch] x86: pci: Prevent mmconfig memory corruption
  2010-02-25 15:42 [patch] x86: pci: Prevent mmconfig memory corruption Thomas Gleixner
  2010-02-25 15:48 ` Bjorn Helgaas
@ 2010-02-25 16:31 ` Jesse Barnes
  1 sibling, 0 replies; 3+ messages in thread
From: Jesse Barnes @ 2010-02-25 16:31 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Ingo Molnar, Yinghai Lu, Bjorn Helgaas

On Thu, 25 Feb 2010 16:42:11 +0100 (CET)
Thomas Gleixner <tglx@linutronix.de> wrote:

> commit ff097ddd4 (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
> pci_mmcfg_list.
> 
> Further down a similar problem exists, where cfg->list.next 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: Ingo Molnar <mingo@elte.hu>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
> Cc: Yinghai Lu <yinghai@kernel.org>
> Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
> Cc: stable@kernel.org
> ---

Applied to my linux-next branch, thanks.  I'll be part of my pull
request to Linus tomorrow.

-- 
Jesse Barnes, Intel Open Source Technology Center

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

end of thread, other threads:[~2010-02-25 16:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-25 15:42 [patch] x86: pci: Prevent mmconfig memory corruption Thomas Gleixner
2010-02-25 15:48 ` Bjorn Helgaas
2010-02-25 16:31 ` Jesse Barnes

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

all inboxes | Powered by JetHome®