提交 1a874243 编写于 作者: Y Ye Weihua 提交者: Yang Yingliang

livepatch: Fix crash when access the global variable in hook

hulk inclusion
category: bugfix
bugzilla: 175623
CVE: NA

---------------------------

Livepatch allows users to call hook functions to perform some customized
operations when insmod the .ko. During the test, it is found that in the
ARM64 architecture, if accesses the global variables defined by other ko in
hook functions, a crash occurs.

Since relocation is performed during the livepatch insertion, instructions
in the icache should be invalid. If the instructions in the icache are
directly obtained, incorrect addresses may be obtained, caseing crash.
Therefore, flush the icache before calling the hook functions.
Signed-off-by: NYe Weihua <yeweihua4@huawei.com>
Reviewed-by: NJian Cheng <cj.chengjian@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 a23c8f5f
...@@ -86,6 +86,8 @@ void module_arch_cleanup(struct module *mod); ...@@ -86,6 +86,8 @@ void module_arch_cleanup(struct module *mod);
/* Any cleanup before freeing mod->module_init */ /* Any cleanup before freeing mod->module_init */
void module_arch_freeing_init(struct module *mod); void module_arch_freeing_init(struct module *mod);
void flush_module_icache(const struct module *mod);
#ifdef CONFIG_KASAN #ifdef CONFIG_KASAN
#include <linux/kasan.h> #include <linux/kasan.h>
#define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
......
...@@ -1062,6 +1062,7 @@ static int klp_init_object_loaded(struct klp_patch *patch, ...@@ -1062,6 +1062,7 @@ static int klp_init_object_loaded(struct klp_patch *patch,
} }
arch_klp_init_object_loaded(patch, obj); arch_klp_init_object_loaded(patch, obj);
flush_module_icache(patch->mod);
module_enable_ro(patch->mod, true); module_enable_ro(patch->mod, true);
mutex_unlock(&text_mutex); mutex_unlock(&text_mutex);
......
...@@ -3302,7 +3302,7 @@ static int check_module_license_and_versions(struct module *mod) ...@@ -3302,7 +3302,7 @@ static int check_module_license_and_versions(struct module *mod)
return 0; return 0;
} }
static void flush_module_icache(const struct module *mod) void flush_module_icache(const struct module *mod)
{ {
mm_segment_t old_fs; mm_segment_t old_fs;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册