From 969eb7b840c13a73190d98a608b8fec50dc31971 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 26 Jun 2004 20:55:19 -0700 Subject: [PATCH] Fix race between CONFIG_DEBUG_SLABALLOC and modules store_stackinfo() does an unlocked module list walk during normal runtime which opens up a race with the module load/unload code. This can be triggered by simply unloading and loading a module in a loop with CONFIG_DEBUG_PAGEALLOC resulting in store_stackinfo() tripping over bad list pointers. kernel_text_address doesn't take any locks, because during an OOPS we don't want to deadlock. Rename that to __kernel_text_address, and make kernel_text_address take the lock. Signed-off-by: Zwane Mwaikambo Signed-off-by: Rusty Russell (modified) Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- kernel/extable.c | 15 ++++++++++++++- kernel/module.c | 14 +++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'kernel') diff --git a/kernel/extable.c b/kernel/extable.c index fbbfbf4fd367..7501b531ceed 100644 --- a/kernel/extable.c +++ b/kernel/extable.c @@ -40,7 +40,7 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr) return e; } -int kernel_text_address(unsigned long addr) +static int core_kernel_text(unsigned long addr) { if (addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) @@ -49,6 +49,19 @@ int kernel_text_address(unsigned long addr) if (addr >= (unsigned long)_sinittext && addr <= (unsigned long)_einittext) return 1; + return 0; +} +int __kernel_text_address(unsigned long addr) +{ + if (core_kernel_text(addr)) + return 1; + return __module_text_address(addr) != NULL; +} + +int kernel_text_address(unsigned long addr) +{ + if (core_kernel_text(addr)) + return 1; return module_text_address(addr) != NULL; } diff --git a/kernel/module.c b/kernel/module.c index 71a0944bddb1..858b34f4c33b 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2128,7 +2128,7 @@ const struct exception_table_entry *search_module_extables(unsigned long addr) } /* Is this a valid kernel address? We don't grab the lock: we are oopsing. */ -struct module *module_text_address(unsigned long addr) +struct module *__module_text_address(unsigned long addr) { struct module *mod; @@ -2139,6 +2139,18 @@ struct module *module_text_address(unsigned long addr) return NULL; } +struct module *module_text_address(unsigned long addr) +{ + struct module *mod; + unsigned long flags; + + spin_lock_irqsave(&modlist_lock, flags); + mod = __module_text_address(addr); + spin_unlock_irqrestore(&modlist_lock, flags); + + return mod; +} + /* Don't grab lock, we're oopsing. */ void print_modules(void) { -- cgit v1.2.3