linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: Bjorn Helgaas <bhelgaas@google.com>,
	Taku Izumi <izumi.taku@jp.fujitsu.com>,
	Jiang Liu <jiang.liu@huawei.com>, x86 <x86@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-acpi@vger.kernel.org, Yinghai Lu <yinghai@kernel.org>
Subject: [PATCH part4 04/11] PCI: Fix an access-after-free issue in function pci_stop_and_remove_bus()
Date: Sun,  2 Sep 2012 14:54:14 -0700	[thread overview]
Message-ID: <1346622861-30865-5-git-send-email-yinghai@kernel.org> (raw)
In-Reply-To: <1346622861-30865-1-git-send-email-yinghai@kernel.org>

From: Jiang Liu <jiang.liu@huawei.com>

If pci_stop_and_remove_bus() is called to remove a pci root bus,
the host_bridge structure may have already been freed after returning
from pci_remove_bus(). To avoid that, hold an extra reference count
to the root bus before calling pci_remove_bus(), so we can safely
access the pci_host_bridge structure after returning from function
pci_remove_bus().

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/remove.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index 94407d4..40f8148 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -154,6 +154,7 @@ void pci_stop_and_remove_bus(struct pci_bus *bus)
 
 	if (pci_is_root_bus(bus)) {
 		host_bridge = to_pci_host_bridge(bus->bridge);
+		get_device(&host_bridge->dev);
 		pci_stop_host_bridge(host_bridge);
 	} else
 		pci_bridge = bus->self;
@@ -162,8 +163,10 @@ void pci_stop_and_remove_bus(struct pci_bus *bus)
 
 	pci_remove_bus(bus);
 
-	if (host_bridge)
+	if (host_bridge) {
 		host_bridge->bus = NULL;
+		put_device(&host_bridge->dev);
+	}
 
 	if (pci_bridge)
 		pci_bridge->subordinate = NULL;
-- 
1.7.7


  parent reply	other threads:[~2012-09-02 21:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-02 21:54 [PATCH part4 00/11] PCI, ACPI: pci root bus hotplug support - part4 Yinghai Lu
2012-09-02 21:54 ` [PATCH part4 01/11] PCI: Fix a device reference count leakage issue in pci_dev_present() Yinghai Lu
2012-09-02 21:54 ` [PATCH part4 02/11] PCI: Correctly clean up pci root buses in function pci_remove_bus() Yinghai Lu
2012-09-02 21:54 ` [PATCH part4 03/11] PCI: Add pci_stop_and_remove_bus() Yinghai Lu
2012-09-02 21:54 ` Yinghai Lu [this message]
2012-09-02 21:54 ` [PATCH part4 05/11] PCI, acpiphp: Separate out hot-add support of pci host bridge Yinghai Lu
2012-09-02 21:54 ` [PATCH part4 06/11] PCI, ACPI: Make acpi_pci_root_remove remove pci root bus too Yinghai Lu
2012-09-02 21:54 ` [PATCH part4 07/11] PCI, ACPI: Add pci_root_hp hot removal notification support Yinghai Lu
2012-09-02 21:54 ` [PATCH part4 08/11] PCI, ACPI: Add alloc_acpi_hp_work() Yinghai Lu
2012-09-02 21:54 ` [PATCH part4 09/11] PCI, acpiphp: Use acpi_hp_work Yinghai Lu
2012-09-02 21:54 ` [PATCH part4 10/11] PCI, pci_root_hp: " Yinghai Lu
2012-09-02 21:54 ` [PATCH part4 11/11] PCI, ACPI: Make kacpi_hotplug_wq static Yinghai Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1346622861-30865-5-git-send-email-yinghai@kernel.org \
    --to=yinghai@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bhelgaas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=izumi.taku@jp.fujitsu.com \
    --cc=jiang.liu@huawei.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).