From 5d8591bc0fbaeb6deda6ee478577e9c4d9b10c2b Mon Sep 17 00:00:00 2001 From: Rabin Vincent Date: Fri, 6 Feb 2015 15:09:57 +1030 Subject: [PATCH 1/5] module: set ksymtab/kcrctab* section addresses to 0x0 These __ksymtab*/__kcrctab* sections currently have non-zero addresses. Non-zero section addresses in a relocatable ELF confuse GDB and it ends up not relocating all symbols when add-symbol-file is used on modules which have exports. The kernel's module loader does not care about these addresses, so let's just set them to zero. Before: $ readelf -S lib/notifier-error-inject.ko | grep 'Name\| __ksymtab_gpl' [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 8] __ksymtab_gpl PROGBITS 0000000c 0001b4 000010 00 A 0 0 4 (gdb) add-symbol-file lib/notifier-error-inject.ko 0x500000 -s .bss 0x700000 add symbol table from file "lib/notifier-error-inject.ko" at .text_addr = 0x500000 .bss_addr = 0x700000 (gdb) p ¬ifier_err_inject_dir $3 = (struct dentry **) 0x0 After: $ readelf -S lib/notifier-error-inject.ko | grep 'Name\| __ksymtab_gpl' [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 8] __ksymtab_gpl PROGBITS 00000000 0001b4 000010 00 A 0 0 4 (gdb) add-symbol-file lib/notifier-error-inject.ko 0x500000 -s .bss 0x700000 add symbol table from file "lib/notifier-error-inject.ko" at .text_addr = 0x500000 .bss_addr = 0x700000 (gdb) p ¬ifier_err_inject_dir $3 = (struct dentry **) 0x700000 Signed-off-by: Rabin Vincent Signed-off-by: Rusty Russell --- scripts/module-common.lds | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/module-common.lds b/scripts/module-common.lds index 0865b3e752be..bec15f908fc6 100644 --- a/scripts/module-common.lds +++ b/scripts/module-common.lds @@ -6,14 +6,14 @@ SECTIONS { /DISCARD/ : { *(.discard) } - __ksymtab : { *(SORT(___ksymtab+*)) } - __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) } - __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) } - __ksymtab_unused_gpl : { *(SORT(___ksymtab_unused_gpl+*)) } - __ksymtab_gpl_future : { *(SORT(___ksymtab_gpl_future+*)) } - __kcrctab : { *(SORT(___kcrctab+*)) } - __kcrctab_gpl : { *(SORT(___kcrctab_gpl+*)) } - __kcrctab_unused : { *(SORT(___kcrctab_unused+*)) } - __kcrctab_unused_gpl : { *(SORT(___kcrctab_unused_gpl+*)) } - __kcrctab_gpl_future : { *(SORT(___kcrctab_gpl_future+*)) } + __ksymtab 0 : { *(SORT(___ksymtab+*)) } + __ksymtab_gpl 0 : { *(SORT(___ksymtab_gpl+*)) } + __ksymtab_unused 0 : { *(SORT(___ksymtab_unused+*)) } + __ksymtab_unused_gpl 0 : { *(SORT(___ksymtab_unused_gpl+*)) } + __ksymtab_gpl_future 0 : { *(SORT(___ksymtab_gpl_future+*)) } + __kcrctab 0 : { *(SORT(___kcrctab+*)) } + __kcrctab_gpl 0 : { *(SORT(___kcrctab_gpl+*)) } + __kcrctab_unused 0 : { *(SORT(___kcrctab_unused+*)) } + __kcrctab_unused_gpl 0 : { *(SORT(___kcrctab_unused_gpl+*)) } + __kcrctab_gpl_future 0 : { *(SORT(___kcrctab_gpl_future+*)) } } From de96d79f343321d26ff920af25fcefe6895ca544 Mon Sep 17 00:00:00 2001 From: Andrey Tsyvarev Date: Fri, 6 Feb 2015 15:09:57 +1030 Subject: [PATCH 2/5] kernel/module.c: Free lock-classes if parse_args failed parse_args call module parameters' .set handlers, which may use locks defined in the module. So, these classes should be freed in case parse_args returns error(e.g. due to incorrect parameter passed). Signed-off-by: Andrey Tsyvarev Signed-off-by: Rusty Russell --- kernel/module.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/module.c b/kernel/module.c index d856e96a3cce..441ed3fc9c89 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -3356,6 +3356,9 @@ static int load_module(struct load_info *info, const char __user *uargs, module_bug_cleanup(mod); mutex_unlock(&module_mutex); + /* Free lock-classes: */ + lockdep_free_key_range(mod->module_core, mod->core_size); + /* we can't deallocate the module until we clear memory protection */ unset_module_init_ro_nx(mod); unset_module_core_ro_nx(mod); From ab92ebbb8e10d402f4fe73c6b3d85be72614f1fa Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 6 Feb 2015 15:09:57 +1030 Subject: [PATCH 3/5] module: Remove double spaces in module verification taint message The warning message when loading modules with a wrong signature has two spaces in it: "module verification failed: signature and/or required key missing" Signed-off-by: Marcel Holtmann Signed-off-by: Rusty Russell --- kernel/module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/module.c b/kernel/module.c index 441ed3fc9c89..2461370813b3 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -3265,7 +3265,7 @@ static int load_module(struct load_info *info, const char __user *uargs, mod->sig_ok = info->sig_ok; if (!mod->sig_ok) { pr_notice_once("%s: module verification failed: signature " - "and/or required key missing - tainting " + "and/or required key missing - tainting " "kernel\n", mod->name); add_taint_module(mod, TAINT_UNSIGNED_MODULE, LOCKDEP_STILL_OK); } From d64810f56147b53e92228c31442e925576314aa2 Mon Sep 17 00:00:00 2001 From: Peter Zijlstra Date: Wed, 11 Feb 2015 15:01:13 +1030 Subject: [PATCH 4/5] module: Annotate nested sleep in resolve_symbol() Because wait_event() loops are safe vs spurious wakeups we can allow the occasional sleep -- which ends up being very similar. Reported-by: Dave Jones Signed-off-by: Peter Zijlstra (Intel) Tested-by: Dave Jones Signed-off-by: Rusty Russell --- kernel/module.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/module.c b/kernel/module.c index 2461370813b3..d7a92682fba3 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -1225,6 +1225,12 @@ static const struct kernel_symbol *resolve_symbol(struct module *mod, const unsigned long *crc; int err; + /* + * The module_mutex should not be a heavily contended lock; + * if we get the occasional sleep here, we'll go an extra iteration + * in the wait_event_interruptible(), which is harmless. + */ + sched_annotate_sleep(); mutex_lock(&module_mutex); sym = find_symbol(name, &owner, &crc, !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); From 9cc019b8c94fa59e02fd82f15f7b7d689e35c190 Mon Sep 17 00:00:00 2001 From: Peter Zijlstra Date: Wed, 11 Feb 2015 15:01:13 +1030 Subject: [PATCH 5/5] module: Replace over-engineered nested sleep Since the introduction of the nested sleep warning; we've established that the occasional sleep inside a wait_event() is fine. wait_event() loops are invariant wrt. spurious wakeups, and the occasional sleep has a similar effect on them. As long as its occasional its harmless. Therefore replace the 'correct' but verbose wait_woken() thing with a simple annotation to shut up the warning. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Rusty Russell --- kernel/module.c | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index d7a92682fba3..82dc1f899e6d 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2984,6 +2984,12 @@ static bool finished_loading(const char *name) struct module *mod; bool ret; + /* + * The module_mutex should not be a heavily contended lock; + * if we get the occasional sleep here, we'll go an extra iteration + * in the wait_event_interruptible(), which is harmless. + */ + sched_annotate_sleep(); mutex_lock(&module_mutex); mod = find_module_all(name, strlen(name), true); ret = !mod || mod->state == MODULE_STATE_LIVE @@ -3125,32 +3131,6 @@ static int may_init_module(void) return 0; } -/* - * Can't use wait_event_interruptible() because our condition - * 'finished_loading()' contains a blocking primitive itself (mutex_lock). - */ -static int wait_finished_loading(struct module *mod) -{ - DEFINE_WAIT_FUNC(wait, woken_wake_function); - int ret = 0; - - add_wait_queue(&module_wq, &wait); - for (;;) { - if (finished_loading(mod->name)) - break; - - if (signal_pending(current)) { - ret = -ERESTARTSYS; - break; - } - - wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT); - } - remove_wait_queue(&module_wq, &wait); - - return ret; -} - /* * We try to place it in the list now to make sure it's unique before * we dedicate too many resources. In particular, temporary percpu @@ -3171,8 +3151,8 @@ static int add_unformed_module(struct module *mod) || old->state == MODULE_STATE_UNFORMED) { /* Wait in case it fails to load. */ mutex_unlock(&module_mutex); - - err = wait_finished_loading(mod); + err = wait_event_interruptible(module_wq, + finished_loading(mod->name)); if (err) goto out_unlocked; goto again;