Skip to contentSkip to conversation

livepatch: robustify klp_register_patch() API error checking

PATCH In review Jiri Kosina 3 participants 4 messages Apr 7, 2016 1 message not in the archive Live patching

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 20160404203426.GA8200@mwanda

#1 lore raw

PATCH 1/1 livepatch: robustify klp_register_patch() API error checking

From: Jiri Kosina <[email protected]>

Commit 425595a7fc20 ("livepatch: reuse module loader code to write relocations") adds a possibility of dereferncing pointers supplied by the consumer of the livepatch API before sanity (NULL) checking them (patch and patch->mod).

Spotted by smatch tool.

---
 kernel/livepatch/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/livepatch/core.c +3 -3
index eb5db6e..28c37fa 100644
@@ -876,6 +876,9 @@ int klp_register_patch(struct klp_patch *patch)
 {
 	int ret;
 
+	if (!patch || !patch->mod)
+		return -EINVAL;
+
 	if (!is_livepatch_module(patch->mod)) {
 		pr_err("module %s is not marked as a livepatch module",
 		       patch->mod->name);
@@ -885,9 +888,6 @@ int klp_register_patch(struct klp_patch *patch)
 	if (!klp_initialized())
 		return -ENODEV;
 
-	if (!patch || !patch->mod)
-		return -EINVAL;
-
 	/*
 	 * A reference is taken on the patch module to prevent it from being
 	 * unloaded.  Right now, we don't allow patch modules to unload since
Signature · 2 lines
Jiri Kosina
SUSE Labs
Acked-by on v1 1/1
#2 lore raw
Quoted 11 lines · Jiri Kosina

From: Jiri Kosina <[email protected]>

Commit 425595a7fc20 ("livepatch: reuse module loader code to write relocations") adds a possibility of dereferncing pointers supplied by the consumer of the livepatch API before sanity (NULL) checking them (patch and patch->mod).

Spotted by smatch tool.

Signature · 1 line
Josh
Acked-by on v1 1/1
#3 lore raw
In reply to Jiri Kosina

+++ Jiri Kosina [07/04/16 18:06 +0200]:

Quoted 11 lines

From: Jiri Kosina <[email protected]>

Commit 425595a7fc20 ("livepatch: reuse module loader code to write relocations") adds a possibility of dereferncing pointers supplied by the consumer of the livepatch API before sanity (NULL) checking them (patch and patch->mod).

Spotted by smatch tool.

Thank you Jiri!

author Acked-by Josh Poimboeuf Acked-by Jessica Yu on v1 1/1
#4 lore raw
In reply to Jiri Kosina
Quoted 10 lines · Jiri Kosina

From: Jiri Kosina <[email protected]>

Commit 425595a7fc20 ("livepatch: reuse module loader code to write relocations") adds a possibility of dereferncing pointers supplied by the consumer of the livepatch API before sanity (NULL) checking them (patch and patch->mod).

Spotted by smatch tool.

Pushed out. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs