Kconfig.debug: module: Add debug config to debug modules

There can be scenario where, dynamically loadable modules adds
a certain nodes in list data structure and forgot to remove
reference from the list while unloading themself. And this can
result in fault while accessing those dangling pointers.

So If we log the module used address ranges, we could be able to
tell exact victim module.

And, It will be good to keep these debug logs under a config flag.

So, let's add DEBUG_MODULE_LOAD_INFO config and use this in
printing module used init and core layout address
ranges.

e.g:
Core layout sections:
[   40.599573]  .text
[   40.627074]  .plt
[   40.603426]  .rodata.str1.8
[   40.608016]  __mcount_loc
[   40.622142]  .note.gnu.build-id
[   40.612654]  .data
[   40.616438]  .gnu.linkonce.this_module
[   40.634909]  .bss

Init layout sections
[   40.630781]  .init.plt
[   40.638591]  .symtab
[   40.642573]  .strtab

After this patch:
/ # rmmod sample
[   63.816318] Unloaded sample: module core layout start: 0xffffff9dbff85000 size: 0x4000

This config should not be enabled in production builds.

Change-Id: I4acfc4f53c561f92ca63fa3c4559148929575580
Signed-off-by: Mukesh Ojha <mojha@codeaurora.org>
Signed-off-by: Neeraj Upadhyay <neeraju@codeaurora.org>
This commit is contained in:
Mukesh Ojha
2018-06-22 16:59:47 +05:30
committed by Gerrit - the friendly Code Review server
parent 5219be0fd7
commit 224419de80
2 changed files with 16 additions and 0 deletions

View File

@@ -2187,6 +2187,10 @@ static void free_module(struct module *mod)
/* Finally, free the core (containing the module structure) */
disable_ro_nx(&mod->core_layout);
#ifdef CONFIG_DEBUG_MODULE_LOAD_INFO
pr_info("Unloaded %s: module core layout, start: 0x%pK size: 0x%x\n",
mod->name, mod->core_layout.base, mod->core_layout.size);
#endif
module_memfree(mod->core_layout.base);
}

View File

@@ -155,6 +155,18 @@ config DEBUG_CONSOLE_UNHASHED_POINTERS
actual pointer values, ignoring the kptr_restrict setting.
Not to be enabled on production builds.
config DEBUG_MODULE_LOAD_INFO
bool "Use prints for module info under a debug flag"
help
If you say Y here the resulting kernel image will include
debug prints which was kept under DEBUG_MODULE_LOAD_INFO.
This will be used by developer to debug loadable modules in
the kernel.
Say Y here only if you plan to debug the kernel.
Not to be enabled on production builds.
If unsure, say N.
endmenu # "printk and dmesg options"
menu "Compile-time checks and compiler options"