mirror of
https://github.com/openwall/lkrg.git
synced 2023-12-13 21:30:29 +01:00
Dynamically resolve __module_address and __module_text_address on Linux
>= 5.9
This commit is contained in:
parent
a46e7b0ae1
commit
24d7117647
5 changed files with 42 additions and 0 deletions
|
@ -65,7 +65,11 @@ int p_arch_jump_label_transform_entry(struct kretprobe_instance *p_ri, struct pt
|
|||
* OK, *_JUMP_LABEL tries to modify kernel core .text section
|
||||
*/
|
||||
p_db.p_jump_label.p_state = P_JUMP_LABEL_CORE_TEXT;
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
|
||||
} else if ( (p_module = P_SYM(p_module_text_address)(p_addr)) != NULL) {
|
||||
#else
|
||||
} else if ( (p_module = __module_text_address(p_addr)) != NULL) {
|
||||
#endif
|
||||
/*
|
||||
* OK, *_JUMP_LABEL tries to modify some module's .text section
|
||||
*/
|
||||
|
|
|
@ -115,7 +115,11 @@ int p_arch_jump_label_transform_apply_ret(struct kretprobe_instance *ri, struct
|
|||
|
||||
p_text++;
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
|
||||
} else if ( (p_module = P_SYM(p_module_text_address)(p_jl_batch_addr[p_cnt])) != NULL) {
|
||||
#else
|
||||
} else if ( (p_module = __module_text_address(p_jl_batch_addr[p_cnt])) != NULL) {
|
||||
#endif
|
||||
|
||||
for (p_tmp = 0x0; p_tmp < p_db.p_module_list_nr; p_tmp++) {
|
||||
if (p_db.p_module_list_array[p_tmp].p_mod == p_module) {
|
||||
|
|
|
@ -251,8 +251,13 @@ unsigned int p_count_modules_from_sysfs_kobj(void) {
|
|||
spin_lock(&p_kset->list_lock);
|
||||
list_for_each_entry_safe(p_kobj, p_tmp_safe, &p_kset->list, entry) {
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
|
||||
if (!P_SYM(p_module_address)((unsigned long)p_kobj))
|
||||
continue;
|
||||
#else
|
||||
if (!__module_address((unsigned long)p_kobj))
|
||||
continue;
|
||||
#endif
|
||||
|
||||
if (!p_kobj->state_initialized || !p_kobj->state_in_sysfs) {
|
||||
/* Weirdo state :( */
|
||||
|
@ -320,8 +325,13 @@ int p_list_from_sysfs_kobj(p_module_kobj_mem *p_arg) {
|
|||
spin_lock(&p_kset->list_lock);
|
||||
list_for_each_entry_safe(p_kobj, p_tmp_safe, &p_kset->list, entry) {
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
|
||||
if (!P_SYM(p_module_address)((unsigned long)p_kobj))
|
||||
continue;
|
||||
#else
|
||||
if (!__module_address((unsigned long)p_kobj))
|
||||
continue;
|
||||
#endif
|
||||
|
||||
if (!p_kobj->state_initialized || !p_kobj->state_in_sysfs) {
|
||||
/* Weirdo state :( */
|
||||
|
|
|
@ -439,6 +439,26 @@ static int __init p_lkrg_register(void) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
|
||||
P_SYM(p_module_address) = (struct module* (*)(unsigned long))P_SYM(p_kallsyms_lookup_name)("__module_address");
|
||||
|
||||
if (!P_SYM(p_module_address)) {
|
||||
p_print_log(P_LKRG_ERR,
|
||||
"ERROR: Can't find '__module_address' function :( Exiting...\n");
|
||||
p_ret = P_LKRG_GENERAL_ERROR;
|
||||
goto p_main_error;
|
||||
}
|
||||
|
||||
P_SYM(p_module_text_address) = (struct module* (*)(unsigned long))P_SYM(p_kallsyms_lookup_name)("__module_text_address");
|
||||
|
||||
if (!P_SYM(p_module_text_address)) {
|
||||
p_print_log(P_LKRG_ERR,
|
||||
"ERROR: Can't find '__module_text_address' function :( Exiting...\n");
|
||||
p_ret = P_LKRG_GENERAL_ERROR;
|
||||
goto p_main_error;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Freeze all non-kernel processes
|
||||
while (P_SYM(p_freeze_processes)())
|
||||
schedule();
|
||||
|
|
|
@ -178,6 +178,10 @@ typedef struct _p_lkrg_global_symbols_structure {
|
|||
struct kset **p_module_kset;
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0)
|
||||
void (*p_native_write_cr4)(unsigned long p_val);
|
||||
#endif
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,9,0)
|
||||
struct module* (*p_module_address)(unsigned long p_val);
|
||||
struct module* (*p_module_text_address)(unsigned long p_val);
|
||||
#endif
|
||||
int (*p_kallsyms_on_each_symbol)(int (*)(void *, const char *, struct module *, unsigned long), void *);
|
||||
struct module *p_find_me;
|
||||
|
|
Loading…
Reference in a new issue