livepatch: Enforce reliable stack trace as config dependency
PATCH 1/1 livepatch: Enforce reliable stack trace as config dependency
While the consistency model was introduced, architectures without the reliable stack trace implementation could use the immediate flag for livepatching but with its own limitations.
After removal of the immediate flag by commit d0807da78e11 ("livepatch: Remove immediate feature"), reliable stack trace became enforcing dependency for livepatch support on any architecture. In the current code, we ensure that the dependency is met when enabling the patch during the module load.
This dependency check can be improved by moving it to the Kconfig, which disables the support for livepatching in the kernel for unmet dependencies. This patch moves both HAVE_RELIABLE_STACKTRACE and STACKTRACE under config LIVEPATCH, it also removes the klp_have_reliable_stack() function.
Loading a livepatching module on an architecture where reliable stack trace is yet to be implemented, the user should see:
insmod: ERROR: could not insert module ./livepatch-sample.ko: Invalid module format
...
[ 286.453463] livepatch_sample: module is marked as livepatch module, but livepatch support is disabled
[[email protected]: Suggested to explicitly add CONFIG_STACKTRACE under
config LIVEPATCH]
---
Patch is based on a087cdd4073b (origin/for-5.1/atomic-replace) branch
include/linux/livepatch.h | 6 ------ kernel/livepatch/Kconfig | 2 ++ kernel/livepatch/core.c | 6 ------ 3 files changed, 2 insertions(+), 12 deletions(-)
include/linux/livepatch.h +0 -6
@@ -214,12 +214,6 @@ static inline bool klp_patch_pending(struct task_struct *task)return test_tsk_thread_flag (task,TIF_PATCH_PENDING ); } -static inline bool klp_have_reliable_stack (void ) -{ -return IS_ENABLED (CONFIG_STACKTRACE ) && -IS_ENABLED (CONFIG_HAVE_RELIABLE_STACKTRACE ); -} -typedef int (*klp_shadow_ctor_t )(void *obj,void *shadow_data,void *ctor_data);
kernel/livepatch/Kconfig +2 -0
@@ -10,6 +10,8 @@ config LIVEPATCH depends on SYSFS depends on KALLSYMS_ALL depends on HAVE_LIVEPATCH + depends on STACKTRACE + depends on HAVE_RELIABLE_STACKTRACE depends on !TRIM_UNUSED_KSYMS help Say Y here if you want to support kernel live patching.
kernel/livepatch/core.c +0 -6
@@ -1034,12 +1034,6 @@ int klp_enable_patch(struct klp_patch *patch)if (!klp_initialized ())return -ENODEV ; -if (!klp_have_reliable_stack ()) { -pr_err ("This architecture doesn't have support for the livepatch consistency model.\n" ); -return -EOPNOTSUPP ; - } - -mutex_lock (&klp_mutex); ret =klp_init_patch_early (patch);
Signature · 1 line
2.20.1
Quoted 19 lines · Kamalesh Babulal
While the consistency model was introduced, architectures without the reliable stack trace implementation could use the immediate flag for livepatching but with its own limitations.
After removal of the immediate flag by commit
d0807da78e11("livepatch: Remove immediate feature"), reliable stack trace became enforcing dependency for livepatch support on any architecture. In the current code, we ensure that the dependency is met when enabling the patch during the module load.This dependency check can be improved by moving it to the
Kconfig, which disables the support for livepatching in the kernel for unmet dependencies. This patch moves bothHAVE_RELIABLE_STACKTRACEand STACKTRACE under config LIVEPATCH, it also removes theklp_have_reliable_stack()function.Loading a livepatching module on an architecture where reliable stack trace is yet to be implemented, the user should see:
Quoted 8 lines
insmod: ERROR: could not insert module ./livepatch-sample.ko: Invalid module format
...
[ 286.453463] livepatch_sample: module is marked as livepatch module, but livepatch support is disabled[[email protected]: Suggested to explicitly add
CONFIG_STACKTRACEunder
config LIVEPATCH]Signed-off-by Kamalesh Babulal <[email protected]>
Best Regards,
Petr
Quoted 16 lines · Kamalesh Babulal
While the consistency model was introduced, architectures without the reliable stack trace implementation could use the immediate flag for livepatching but with its own limitations.
After removal of the immediate flag by commit
d0807da78e11("livepatch: Remove immediate feature"), reliable stack trace became enforcing dependency for livepatch support on any architecture. In the current code, we ensure that the dependency is met when enabling the patch during the module load.This dependency check can be improved by moving it to the
Kconfig, which disables the support for livepatching in the kernel for unmet dependencies. This patch moves bothHAVE_RELIABLE_STACKTRACEand STACKTRACE under config LIVEPATCH, it also removes theklp_have_reliable_stack()function.
Quoted 7 lines
Loading a livepatching module on an architecture where reliable stack trace is yet to be implemented, the user should see:
insmod: ERROR: could not insert module ./livepatch-sample.ko: Invalid module format
...
[ 286.453463] livepatch_sample: module is marked as livepatch module, but livepatch support is disabled
Wouldn't the module fail to build in the first place, since CONFIG_LIVEPATCH is disabled?
Anyway, I'm not sure about this approach. This patch makes the s390 livepatch code no longer compilable, turning it into completely dead code. So if something changes in the s390 code which causes it to stop compiling, nobody will notice.
I think I'd rather go in the opposite direction: allow the patches to be loaded. Then they can be forced, if needed. That enables both compile and runtime testing. That way we don't make any backward progress, until such arches get reliable stacktraces.
Signature · 1 line
Josh
Quoted 16 lines · Josh Poimboeuf
Quoted 15 lines · Kamalesh Babulal
After removal of the immediate flag by commit
d0807da78e11("livepatch: Remove immediate feature"), reliable stack trace became enforcing dependency for livepatch support on any architecture. In the current code, we ensure that the dependency is met when enabling the patch during the module load.This dependency check can be improved by moving it to the
Kconfig, which disables the support for livepatching in the kernel for unmet dependencies. This patch moves bothHAVE_RELIABLE_STACKTRACEand STACKTRACE under config LIVEPATCH, it also removes theklp_have_reliable_stack()function.Loading a livepatching module on an architecture where reliable stack trace is yet to be implemented, the user should see:
Quoted 7 lines
Quoted 4 lines
insmod: ERROR: could not insert module ./livepatch-sample.ko: Invalid module format
...
[ 286.453463] livepatch_sample: module is marked as livepatch module, but livepatch support is disabledWouldn't the module fail to build in the first place, since
CONFIG_LIVEPATCHis disabled?
Yes, with this patch applied, the livepatch modules will fail to build. The intention was to paste the output of a module load, marked as the livepatch but without the reliable stack trace support. I used the previously compiled livepatch sample module for the illustration but yeah we would not have a functioning module build in the first place.
Quoted 5 lines
Anyway, I'm not sure about this approach. This patch makes the s390 livepatch code no longer compilable, turning it into completely dead code. So if something changes in the s390 code which causes it to stop compiling, nobody will notice.
Fair point, we can drop this patch in favor of getting compile time testing for s390.
Quoted 5 lines
I think I'd rather go in the opposite direction: allow the patches to be loaded. Then they can be forced, if needed. That enables both compile and runtime testing. That way we don't make any backward progress, until such arches get reliable stacktraces.
klp_have_reliable_stack() enforces implementation of reliable stack trace and run time testing will not be complete with we returning after the check. We can re-think about enforcing the dependency after we have the reliable stack trace for s390.
Signature · 1 line
Kamalesh
Petr Mladek
maintainerQuoted 4 lines · Josh Poimboeuf
Anyway, I'm not sure about this approach. This patch makes the s390 livepatch code no longer compilable, turning it into completely dead code. So if something changes in the s390 code which causes it to stop compiling, nobody will notice.
Good point. Well, it is only small win when a code is buildable but it could not get really used. Also the amount of arch-specific code is really minimal.
Quoted 4 lines
I think I'd rather go in the opposite direction: allow the patches to be loaded. Then they can be forced, if needed. That enables both compile and runtime testing. That way we don't make any backward progress, until such arches get reliable stacktraces.
Do you mean to convert the error into warning?
For example, the change below. Note that I did not mention the possibility to force the transition by intention. It is risky and people should not get used to it.
Heh, I think that this was the main reason why it was the error. We did not want to get people used to forcing livepatches.
kernel/livepatch/core.c +2 -3
@@ -1035,11 +1035,10 @@ int klp_enable_patch(struct klp_patch *patch)return -ENODEV ;if (!klp_have_reliable_stack ()) { -pr_err ("This architecture doesn't have support for the livepatch consistency model.\n" ); -return -EOPNOTSUPP ; +pr_warn ("This architecture doesn't have support for the livepatch consistency model.\n" ); +pr_warn ("Only one livepatch can be installed.\n" ); } -mutex_lock (&klp_mutex); ret =klp_init_patch_early (patch);
Best Regards,
Petr
Quoted 20 lines · Petr Mladek
Quoted 4 lines
I think I'd rather go in the opposite direction: allow the patches to be loaded. Then they can be forced, if needed. That enables both compile and runtime testing. That way we don't make any backward progress, until such arches get reliable stacktraces.
Do you mean to convert the error into warning?
For example, the change below. Note that I did not mention the possibility to force the transition by intention. It is risky and people should not get used to it.
Heh, I think that this was the main reason why it was the error. We did not want to get people used to forcing livepatches.
kernel/livepatch/core.c +0
-0
kernel/livepatch/core.c int klp_enable_patch(struct klp_patch *patch) · line 1042
Quoted 10 lines
kernel/livepatch/core.c +2
-3@@ -1035,11 +1035,10 @@ int klp_enable_patch(struct klp_patch *patch)return -ENODEV ;if (!klp_have_reliable_stack ()) { -pr_err ("This architecture doesn't have support for the livepatch consistency model.\n" ); -return -EOPNOTSUPP ; +pr_warn ("This architecture doesn't have support for the livepatch consistency model.\n" ); +pr_warn ("Only one livepatch can be installed.\n" ); } -
This seems to have been lost.
I think we should take this aproach before Miroslav is ready with realiable stack traces for s390. At the same time, I'd suggest issuing a proper WARN() there instead of just pr_warn(). The kernel might be in a potentially funky state, so let's at least get the 'W' taint in place.
Signature · 2 lines
Jiri Kosina SUSE Labs
Quoted 24 lines · Jiri Kosina
Quoted 24 lines
Do you mean to convert the error into warning?
For example, the change below. Note that I did not mention the possibility to force the transition by intention. It is risky and people should not get used to it.
Heh, I think that this was the main reason why it was the error. We did not want to get people used to forcing livepatches.
kernel/livepatch/core.c +2
-2@@ -1035,11 +1035,10 @@ int klp_enable_patch(struct klp_patch *patch)return -ENODEV ;if (!klp_have_reliable_stack ()) { -pr_err ("This architecture doesn't have support for the livepatch consistency model.\n" ); -return -EOPNOTSUPP ; +pr_warn ("This architecture doesn't have support for the livepatch consistency model.\n" ); +pr_warn ("Only one livepatch can be installed.\n" ); }
Quoted 8 lines
kernel/livepatch/core.c int klp_enable_patch(struct klp_patch *patch) · line 1042
Quoted 1 line
kernel/livepatch/core.c +0
-1-This seems to have been lost.
I think we should take this aproach before Miroslav is ready with realiable stack traces for s390. At the same time, I'd suggest issuing a proper
WARN()there instead of justpr_warn(). The kernel might be in a potentially funky state, so let's at least get the 'W' taint in place.
Ignore the above, there is nothing wrong with the kernel unless the patch is forced.
So we should be good taking it as-is. Petr, could you please send it with proper changelog and signoff? Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Quoted 31 lines · Jiri Kosina
Quoted 29 lines · Petr Mladek
Quoted 4 lines
I think I'd rather go in the opposite direction: allow the patches to be loaded. Then they can be forced, if needed. That enables both compile and runtime testing. That way we don't make any backward progress, until such arches get reliable stacktraces.
Do you mean to convert the error into warning?
For example, the change below. Note that I did not mention the possibility to force the transition by intention. It is risky and people should not get used to it.
Heh, I think that this was the main reason why it was the error. We did not want to get people used to forcing livepatches.
kernel/livepatch/core.c +2
-2@@ -1035,11 +1035,10 @@ int klp_enable_patch(struct klp_patch *patch)return -ENODEV ;if (!klp_have_reliable_stack ()) { -pr_err ("This architecture doesn't have support for the livepatch consistency model.\n" ); -return -EOPNOTSUPP ; +pr_warn ("This architecture doesn't have support for the livepatch consistency model.\n" ); +pr_warn ("Only one livepatch can be installed.\n" ); }
Quoted 3 lines
kernel/livepatch/core.c int klp_enable_patch(struct klp_patch *patch) · line 1042
Quoted 1 line
kernel/livepatch/core.c +0
-1-This seems to have been lost.
Sorry, this must have gotten lost in my inbox - yes, something like the above is what I had in mind. Though instead of "one livepatch can be installed" it might say that the patch transition may never complete.
BTW, might we want to consider adding a way to say "this patch doesn't need the consistency model", which just applies the patch immediately like we used to? Like patch->simple = true? Then we could easily support all arches for basic patches.
Quoted 4 lines
I think we should take this aproach before Miroslav is ready with realiable stack traces for s390. At the same time, I'd suggest issuing a proper
WARN()there instead of justpr_warn(). The kernel might be in a potentially funky state, so let's at least get the 'W' taint in place.
I don't think it would be in a dangerous state, because save_stack_trace_tsk_reliable() will return -ENOSYS and the patch will remain in transition forever because the signaling doesn't work for kthreads. So I don't think a warning is necessary. In fact we may want to remove the warning in the generic version of save_stack_trace_tsk_reliable().
Signature · 1 line
Josh
Miroslav Benes
maintainerQuoted 32 lines · Josh Poimboeuf
Quoted 31 lines · Jiri Kosina
Quoted 29 lines · Petr Mladek
Quoted 4 lines
I think I'd rather go in the opposite direction: allow the patches to be loaded. Then they can be forced, if needed. That enables both compile and runtime testing. That way we don't make any backward progress, until such arches get reliable stacktraces.
Do you mean to convert the error into warning?
For example, the change below. Note that I did not mention the possibility to force the transition by intention. It is risky and people should not get used to it.
Heh, I think that this was the main reason why it was the error. We did not want to get people used to forcing livepatches.
kernel/livepatch/core.c +2
-2@@ -1035,11 +1035,10 @@ int klp_enable_patch(struct klp_patch *patch)return -ENODEV ;if (!klp_have_reliable_stack ()) { -pr_err ("This architecture doesn't have support for the livepatch consistency model.\n" ); -return -EOPNOTSUPP ; +pr_warn ("This architecture doesn't have support for the livepatch consistency model.\n" ); +pr_warn ("Only one livepatch can be installed.\n" ); }
Quoted 7 lines
Quoted 3 lines
kernel/livepatch/core.c int klp_enable_patch(struct klp_patch *patch) · line 1042
Quoted 1 line
kernel/livepatch/core.c +0
-1-This seems to have been lost.
Sorry, this must have gotten lost in my inbox - yes, something like the above is what I had in mind. Though instead of "one livepatch can be installed" it might say that the patch transition may never complete.
Sounds better to me too.
Quoted 4 lines
BTW, might we want to consider adding a way to say "this patch doesn't need the consistency model", which just applies the patch immediately like we used to? Like
patch->simple= true? Then we could easily support all arches for basic patches.
I'd rather not return to immediate. There was a bug (commit d0807da78e11 ("livepatch: Remove immediate feature") explains it), it made the code complicated and it was impossible to disable patches/remove modules with that. After all, the consistency model gives us not only the consistency, but also assurance that all tasks were migrated outside of patched functions.
Quoted 11 lines
Quoted 4 lines
I think we should take this aproach before Miroslav is ready with realiable stack traces for s390. At the same time, I'd suggest issuing a proper
WARN()there instead of justpr_warn(). The kernel might be in a potentially funky state, so let's at least get the 'W' taint in place.I don't think it would be in a dangerous state, because
save_stack_trace_tsk_reliable()will return-ENOSYSand the patch will remain in transition forever because the signaling doesn't work for kthreads. So I don't think a warning is necessary. In fact we may want to remove the warning in the generic version ofsave_stack_trace_tsk_reliable().
I would not mind.
Miroslav