From e6a47cb429acef6470dd382934bb2a2942d76458 Mon Sep 17 00:00:00 2001 From: Zhao Xuehui Date: Fri, 14 May 2021 15:55:35 +0800 Subject: [PATCH] livepatch/x86_64: Fix the deadlock when insmoding livepatch kernel module hulk inclusion category: bugfix bugzilla: 51843 CVE: NA --------------------------- In function klp_init_patch, a text_mutex lock is used when doing jump_label_apply_nops. However, the jump_label_register in which a text_mutex lock is used is done before the original text_mutex lock released. Thus, an AA deadlock is occured. In this commit, we do jump_label_register after the original text_mutex lock is released to avoid this AA deadlock. Signed-off-by: Zhao Xuehui Reviewed-by: Kuohai Xu Signed-off-by: Yang Yingliang --- kernel/livepatch/core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 4cbe7ebfcf7f..2c4aed29a298 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -1207,14 +1207,12 @@ static int klp_init_patch(struct klp_patch *patch) mutex_lock(&text_mutex); module_disable_ro(patch->mod); jump_label_apply_nops(patch->mod); + module_enable_ro(patch->mod, true); + mutex_unlock(&text_mutex); ret = jump_label_register(patch->mod); if (ret) { - module_enable_ro(patch->mod, true); - mutex_unlock(&text_mutex); goto free; } - module_enable_ro(patch->mod, true); - mutex_unlock(&text_mutex); #ifdef CONFIG_LIVEPATCH_WO_FTRACE klp_for_each_object(patch, obj) -- GitLab