Skip to content

Commit 2abf84f

Browse files
Sebastian Andrzej Siewiorpetrpavlu
authored andcommitted
module: Use RCU in search_module_extables().
search_module_extables() returns an exception_table_entry belonging to a module. The lookup via __module_address() can be performed with RCU protection. The returned exception_table_entry remains valid because the passed address usually belongs to a module that is currently executed. So the module can not be removed because "something else" holds a reference to it, ensuring that it can not be removed. Exceptions here are: - kprobe, acquires a reference on the module beforehand - MCE, invokes the function from within a timer and the RCU lifetime guarantees (of the timer) are sufficient. Therefore it is safe to return the exception_table_entry outside the RCU section which provided the module. Use RCU for the lookup in search_module_extables() and update the comment. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20250108090457.512198-14-bigeasy@linutronix.de Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
1 parent 7d9dda6 commit 2abf84f

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

kernel/module/main.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,28 +3703,23 @@ char *module_flags(struct module *mod, char *buf, bool show_state)
37033703
/* Given an address, look for it in the module exception tables. */
37043704
const struct exception_table_entry *search_module_extables(unsigned long addr)
37053705
{
3706-
const struct exception_table_entry *e = NULL;
37073706
struct module *mod;
37083707

3709-
preempt_disable();
3708+
guard(rcu)();
37103709
mod = __module_address(addr);
37113710
if (!mod)
3712-
goto out;
3711+
return NULL;
37133712

37143713
if (!mod->num_exentries)
3715-
goto out;
3716-
3717-
e = search_extable(mod->extable,
3718-
mod->num_exentries,
3719-
addr);
3720-
out:
3721-
preempt_enable();
3722-
3714+
return NULL;
37233715
/*
3724-
* Now, if we found one, we are running inside it now, hence
3725-
* we cannot unload the module, hence no refcnt needed.
3716+
* The address passed here belongs to a module that is currently
3717+
* invoked (we are running inside it). Therefore its module::refcnt
3718+
* needs already be >0 to ensure that it is not removed at this stage.
3719+
* All other user need to invoke this function within a RCU read
3720+
* section.
37263721
*/
3727-
return e;
3722+
return search_extable(mod->extable, mod->num_exentries, addr);
37283723
}
37293724

37303725
/**

0 commit comments

Comments
 (0)