lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 21 Jun 2022 21:57:32 -0500
From:   Bjorn Helgaas <helgaas@...nel.org>
To:     Marek Vasut <marek.vasut+renesas@...il.com>,
        Yoshihiro Shimoda <yoshihiro.shimoda.uh@...esas.com>
Cc:     Liang He <windhl@....com>,
        Geert Uytterhoeven <geert+renesas@...der.be>,
        Lorenzo Pieralisi <lpieralisi@...nel.org>,
        Rob Herring <robh@...nel.org>,
        Krzysztof WilczyƄski <kw@...ux.com>,
        linux-pci@...r.kernel.org, linux-renesas-soc@...r.kernel.org,
        linux-kernel@...r.kernel.org, Bjorn Helgaas <bhelgaas@...gle.com>,
        Geert Uytterhoeven <geert@...ux-m68k.org>
Subject: [PATCH 2/2] PCI: rcar: Resolve of_find_matching_node() reference leak

From: Bjorn Helgaas <bhelgaas@...gle.com>

Previously, rcar_pcie_init() used of_find_matching_node() to search the
entire device tree for compatible strings for which we need to install an
abort handler.  If we found one, we got a device_node with refcount
incremented, but we discarded the pointer and never released that
reference.

Extend the struct rcar_variant to indicate whether each variant requires an
abort handler.  Install the handler in rcar_pcie_probe() when needed.

Signed-off-by: Bjorn Helgaas <bhelgaas@...gle.com>
Cc: Liang He <windhl@....com>
Cc: Geert Uytterhoeven <geert@...ux-m68k.org>
---
 drivers/pci/controller/pcie-rcar-host.c | 60 +++++++++++--------------
 1 file changed, 27 insertions(+), 33 deletions(-)

diff --git a/drivers/pci/controller/pcie-rcar-host.c b/drivers/pci/controller/pcie-rcar-host.c
index ccf13aafa1e5..139a0274b9e0 100644
--- a/drivers/pci/controller/pcie-rcar-host.c
+++ b/drivers/pci/controller/pcie-rcar-host.c
@@ -60,6 +60,7 @@ struct rcar_pcie_host;
 
 struct rcar_variant {
 	int	(*phy_init_fn)(struct rcar_pcie_host *host);
+	bool	hook_aborts;
 };
 
 /* Structure representing the PCIe interface */
@@ -964,12 +965,35 @@ static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie_host *host)
 	return err;
 }
 
+#ifdef CONFIG_ARM
+static int rcar_pcie_aarch32_abort_handler(unsigned long addr,
+		unsigned int fsr, struct pt_regs *regs)
+{
+	return !fixup_exception(regs);
+}
+#endif
+
+static void rcar_pcie_hook_aborts(void)
+{
+#ifdef CONFIG_ARM
+#ifdef CONFIG_ARM_LPAE
+	hook_fault_code(17, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,
+			"asynchronous external abort");
+#else
+	hook_fault_code(22, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,
+			"imprecise external abort");
+#endif
+#endif
+}
+
 static const struct rcar_variant rcar_h1_data = {
 	.phy_init_fn = rcar_pcie_phy_init_h1,
+	.hook_aborts = true,
 };
 
 static const struct rcar_variant rcar_gen2_data = {
 	.phy_init_fn = rcar_pcie_phy_init_gen2,
+	.hook_aborts = true,
 };
 
 static const struct rcar_variant rcar_gen3_data = {
@@ -1035,6 +1059,9 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 		goto err_clk_disable;
 	}
 
+	if (host->variant->hook_aborts)
+		rcar_pcie_hook_aborts();
+
 	/* Failure to get a link might just be that no cards are inserted */
 	if (rcar_pcie_hw_init(pcie)) {
 		dev_info(dev, "PCIe link down\n");
@@ -1153,37 +1180,4 @@ static struct platform_driver rcar_pcie_driver = {
 	},
 	.probe = rcar_pcie_probe,
 };
-
-#ifdef CONFIG_ARM
-static int rcar_pcie_aarch32_abort_handler(unsigned long addr,
-		unsigned int fsr, struct pt_regs *regs)
-{
-	return !fixup_exception(regs);
-}
-
-static const struct of_device_id rcar_pcie_abort_handler_of_match[] __initconst = {
-	{ .compatible = "renesas,pcie-r8a7779" },
-	{ .compatible = "renesas,pcie-r8a7790" },
-	{ .compatible = "renesas,pcie-r8a7791" },
-	{ .compatible = "renesas,pcie-rcar-gen2" },
-	{},
-};
-
-static int __init rcar_pcie_init(void)
-{
-	if (of_find_matching_node(NULL, rcar_pcie_abort_handler_of_match)) {
-#ifdef CONFIG_ARM_LPAE
-		hook_fault_code(17, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,
-				"asynchronous external abort");
-#else
-		hook_fault_code(22, rcar_pcie_aarch32_abort_handler, SIGBUS, 0,
-				"imprecise external abort");
-#endif
-	}
-
-	return platform_driver_register(&rcar_pcie_driver);
-}
-device_initcall(rcar_pcie_init);
-#else
 builtin_platform_driver(rcar_pcie_driver);
-#endif
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ