module: Introduce module unload taint tracking
v2 cover module: Introduce module unload taint tracking
Hi Luis,
This is based on the latest mcgrof/modules-next branch. I have decided still to use RCU even though no entry is ever removed from the unloaded tainted modules list. That being said, if I understand correctly, it is not safe in some instances to use 'module_mutex' in print_modules(). So instead we disable preemption to ensure list traversal with concurrent list manipulation e.g. list_add_rcu(), is safe too.
Please let me know your thoughts.
Aaron Tomlin (2):
module: Make module_flags_taint() accept a module's taints bitmap
directly
module: Introduce module unload taint tracking
init/Kconfig | 11 +++++++ kernel/module/main.c | 76 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 83 insertions(+), 4 deletions(-)
base-commit: eeaec7801c421e17edda6e45a32d4a5596b633da
Signature · 1 line
2.34.1
RFC PATCH v2 1/2 module: Make module_flags_taint() accept a module's taints bitmap directly
No functional change.
The purpose of this patch is to modify module_flags_taint() to accept a module's taints bitmap as a parameter and modifies all users accordingly. This is in preparation for module unload taint tracking support.
--- kernel/module/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/module/main.c +4 -4
@@ -890,13 +890,13 @@ static inline int module_unload_init(struct module *mod) }#endif /* CONFIG_MODULE_UNLOAD */ -static size_t module_flags_taint (struct module *mod,char *buf) +static size_t module_flags_taint (unsigned long taints,char *buf) {size_t l =0 ;int i;for (i =0 ; i <TAINT_FLAGS_COUNT ; i++) { -if (taint_flags[i].module &&test_bit (i, &mod->taints)) +if (taint_flags[i].module &&test_bit (i, &taints)) buf[l++] = taint_flags[i].c_true; }
@@ -974,7 +974,7 @@ static ssize_t show_taint(struct module_attribute *mattr, {size_t l; - l =module_flags_taint (mk->mod, buffer); + l =module_flags_taint (mk->mod->taints, buffer); buffer[l++] ='\n' ;return l; }
@@ -2993,7 +2993,7 @@ char *module_flags(struct module *mod, char *buf) mod->state == MODULE_STATE_GOING || mod->state == MODULE_STATE_COMING) { buf[bx++] ='(' ; - bx +=module_flags_taint (mod, buf + bx); + bx +=module_flags_taint (mod->taints, buf + bx);/* Show a - for module-is-being-unloaded */ if (mod->state ==MODULE_STATE_GOING ) buf[bx++] ='-' ;
Signature · 1 line
2.34.1
RFC PATCH v2 2/2 module: Introduce module unload taint tracking
In reply to Aaron TomlinCurrently, only the initial module that tainted the kernel is recorded e.g. when an out-of-tree module is loaded.
The purpose of this patch is to allow the kernel to maintain a record of each unloaded module that taints the kernel. So, in addition to displaying a list of linked modules (see print_modules()) e.g. in the event of a detected bad page, unloaded modules that carried a taint/or taints are displayed too. If a previously unloaded module with a taint/or tains is loaded once again and then a count will be shown accordingly.
The number of tracked modules is not fixed. This feature is disabled by default.
--- init/Kconfig | 11 +++++++ kernel/module/main.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+)
init/Kconfig +11 -0
@@ -2118,6 +2118,17 @@ config MODULE_FORCE_UNLOAD rmmod). This is mainly for kernel developers and desperate users. If unsure, say N. +config MODULE_UNLOAD_TAINT_TRACKING + bool "Tainted module unload tracking" + depends on MODULE_UNLOAD + default n + help + This option allows you to maintain a record of each unloaded + module that tainted the kernel. In addition to displaying a + list of linked (or loaded) modules e.g. on detection of a bad + page (see bad_page()), the aforementioned details are also + shown. If unsure, say N. + config MODVERSIONS bool "Module versioning support" help
kernel/module/main.c +68 -0
98 lines not on this page · raw message
Signature · 1 line
2.34.1