From 0bb433e0140efece0a1ce8124283cb68fda33a3f Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Tue, 13 Jul 2021 14:26:23 -0700 Subject: [PATCH] ANDROID: debug_symbols: Add android_debug_for_each_module Allow vendors to obtain a list of modules loaded at given time. Vendor modules are able to register on part of notifier chain (register_module_notifer), but a vendor module would never see modules which are loaded before the one which registers on the notifier chain. The kernel doesn't offer load order control, so a hook is necessary to iterate through currently loaded kernel modules. Bug: 193552324 Change-Id: I3b01cc1b90f8c0c7c21a37992cc7d607316efc7b Signed-off-by: Elliot Berman --- include/linux/android_debug_symbols.h | 6 ++++++ kernel/module.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/linux/android_debug_symbols.h b/include/linux/android_debug_symbols.h index c80f063ffef4..6a54e9116e3d 100644 --- a/include/linux/android_debug_symbols.h +++ b/include/linux/android_debug_symbols.h @@ -50,6 +50,9 @@ enum android_debug_per_cpu_symbol { void *android_debug_symbol(enum android_debug_symbol symbol); void *android_debug_per_cpu_symbol(enum android_debug_per_cpu_symbol symbol); +void android_debug_for_each_module(int (*fn)(const char *mod_name, void *mod_addr, void *data), + void *data); + #else /* !CONFIG_ANDROID_DEBUG_SYMBOLS */ static inline void *android_debug_symbol(enum android_debug_symbol symbol) @@ -60,6 +63,9 @@ static inline void *android_debug_per_cpu_symbol(enum android_debug_per_cpu_symb { return NULL; } + +static inline void android_debug_for_each_module(int (*fn)(const char *mod_name, void *mod_addr, + void *data), void *data) {} #endif /* CONFIG_ANDROID_DEBUG_SYMBOLS */ #endif /* _ANDROID_DEBUG_SYMBOLS_H */ diff --git a/kernel/module.c b/kernel/module.c index 26da85fcd877..c52adc976c01 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -4788,6 +4788,23 @@ void print_modules(void) pr_cont("\n"); } +#ifdef CONFIG_ANDROID_DEBUG_SYMBOLS +void android_debug_for_each_module(int (*fn)(const char *mod_name, void *mod_addr, void *data), + void *data) +{ + struct module *module; + + preempt_disable(); + list_for_each_entry_rcu(module, &modules, list) { + if (fn(module->name, module->core_layout.base, data)) + goto out; + } +out: + preempt_enable(); +} +EXPORT_SYMBOL_GPL(android_debug_for_each_module); +#endif + #ifdef CONFIG_MODVERSIONS /* Generate the signature for all relevant module structures here. * If these change, we don't want to try to parse the module. */