Skip to contentSkip to conversation

livepatch: Cancel transition a safe way for immediate patches

PATCH In review Petr Mladek 4 participants 4 messages Apr 11, 2017 Live patching

lore
Share & tools
lore

Petr Mladek

author maintainer
#0 lore raw

PATCH 1/1 livepatch: Cancel transition a safe way for immediate patches

klp_init_transition() does not set func->transition for immediate patches. Then klp_ftrace_handler() could use the new code immediately. As a result, it is not safe to put the livepatch module in klp_cancel_transition().

This patch reverts most of the last minute changes klp_cancel_transition(). It keeps the warning about a misuse because it still makes sense.

---
Hi,

I am afraid that Mirek was not right in the mail
https://lkml.kernel.org/r/[email protected]
IMHO, it is not safe to put the module when the immediate patch cannot be applied.

Best Regards,
Petr

 kernel/livepatch/transition.c | 20 --------------------
 1 file changed, 20 deletions(-)
kernel/livepatch/transition.c +0 -20
index 2de09e0c4e5c..adc0cc64aa4b 100644
@@ -120,31 +120,11 @@ static void klp_complete_transition(void)
  */
 void klp_cancel_transition(void)
 {
-	struct klp_patch *patch = klp_transition_patch;
-	struct klp_object *obj;
-	struct klp_func *func;
-	bool immediate_func = false;
-
 	if (WARN_ON_ONCE(klp_target_state != KLP_PATCHED))
 		return;
 
 	klp_target_state = KLP_UNPATCHED;
 	klp_complete_transition();
-
-	/*
-	 * In the enable error path, even immediate patches can be safely
-	 * removed because the transition hasn't been started yet.
-	 *
-	 * klp_complete_transition() doesn't have a module_put() for immediate
-	 * patches, so do it here.
-	 */
-	klp_for_each_object(patch, obj)
-		klp_for_each_func(obj, func)
-			if (func->immediate)
-				immediate_func = true;
-
-	if (patch->immediate || immediate_func)
-		module_put(patch->mod);
 }
 
 /*
Signature · 1 line
1.8.5.6
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Petr Mladek

klp_init_transition() does not set func->transition for immediate patches. Then klp_ftrace_handler() could use the new code immediately. As a result, it is not safe to put the livepatch module in klp_cancel_transition().

This patch reverts most of the last minute changes klp_cancel_transition(). It keeps the warning about a misuse because it still makes sense.

---
Hi,

Quoted 7 lines

I am afraid that Mirek was not right in the mail
https://lkml.kernel.org/r/[email protected]
IMHO, it is not safe to put the module when the immediate patch cannot be applied.

Best Regards,
Petr

You're right, Petr. Thanks for fixing my fault.

If needed, we could still follow the idea - set func->transition even for immediate patches/funcs. But for now, removing the code is the best.

Jiri, this (obviously) needs to go to 4.12 with the patch set...

Miroslav

Quoted 42 lines
 kernel/livepatch/transition.c | 20 --------------------
 1 file changed, 20 deletions(-)
kernel/livepatch/transition.c +0 -20
index 2de09e0c4e5c..adc0cc64aa4b 100644
@@ -120,31 +120,11 @@ static void klp_complete_transition(void)
  */
 void klp_cancel_transition(void)
 {
-	struct klp_patch *patch = klp_transition_patch;
-	struct klp_object *obj;
-	struct klp_func *func;
-	bool immediate_func = false;
-
 	if (WARN_ON_ONCE(klp_target_state != KLP_PATCHED))
 		return;
 
 	klp_target_state = KLP_UNPATCHED;
 	klp_complete_transition();
-
-	/*
-	 * In the enable error path, even immediate patches can be safely
-	 * removed because the transition hasn't been started yet.
-	 *
-	 * klp_complete_transition() doesn't have a module_put() for immediate
-	 * patches, so do it here.
-	 */
-	klp_for_each_object(patch, obj)
-		klp_for_each_func(obj, func)
-			if (func->immediate)
-				immediate_func = true;
-
-	if (patch->immediate || immediate_func)
-		module_put(patch->mod);
 }
 
 /*
Signature · 1 line
1.8.5.6
Acked-by on v1 1/1
#2 lore raw
In reply to Petr Mladek
Quoted 8 lines · Petr Mladek

klp_init_transition() does not set func->transition for immediate patches. Then klp_ftrace_handler() could use the new code immediately. As a result, it is not safe to put the livepatch module in klp_cancel_transition().

This patch reverts most of the last minute changes klp_cancel_transition(). It keeps the warning about a misuse because it still makes sense.

Good catch Petr, thanks!

Fixes 3ec24776bfd0 ("livepatch: allow removal of a disabled patch")
Signature · 1 line
Josh
#3 lore raw
In reply to Petr Mladek
Quoted 7 lines · Petr Mladek

klp_init_transition() does not set func->transition for immediate patches. Then klp_ftrace_handler() could use the new code immediately. As a result, it is not safe to put the livepatch module in klp_cancel_transition().

This patch reverts most of the last minute changes klp_cancel_transition(). It keeps the warning about a misuse because it still makes sense.

Quoted 8 lines

---
Hi,

I am afraid that Mirek was not right in the mail
https://lkml.kernel.org/r/[email protected]
IMHO, it is not safe to put the module when the immediate patch cannot be applied.

That's a very good catch indeed, thanks. Applied.

Signature · 2 lines
Jiri Kosina
SUSE Labs