From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Simon Horman <horms@verge.net.au>,
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Bjorn Helgaas <bhelgaas@google.com>
Cc: Harunobu Kurokawa <harunobu.kurokawa.dn@renesas.com>,
Phil Edworthy <phil.edworthy@renesas.com>,
linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-kernel@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH 1/2] PCI: rcar: Fix use-after-free in probe error path
Date: Thu, 7 Dec 2017 11:15:19 +0100 [thread overview]
Message-ID: <1512641720-4715-2-git-send-email-geert+renesas@glider.be> (raw)
In-Reply-To: <1512641720-4715-1-git-send-email-geert+renesas@glider.be>
If CONFIG_DEBUG_SLAB=y, and no PCIe card is inserted, the kernel crashes
during probe on r8a7791/koelsch:
rcar-pcie fe000000.pcie: PCIe link down
Unable to handle kernel paging request at virtual address 6b6b6b6b
(seeing this message requires earlycon and keep_bootcon).
Indeed, pci_free_host_bridge() frees the PCI host bridge, including the
embedded rcar_pcie object, so pci_free_resource_list() must not be
called afterwards.
To fix this, move the call to pci_free_resource_list() up, and update the
label name accordingly.
Fixes: ddd535f1ea3eb27e ("PCI: rcar: Fix memory leak when no PCIe card is inserted")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/pci/host/pcie-rcar.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c
index 12796eccb2befd91..52ab3cb0a0bfe065 100644
--- a/drivers/pci/host/pcie-rcar.c
+++ b/drivers/pci/host/pcie-rcar.c
@@ -1128,12 +1128,12 @@ static int rcar_pcie_probe(struct platform_device *pdev)
err = rcar_pcie_get_resources(pcie);
if (err < 0) {
dev_err(dev, "failed to request resources: %d\n", err);
- goto err_free_bridge;
+ goto err_free_resource_list;
}
err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
if (err)
- goto err_free_bridge;
+ goto err_free_resource_list;
pm_runtime_enable(dev);
err = pm_runtime_get_sync(dev);
@@ -1176,9 +1176,9 @@ static int rcar_pcie_probe(struct platform_device *pdev)
err_pm_disable:
pm_runtime_disable(dev);
-err_free_bridge:
- pci_free_host_bridge(bridge);
+err_free_resource_list:
pci_free_resource_list(&pcie->resources);
+ pci_free_host_bridge(bridge);
return err;
}
--
2.7.4
next prev parent reply other threads:[~2017-12-07 10:15 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-07 10:15 [PATCH 0/2] PCI: rcar: Misc error path fixes Geert Uytterhoeven
2017-12-07 10:15 ` Geert Uytterhoeven [this message]
2017-12-08 10:24 ` [PATCH 1/2] PCI: rcar: Fix use-after-free in probe error path Lorenzo Pieralisi
2017-12-12 19:29 ` Bjorn Helgaas
2017-12-13 8:29 ` Simon Horman
2017-12-07 10:15 ` [PATCH 2/2] PCI: rcar: Handle rcar_pcie_parse_request_of_pci_ranges() failures Geert Uytterhoeven
2017-12-08 10:30 ` Lorenzo Pieralisi
2017-12-19 11:40 ` Lorenzo Pieralisi
2017-12-07 10:29 ` [PATCH 0/2] PCI: rcar: Misc error path fixes Simon Horman
2017-12-12 17:16 ` Bjorn Helgaas
2017-12-12 18:07 ` Geert Uytterhoeven
2017-12-12 18:10 ` Lorenzo Pieralisi
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=1512641720-4715-2-git-send-email-geert+renesas@glider.be \
--to=geert+renesas@glider.be \
--cc=bhelgaas@google.com \
--cc=harunobu.kurokawa.dn@renesas.com \
--cc=horms@verge.net.au \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=phil.edworthy@renesas.com \
/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).