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: <1463180405-10177-1-git-send-email-khoroshilov@ispras.ru>
Date:	Sat, 14 May 2016 02:00:05 +0300
From:	Alexey Khoroshilov <khoroshilov@...ras.ru>
To:	Kashyap Desai <kashyap.desai@...gotech.com>,
	Sumit Saxena <sumit.saxena@...gotech.com>,
	Uday Lingala <uday.lingala@...gotech.com>,
	"James E.J. Bottomley" <jejb@...ux.vnet.ibm.com>
Cc:	Alexey Khoroshilov <khoroshilov@...ras.ru>,
	"Martin K. Petersen" <martin.petersen@...cle.com>,
	megaraidlinux.pdl@...gotech.com, linux-scsi@...r.kernel.org,
	linux-kernel@...r.kernel.org, ldv-project@...uxtesting.org
Subject: [PATCH] megaraid: fix error code check of register_chrdev()

There is invalid error code check of register_chrdev() in megaraid_init().

register_chrdev() returns negative code in case of error,
as a result current code can try to unregister_chrdev() with error code
instead of major that may lead to unregistering somebody else's chardev.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@...ras.ru>
---
 drivers/scsi/megaraid.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 9d05302a3bcd..ded082942ca0 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -4702,7 +4702,7 @@ static int __init megaraid_init(void)
 	 * major number allocation.
 	 */
 	major = register_chrdev(0, "megadev_legacy", &megadev_fops);
-	if (!major) {
+	if (major < 0) {
 		printk(KERN_WARNING
 				"megaraid: failed to register char device\n");
 	}
@@ -4715,7 +4715,10 @@ static void __exit megaraid_exit(void)
 	/*
 	 * Unregister the character device interface to the driver.
 	 */
-	unregister_chrdev(major, "megadev_legacy");
+	if (major > 0) {
+		unregister_chrdev(major, "megadev_legacy");
+		major = 0;
+	}
 
 	pci_unregister_driver(&megaraid_pci_driver);
 
-- 
1.9.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ