From da821c827a0f6f2268357936fa9971c298fc66c3 Mon Sep 17 00:00:00 2001 From: Mukesh Ojha Date: Fri, 22 Jun 2018 16:59:47 +0530 Subject: [PATCH 1/2] 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 themselves. 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 Signed-off-by: Neeraj Upadhyay --- kernel/module.c | 4 ++++ lib/Kconfig.debug | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/kernel/module.c b/kernel/module.c index 2a4ff2960cbd..28d49f3841e9 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2238,6 +2238,10 @@ static void free_module(struct module *mod) /* Free lock-classes; relies on the preceding sync_rcu(). */ lockdep_free_key_range(mod->core_layout.base, mod->core_layout.size); +#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 /* Finally, free the core (containing the module structure) */ module_memfree(mod->core_layout.base); } diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 60807fadf343..e7709a057672 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -186,6 +186,18 @@ config DYNAMIC_DEBUG_CORE the case of embedded system where the kernel image size is sensitive for people. +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" From 6ddf9b8520bcce54221581ea9791170581846ff3 Mon Sep 17 00:00:00 2001 From: Mukesh Ojha Date: Thu, 13 Aug 2020 17:11:21 +0530 Subject: [PATCH 2/2] defconfig: msm: Enable debug module info config for Lahaina/Shima Enable config to print information about module (un)loading for Lahaina/Shima SoC. Change-Id: I2fb3bc47fd550b26c693fdc76cb6eba05db4ce60 Signed-off-by: Mukesh Ojha --- arch/arm64/configs/vendor/lahaina_consolidate.config | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/vendor/lahaina_consolidate.config b/arch/arm64/configs/vendor/lahaina_consolidate.config index 81774c4ac977..a00789d82639 100644 --- a/arch/arm64/configs/vendor/lahaina_consolidate.config +++ b/arch/arm64/configs/vendor/lahaina_consolidate.config @@ -47,3 +47,4 @@ CONFIG_USB_F_FS_IPC_LOGGING=y CONFIG_DYNAMIC_DEBUG=y CONFIG_QTI_PMIC_GLINK_CLIENT_DEBUG=y # CONFIG_HH_DISABLE_UART is not set +CONFIG_DEBUG_MODULE_LOAD_INFO=y