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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 17 Jan 2020 16:03:18 +0100
From:   Petr Mladek <pmladek@...e.com>
To:     Jiri Kosina <jikos@...nel.org>,
        Josh Poimboeuf <jpoimboe@...hat.com>,
        Miroslav Benes <mbenes@...e.cz>
Cc:     Joe Lawrence <joe.lawrence@...hat.com>,
        Kamalesh Babulal <kamalesh@...ux.vnet.ibm.com>,
        Nicolai Stange <nstange@...e.de>,
        live-patching@...r.kernel.org, linux-kernel@...r.kernel.org,
        Petr Mladek <pmladek@...e.com>
Subject: [POC 18/23] module: Refactor add_unformed_module()

The livepatching code will need to add another condition to avoid
waiting. Let's make the code slightly less hairy.

Of course, it is a matter of taste. The main ideas of refactoring:

  + Make it clear what happens when old->state == MODULE_STATE_LIVE.

  + Make it more clear when we are leaving the function immediately
    and when we are doing some extra actions.

  + Be able to add another check that has to be done outside
    module_mutex and can result into an immediate return.

Signed-off-by: Petr Mladek <pmladek@...e.com>
---
 kernel/module.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index b3f11524f8f9..ac45d465ff23 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -3721,28 +3721,30 @@ static int add_unformed_module(struct module *mod)
 again:
 	mutex_lock(&module_mutex);
 	old = find_module_all(mod->name, strlen(mod->name), true);
+
 	if (old != NULL) {
-		if (old->state != MODULE_STATE_LIVE) {
-			/* Wait in case it fails to load. */
+		if (old->state == MODULE_STATE_LIVE) {
 			mutex_unlock(&module_mutex);
-			err = wait_event_interruptible(module_wq,
-					       finished_loading(mod->name));
-			if (err)
-				goto out_unlocked;
-			goto again;
+			return -EEXIST;
 		}
-		err = -EEXIST;
-		goto out;
+
+		/* Wait in case it fails to load. */
+		mutex_unlock(&module_mutex);
+		err = wait_event_interruptible(module_wq,
+					       finished_loading(mod->name));
+		if (err)
+			return err;
+
+		/* Did the load succeded or failed? */
+		goto again;
 	}
+
 	mod_update_bounds(mod);
 	list_add_rcu(&mod->list, &modules);
 	mod_tree_insert(mod);
-	err = 0;
 
-out:
 	mutex_unlock(&module_mutex);
-out_unlocked:
-	return err;
+	return 0;
 }
 
 static int complete_formation(struct module *mod, struct load_info *info)
-- 
2.16.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ