Talk about how Linux kernel invokes your module's init function.
Note: When you view the the slide deck via web browser, the screenshots may be blurred. You can download and view them offline (Screenshots are clear).
Agenda
• From ‘insmod’command
• Call path for LKM’s init function
• ‘.gnu.linkonce.this_module’ section
• Deep Dive into call path
• modinfo
Note
• Kernel source: 5.10
• Mainly focus on the ‘init’ function call path
3.
From `insmod` command
HelloWorld Kernel Module strace
finit_module() system call loads an ELF image into kernel space
4.
From `insmod` command
HelloWorld Kernel Module strace
finit_module() system call loads an ELF image into kernel space
finit_module()
• Load an ELF image into kernel space
• Perform symbol relocations
• Initialize module parameters to values
• Run the module’s init function
5.
Call path forLKM’s init function
finit_module
load_module
do_init_module
do_one_initcall(mod->init)
mod->init();
Analysis
• Key: mod->init()
• How to assign the address of mod->init()?
kernel_read_file_from_fd
elf_header_check
setup_load_info
blacklisted(info->name)?
cleanup & return
module_sig_check
Y
N
mod = layout_and_allocate(info, ..)
rewrite_section_headers
apply_relocations