Commit e3350aa0 authored by Zheng Yejian's avatar Zheng Yejian
Browse files

livepatch: Bypass dead thread when check calltrace

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: default avatarZheng Yejian <zhengyejian1@huawei.com>
parent 7a3d8e41
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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;
+2 −0
Original line number Diff line number Diff line
@@ -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;
+2 −0
Original line number Diff line number Diff line
@@ -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;
+2 −0
Original line number Diff line number Diff line
@@ -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)
+12 −0
Original line number Diff line number Diff line
@@ -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; }