Skip to content

Commit

Permalink
livepatch: enforce patch stacking semantics
Browse files Browse the repository at this point in the history
Only allow the topmost patch on the stack to be enabled or disabled, so
that patches can't be removed or added in an arbitrary order.

Suggested-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Reviewed-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Josh Poimboeuf authored and Jiri Kosina committed Jan 20, 2015
1 parent 32b7eb8 commit 83a90bb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions kernel/livepatch/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ static int __klp_disable_patch(struct klp_patch *patch)
struct klp_object *obj;
int ret;

/* enforce stacking: only the last enabled patch can be disabled */
if (!list_is_last(&patch->list, &klp_patches) &&
list_next_entry(patch, list)->state == KLP_ENABLED)
return -EBUSY;

pr_notice("disabling patch '%s'\n", patch->mod->name);

for (obj = patch->objs; obj->funcs; obj++) {
Expand Down Expand Up @@ -435,6 +440,11 @@ static int __klp_enable_patch(struct klp_patch *patch)
if (WARN_ON(patch->state != KLP_DISABLED))
return -EINVAL;

/* enforce stacking: only the first disabled patch can be enabled */
if (patch->list.prev != &klp_patches &&
list_prev_entry(patch, list)->state == KLP_DISABLED)
return -EBUSY;

pr_notice_once("tainting kernel with TAINT_LIVEPATCH\n");
add_taint(TAINT_LIVEPATCH, LOCKDEP_STILL_OK);

Expand Down

0 comments on commit 83a90bb

Please sign in to comment.