Skip to content

Commit ff49d74

Browse files
Yehuda Sadehtorvalds
authored andcommitted
module: initialize module dynamic debug later
We should initialize the module dynamic debug datastructures only after determining that the module is not loaded yet. This fixes a bug that introduced in 2.6.35-rc2, where when a trying to load a module twice, we also load it's dynamic printing data twice which causes all sorts of nasty issues. Also handle the dynamic debug cleanup later on failure. Signed-off-by: Yehuda Sadeh <yehuda@hq.newdream.net> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (removed a #ifdef) Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e3668dd commit ff49d74

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

‎include/linux/dynamic_debug.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
4040
const char *modname);
4141

4242
#if defined(CONFIG_DYNAMIC_DEBUG)
43-
extern int ddebug_remove_module(char *mod_name);
43+
extern int ddebug_remove_module(const char *mod_name);
4444

4545
#define __dynamic_dbg_enabled(dd) ({ \
4646
int __ret = 0; \
@@ -73,7 +73,7 @@ extern int ddebug_remove_module(char *mod_name);
7373

7474
#else
7575

76-
static inline int ddebug_remove_module(char *mod)
76+
static inline int ddebug_remove_module(const char *mod)
7777
{
7878
return 0;
7979
}

‎kernel/module.c‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,12 @@ static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
20622062
#endif
20632063
}
20642064

2065+
static void dynamic_debug_remove(struct _ddebug *debug)
2066+
{
2067+
if (debug)
2068+
ddebug_remove_module(debug->modname);
2069+
}
2070+
20652071
static void *module_alloc_update_bounds(unsigned long size)
20662072
{
20672073
void *ret = module_alloc(size);
@@ -2124,6 +2130,8 @@ static noinline struct module *load_module(void __user *umod,
21242130
void *ptr = NULL; /* Stops spurious gcc warning */
21252131
unsigned long symoffs, stroffs, *strmap;
21262132
void __percpu *percpu;
2133+
struct _ddebug *debug = NULL;
2134+
unsigned int num_debug = 0;
21272135

21282136
mm_segment_t old_fs;
21292137

@@ -2476,15 +2484,9 @@ static noinline struct module *load_module(void __user *umod,
24762484
kfree(strmap);
24772485
strmap = NULL;
24782486

2479-
if (!mod->taints) {
2480-
struct _ddebug *debug;
2481-
unsigned int num_debug;
2482-
2487+
if (!mod->taints)
24832488
debug = section_objs(hdr, sechdrs, secstrings, "__verbose",
24842489
sizeof(*debug), &num_debug);
2485-
if (debug)
2486-
dynamic_debug_setup(debug, num_debug);
2487-
}
24882490

24892491
err = module_finalize(hdr, sechdrs, mod);
24902492
if (err < 0)
@@ -2526,10 +2528,13 @@ static noinline struct module *load_module(void __user *umod,
25262528
goto unlock;
25272529
}
25282530

2531+
if (debug)
2532+
dynamic_debug_setup(debug, num_debug);
2533+
25292534
/* Find duplicate symbols */
25302535
err = verify_export_symbols(mod);
25312536
if (err < 0)
2532-
goto unlock;
2537+
goto ddebug;
25332538

25342539
list_add_rcu(&mod->list, &modules);
25352540
mutex_unlock(&module_mutex);
@@ -2557,6 +2562,8 @@ static noinline struct module *load_module(void __user *umod,
25572562
mutex_lock(&module_mutex);
25582563
/* Unlink carefully: kallsyms could be walking list. */
25592564
list_del_rcu(&mod->list);
2565+
ddebug:
2566+
dynamic_debug_remove(debug);
25602567
unlock:
25612568
mutex_unlock(&module_mutex);
25622569
synchronize_sched();

‎lib/dynamic_debug.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ static void ddebug_table_free(struct ddebug_table *dt)
692692
* Called in response to a module being unloaded. Removes
693693
* any ddebug_table's which point at the module.
694694
*/
695-
int ddebug_remove_module(char *mod_name)
695+
int ddebug_remove_module(const char *mod_name)
696696
{
697697
struct ddebug_table *dt, *nextdt;
698698
int ret = -ENOENT;

0 commit comments

Comments
 (0)