Commit 5e376613899076396d0c97de67ad072587267370
Committed by
Linus Torvalds
1 parent
0159677857
Exists in
master
and in
4 other branches
[PATCH] symbol_put_addr() locks kernel
Even since a previous patch: Fix race between CONFIG_DEBUG_SLABALLOC and modules Sun, 27 Jun 2004 17:55:19 +0000 (17:55 +0000) http://www.kernel.org/git/?p=linux/kernel/git/torvalds/old-2.6-bkcvs.git;a=commit;h=92b3db26d31cf21b70e3c1eadc56c179506d8fbe The function symbol_put_addr() will deadlock the kernel. symbol_put_addr() would acquire modlist_lock, then while holding the lock call two functions kernel_text_address() and module_text_address() which also try to acquire the same lock. This deadlocks the kernel of course. This patch changes symbol_put_addr() to not acquire the modlist_lock, it doesn't need it since it never looks at the module list directly. Also, it now uses core_kernel_text() instead of kernel_text_address(). The latter has an additional check for addr inside a module, but we don't need to do that since we call module_text_address() (the same function kernel_text_address uses) ourselves. Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Cc: Zwane Mwaikambo <zwane@fsmlabs.com> Acked-by: Rusty Russell <rusty@rustcorp.com.au> Cc: Johannes Stezenbach <js@linuxtv.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Showing 3 changed files with 8 additions and 7 deletions Side-by-side Diff
include/linux/kernel.h
... | ... | @@ -124,6 +124,7 @@ |
124 | 124 | extern char *get_options(const char *str, int nints, int *ints); |
125 | 125 | extern unsigned long long memparse(char *ptr, char **retptr); |
126 | 126 | |
127 | +extern int core_kernel_text(unsigned long addr); | |
127 | 128 | extern int __kernel_text_address(unsigned long addr); |
128 | 129 | extern int kernel_text_address(unsigned long addr); |
129 | 130 | extern int session_of_pgrp(int pgrp); |
kernel/extable.c
kernel/module.c
... | ... | @@ -705,14 +705,14 @@ |
705 | 705 | |
706 | 706 | void symbol_put_addr(void *addr) |
707 | 707 | { |
708 | - unsigned long flags; | |
708 | + struct module *modaddr; | |
709 | 709 | |
710 | - spin_lock_irqsave(&modlist_lock, flags); | |
711 | - if (!kernel_text_address((unsigned long)addr)) | |
712 | - BUG(); | |
710 | + if (core_kernel_text((unsigned long)addr)) | |
711 | + return; | |
713 | 712 | |
714 | - module_put(module_text_address((unsigned long)addr)); | |
715 | - spin_unlock_irqrestore(&modlist_lock, flags); | |
713 | + if (!(modaddr = module_text_address((unsigned long)addr))) | |
714 | + BUG(); | |
715 | + module_put(modaddr); | |
716 | 716 | } |
717 | 717 | EXPORT_SYMBOL_GPL(symbol_put_addr); |
718 | 718 |