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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20221208130431.70382-1-yuancan@huawei.com>
Date:   Thu, 8 Dec 2022 13:04:31 +0000
From:   Yuan Can <yuancan@...wei.com>
To:     <lee@...nel.org>, <akpm@...ux-foundation.org>,
        <sameo@...nedhand.com>, <adobriyan@...il.com>,
        <linux-kernel@...r.kernel.org>
CC:     <yuancan@...wei.com>
Subject: [PATCH] mfd: sm501: Fix error handling in sm501_base_init()

A problem about modprobe sm501 failed is triggered with the following log
given:

 [ 4919.196338] Error: Driver 'sm501' is already registered, aborting...
 insmod: ERROR: could not insert module sm501.ko: Device or resource busy

The reason is that sm501_base_init() returns pci_register_driver()
directly without checking its return value, if pci_register_driver()
failed, it returns without unregistering sm501_plat_driver, resulting
the sm501 can never be installed later.
A simple call graph is shown as below:

 sm501_base_init()
   platform_driver_register() # sm501_plat_driver are registered
   pci_register_driver()
     driver_register()
       bus_add_driver()
         priv = kzalloc(...) # OOM happened
   # return without unregister sm501_plat_driver

Fix by calling platform_driver_unregister() when pci_register_driver()
returns error.

Fixes: 158abca5f699 ("mfd: fix sm501 section mismatches")
Signed-off-by: Yuan Can <yuancan@...wei.com>
---
 drivers/mfd/sm501.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 3ac4508a6742..c1efa040e94e 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -1726,7 +1726,13 @@ static int __init sm501_base_init(void)
 	if (ret < 0)
 		return ret;
 
-	return pci_register_driver(&sm501_pci_driver);
+	ret = pci_register_driver(&sm501_pci_driver);
+	if (ret) {
+		platform_driver_unregister(&sm501_plat_driver);
+		return ret;
+	}
+
+	return 0;
 }
 
 static void __exit sm501_base_exit(void)
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ