Skip to content

Commit

Permalink
livepatch: robustify klp_register_patch() API error checking
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Josh Poimboeuf <[email protected]>
Acked-by: Jessica Yu <[email protected]>
Signed-off-by: Jiri Kosina <[email protected]>
  • Loading branch information
Jiri Kosina committed Apr 7, 2016
1 parent 3b812ec commit 61bf12d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions kernel/livepatch/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 61bf12d

Please sign in to comment.