summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2016-04-07 19:06:25 +0300
committerJiri Kosina <jkosina@suse.cz>2016-04-07 21:42:38 +0300
commit61bf12d3304d78ff499245ea995858c3bedb162e (patch)
treee0f558a6afea387144af7561e1cc6a978c82ea48
parent3b812ecce736432e6b55e77028ea387eb1517d24 (diff)
downloadlinux-61bf12d3304d78ff499245ea995858c3bedb162e.tar.xz
livepatch: robustify klp_register_patch() API error checking
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. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Acked-by: Jessica Yu <jeyu@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--kernel/livepatch/core.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index eb5db6e837aa..28c37fa3d3f9 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -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