hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8MGE6
--------------------------------
When the thread become zombie or dead, it's stack memory may have been freed, so ignore it.
Signed-off-by: Zheng Yejian zhengyejian1@huawei.com --- arch/arm/kernel/livepatch.c | 2 ++ arch/arm64/kernel/livepatch.c | 2 ++ arch/powerpc/kernel/livepatch.c | 2 ++ arch/x86/kernel/livepatch.c | 2 ++ include/linux/livepatch.h | 12 ++++++++++++ 5 files changed, 20 insertions(+)
diff --git a/arch/arm/kernel/livepatch.c b/arch/arm/kernel/livepatch.c index cf3cf73cea5c..365b476709fc 100644 --- a/arch/arm/kernel/livepatch.c +++ b/arch/arm/kernel/livepatch.c @@ -119,6 +119,8 @@ static int do_check_calltrace(struct walk_stackframe_args *args, for_each_process_thread(g, t) { if (klp_is_migration_thread(t->comm)) continue; + if (klp_is_thread_dead(t)) + continue; ret = check_task_calltrace(t, args, fn); if (ret) return ret; diff --git a/arch/arm64/kernel/livepatch.c b/arch/arm64/kernel/livepatch.c index 829c7f376ec6..1e47a66b2f2b 100644 --- a/arch/arm64/kernel/livepatch.c +++ b/arch/arm64/kernel/livepatch.c @@ -97,6 +97,8 @@ static int do_check_calltrace(struct walk_stackframe_args *args, for_each_process_thread(g, t) { if (klp_is_migration_thread(t->comm)) continue; + if (klp_is_thread_dead(t)) + continue; ret = check_task_calltrace(t, args, fn); if (ret) return ret; diff --git a/arch/powerpc/kernel/livepatch.c b/arch/powerpc/kernel/livepatch.c index 3d680b5d6d09..09b405740cb5 100644 --- a/arch/powerpc/kernel/livepatch.c +++ b/arch/powerpc/kernel/livepatch.c @@ -214,6 +214,8 @@ static int do_check_calltrace(struct walk_stackframe_args *args, for_each_process_thread(g, t) { if (klp_is_migration_thread(t->comm)) continue; + if (klp_is_thread_dead(t)) + continue; ret = check_task_calltrace(t, args, fn); if (ret) return ret; diff --git a/arch/x86/kernel/livepatch.c b/arch/x86/kernel/livepatch.c index 660c25f2cf89..f560f8b8b1a8 100644 --- a/arch/x86/kernel/livepatch.c +++ b/arch/x86/kernel/livepatch.c @@ -184,6 +184,8 @@ static int do_check_calltrace(bool (*fn)(void *, int *, unsigned long), void *da for_each_process_thread(g, t) { if (klp_is_migration_thread(t->comm)) continue; + if (klp_is_thread_dead(t)) + continue;
ret = check_task_calltrace(t, fn, data); if (ret) diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h index 3388a611f388..9e0915201268 100644 --- a/include/linux/livepatch.h +++ b/include/linux/livepatch.h @@ -315,6 +315,18 @@ static inline bool klp_is_migration_thread(const char *task_name) sizeof(KLP_MIGRATION_NAME_PREFIX) - 1); }
+/* + * When the thread become zombie or dead, it's stack memory may have + * been freed, we can not check calltrace for it. + */ +static inline bool klp_is_thread_dead(const struct task_struct *t) +{ + int exit_state = READ_ONCE(t->exit_state); + + return ((exit_state & EXIT_ZOMBIE) == EXIT_ZOMBIE) || + ((exit_state & EXIT_DEAD) == EXIT_DEAD); +} + int klp_register_patch(struct klp_patch *patch); int klp_unregister_patch(struct klp_patch *patch); static inline int klp_module_coming(struct module *mod) { return 0; }