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]
Date:	Mon, 18 May 2015 20:11:46 +0300
From:	Vladimir Zapolskiy <vladimir_zapolskiy@...tor.com>
To:	Arnd Bergmann <arnd@...db.de>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
CC:	<linux-kernel@...r.kernel.org>
Subject: [PATCH] char: misc: restore MISC_DYNAMIC_MINOR on device_create() failure

On attempt to register a dynamic minor misc device its minor number is
updated to a virtual minor number prior to device_create() call,
however on error path misc->minor == MISC_DYNAMIC_MINOR is not
restored.

Following the rule of thumb that a function returning an error must
not change the state of the caller, assign MISC_DYNAMIC_MINOR back.

The problem is met in a sutuation, when subsys_initcall(misc_init) is
not yet called and misc_class is not created, but misc_register()
modifies statically defined ".minor = MISC_DYNAMIC_MINOR", therefore
implicitly changing the client's logic on next attempt (e.g. retrying
from deferred list) to register a misc device, whose minor number is
converted from dynamic to some unknown static one.

Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@...tor.com>
---
 drivers/char/misc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 9fd5a91..5113409 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -186,12 +186,13 @@ int misc_register(struct miscdevice * misc)
 {
 	dev_t dev;
 	int err = 0;
+	bool is_dynamic = (misc->minor == MISC_DYNAMIC_MINOR);
 
 	INIT_LIST_HEAD(&misc->list);
 
 	mutex_lock(&misc_mtx);
 
-	if (misc->minor == MISC_DYNAMIC_MINOR) {
+	if (is_dynamic) {
 		int i = find_first_zero_bit(misc_minors, DYNAMIC_MINORS);
 		if (i >= DYNAMIC_MINORS) {
 			err = -EBUSY;
@@ -216,9 +217,13 @@ int misc_register(struct miscdevice * misc)
 		device_create_with_groups(misc_class, misc->parent, dev,
 					  misc, misc->groups, "%s", misc->name);
 	if (IS_ERR(misc->this_device)) {
-		int i = DYNAMIC_MINORS - misc->minor - 1;
-		if (i < DYNAMIC_MINORS && i >= 0)
-			clear_bit(i, misc_minors);
+		if (is_dynamic) {
+			int i = DYNAMIC_MINORS - misc->minor - 1;
+
+			if (i < DYNAMIC_MINORS && i >= 0)
+				clear_bit(i, misc_minors);
+			misc->minor = MISC_DYNAMIC_MINOR;
+		}
 		err = PTR_ERR(misc->this_device);
 		goto out;
 	}
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ