Skip to content

Commit 275d7d4

Browse files
Peter Zijlstrarustyrussell
authored andcommitted
module: Fix locking in symbol_put_addr()
Poma (on the way to another bug) reported an assertion triggering: [<ffffffff81150529>] module_assert_mutex_or_preempt+0x49/0x90 [<ffffffff81150822>] __module_address+0x32/0x150 [<ffffffff81150956>] __module_text_address+0x16/0x70 [<ffffffff81150f19>] symbol_put_addr+0x29/0x40 [<ffffffffa04b77ad>] dvb_frontend_detach+0x7d/0x90 [dvb_core] Laura Abbott <labbott@redhat.com> produced a patch which lead us to inspect symbol_put_addr(). This function has a comment claiming it doesn't need to disable preemption around the module lookup because it holds a reference to the module it wants to find, which therefore cannot go away. This is wrong (and a false optimization too, preempt_disable() is really rather cheap, and I doubt any of this is on uber critical paths, otherwise it would've retained a pointer to the actual module anyway and avoided the second lookup). While its true that the module cannot go away while we hold a reference on it, the data structure we do the lookup in very much _CAN_ change while we do the lookup. Therefore fix the comment and add the required preempt_disable(). Reported-by: poma <pomidorabelisima@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Fixes: a6e6abd ("module: remove module_text_address()") Cc: stable@kernel.org
1 parent 1b647a1 commit 275d7d4

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎kernel/module.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,11 +1063,15 @@ void symbol_put_addr(void *addr)
10631063
if (core_kernel_text(a))
10641064
return;
10651065

1066-
/* module_text_address is safe here: we're supposed to have reference
1067-
* to module from symbol_get, so it can't go away. */
1066+
/*
1067+
* Even though we hold a reference on the module; we still need to
1068+
* disable preemption in order to safely traverse the data structure.
1069+
*/
1070+
preempt_disable();
10681071
modaddr = __module_text_address(a);
10691072
BUG_ON(!modaddr);
10701073
module_put(modaddr);
1074+
preempt_enable();
10711075
}
10721076
EXPORT_SYMBOL_GPL(symbol_put_addr);
10731077

0 commit comments

Comments
 (0)