* [PATCH] PCI: Avoid potential NULL pointer dereference in pci_scan_bridge
@ 2011-01-24 20:14 Jesper Juhl
2011-02-08 21:10 ` Jesse Barnes
0 siblings, 1 reply; 2+ messages in thread
From: Jesper Juhl @ 2011-01-24 20:14 UTC (permalink / raw)
To: linux-pci; +Cc: linux-kernel, Jesse Barnes
pci_add_new_bus() calls pci_alloc_child_bus() which calls pci_alloc_bus()
that allocates memory dynamically with kzalloc(). The return value of
kzalloc() is the pointer that's eventually returned from
pci_add_new_bus(), so since kzalloc() can fail and return NULL so can
pci_add_new_bus(). Thus we may end up dereferencing a NULL pointer in
drivers/pci/probe.c::pci_scan_bridge(). Seems to me we should test for
this and bail out if it happens rather than crashing.
Also removed some trailing whitespace that bugged me while looking at
this.
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
probe.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
compile tested
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c84900d..44cbbba 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -764,6 +764,8 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
if (pci_find_bus(pci_domain_nr(bus), max+1))
goto out;
child = pci_add_new_bus(bus, dev, ++max);
+ if (!child)
+ goto out;
buses = (buses & 0xff000000)
| ((unsigned int)(child->primary) << 0)
| ((unsigned int)(child->secondary) << 8)
@@ -777,7 +779,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
buses &= ~0xff000000;
buses |= CARDBUS_LATENCY_TIMER << 24;
}
-
+
/*
* We need to blast all three values with a single write.
*/
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] PCI: Avoid potential NULL pointer dereference in pci_scan_bridge
2011-01-24 20:14 [PATCH] PCI: Avoid potential NULL pointer dereference in pci_scan_bridge Jesper Juhl
@ 2011-02-08 21:10 ` Jesse Barnes
0 siblings, 0 replies; 2+ messages in thread
From: Jesse Barnes @ 2011-02-08 21:10 UTC (permalink / raw)
To: Jesper Juhl; +Cc: linux-pci, linux-kernel
On Mon, 24 Jan 2011 21:14:33 +0100 (CET)
Jesper Juhl <jj@chaosbits.net> wrote:
> pci_add_new_bus() calls pci_alloc_child_bus() which calls pci_alloc_bus()
> that allocates memory dynamically with kzalloc(). The return value of
> kzalloc() is the pointer that's eventually returned from
> pci_add_new_bus(), so since kzalloc() can fail and return NULL so can
> pci_add_new_bus(). Thus we may end up dereferencing a NULL pointer in
> drivers/pci/probe.c::pci_scan_bridge(). Seems to me we should test for
> this and bail out if it happens rather than crashing.
> Also removed some trailing whitespace that bugged me while looking at
> this.
>
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
Applied to linux-next (in the absence of actual reports I'll be
conservative), thanks.
--
Jesse Barnes, Intel Open Source Technology Center
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-02-08 21:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-24 20:14 [PATCH] PCI: Avoid potential NULL pointer dereference in pci_scan_bridge Jesper Juhl
2011-02-08 21:10 ` 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®