Skip to content

Commit 61bf12d

Browse files
author
Jiri Kosina
committed
livepatch: robustify klp_register_patch() API error checking
Commit 425595a ("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>
1 parent 3b812ec commit 61bf12d

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

kernel/livepatch/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,9 @@ int klp_register_patch(struct klp_patch *patch)
876876
{
877877
int ret;
878878

879+
if (!patch || !patch->mod)
880+
return -EINVAL;
881+
879882
if (!is_livepatch_module(patch->mod)) {
880883
pr_err("module %s is not marked as a livepatch module",
881884
patch->mod->name);
@@ -885,9 +888,6 @@ int klp_register_patch(struct klp_patch *patch)
885888
if (!klp_initialized())
886889
return -ENODEV;
887890

888-
if (!patch || !patch->mod)
889-
return -EINVAL;
890-
891891
/*
892892
* A reference is taken on the patch module to prevent it from being
893893
* unloaded. Right now, we don't allow patch modules to unload since

0 commit comments

Comments
 (0)