diff options
author | 2025-01-08 10:04:42 +0100 | |
---|---|---|
committer | 2025-03-10 11:54:45 +0100 | |
commit | 2abf84f688bed9cb4d3208d9d538b3387d292972 (patch) | |
tree | 911dc7647b173ceeb50752992c0574a93b42218f /kernel/module/main.c | |
parent | module: Allow __module_address() to be called from RCU section. (diff) | |
download | wireguard-linux-2abf84f688bed9cb4d3208d9d538b3387d292972.tar.xz wireguard-linux-2abf84f688bed9cb4d3208d9d538b3387d292972.zip |
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>
Diffstat (limited to 'kernel/module/main.c')
-rw-r--r-- | kernel/module/main.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/kernel/module/main.c b/kernel/module/main.c index 2155814f35dd..aebb17e1bfb9 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3703,28 +3703,23 @@ out: /* Given an address, look for it in the module exception tables. */ const struct exception_table_entry *search_module_extables(unsigned long addr) { - const struct exception_table_entry *e = NULL; struct module *mod; - preempt_disable(); + guard(rcu)(); mod = __module_address(addr); if (!mod) - goto out; + return NULL; if (!mod->num_exentries) - goto out; - - e = search_extable(mod->extable, - mod->num_exentries, - addr); -out: - preempt_enable(); - + return NULL; /* - * Now, if we found one, we are running inside it now, hence - * we cannot unload the module, hence no refcnt needed. + * The address passed here belongs to a module that is currently + * invoked (we are running inside it). Therefore its module::refcnt + * needs already be >0 to ensure that it is not removed at this stage. + * All other user need to invoke this function within a RCU read + * section. */ - return e; + return search_extable(mod->extable, mod->num_exentries, addr); } /** |