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:05 +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 05/23] livepatch: Initialize and free livepatch submodule

Another step when loading livepatches to livepatch modules is
to initialize the structure, create sysfs entries, do livepatch
specific relocations.

These operation can fail and the objects must be freed that case.
The error message is taken from klp_module_coming() to match
selftests.

Signed-off-by: Petr Mladek <pmladek@...e.com>
---
 kernel/livepatch/core.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index e2c7dc6c2d5f..6c27b635e5a7 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -583,18 +583,23 @@ static void klp_free_object_loaded(struct klp_object *obj)
 	}
 }
 
+static void klp_free_object(struct klp_object *obj, bool nops_only)
+{
+	__klp_free_funcs(obj, nops_only);
+
+	if (nops_only && !obj->dynamic)
+		return;
+
+	list_del(&obj->node);
+	kobject_put(&obj->kobj);
+}
+
 static void __klp_free_objects(struct klp_patch *patch, bool nops_only)
 {
 	struct klp_object *obj, *tmp_obj;
 
 	klp_for_each_object_safe(patch, obj, tmp_obj) {
-		__klp_free_funcs(obj, nops_only);
-
-		if (nops_only && !obj->dynamic)
-			continue;
-
-		list_del(&obj->node);
-		kobject_put(&obj->kobj);
+		klp_free_object(obj, nops_only);
 	}
 }
 
@@ -812,6 +817,8 @@ static int klp_init_object_early(struct klp_patch *patch,
 	if (obj->dynamic || try_module_get(obj->mod))
 		return 0;
 
+	/* patch stays when this function fails in klp_add_object() */
+	list_del(&obj->node);
 	return -ENODEV;
 }
 
@@ -993,9 +1000,22 @@ int klp_add_object(struct klp_object *obj)
 		goto err;
 	}
 
+	ret = klp_init_object_early(patch, obj);
+	if (ret)
+		goto err;
+
+	ret = klp_init_object(patch, obj);
+	if (ret) {
+		pr_warn("failed to initialize patch '%s' for module '%s' (%d)\n",
+			patch->obj->patch_name, obj->name, ret);
+		goto err_free;
+	}
+
 	mutex_unlock(&klp_mutex);
 	return 0;
 
+err_free:
+	klp_free_object(obj, false);
 err:
 	/*
 	 * If a patch is unsuccessfully applied, return
-- 
2.16.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ