__jump_label_mod_text_reserved() should most likely use rcu_read_lock()
while invoking __module_text_address(). I'm not sure there is anything
to protect the module pointed by `start' and `end' from removal.
I *think* the protection is based on the preempt_disable() in
check_kprobe_address_safe(). That preempt_disable however does not
protect from module removal on a SMP machine.

Same goes for jump_label_update(). I think it is safe here to avoid the
read lock since the caller is the module so it can't go away at the same
time. However it might get a problem if the key reference here is shared
across modules for some reason with no module dependency.

Signed-off-by: Sebastian Andrzej Siewior <bige...@linutronix.de>
---
 kernel/jump_label.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index 52ebaca1b9fc..8aa9e0fce92e 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -231,16 +231,21 @@ struct static_key_mod {
 static int __jump_label_mod_text_reserved(void *start, void *end)
 {
        struct module *mod;
+       int ret = 0;
 
+       rcu_read_lock();
        mod = __module_text_address((unsigned long)start);
        if (!mod)
-               return 0;
+               goto out;
 
        WARN_ON_ONCE(__module_text_address((unsigned long)end) != mod);
 
-       return __jump_label_text_reserved(mod->jump_entries,
+       ret = __jump_label_text_reserved(mod->jump_entries,
                                mod->jump_entries + mod->num_jump_entries,
                                start, end);
+out:
+       rcu_read_unlock();
+       return ret;
 }
 
 static void __jump_label_mod_update(struct static_key *key, int enable)
@@ -448,11 +453,11 @@ static void jump_label_update(struct static_key *key, int 
enable)
 
        __jump_label_mod_update(key, enable);
 
-       preempt_disable();
+       rcu_read_lock();
        mod = __module_address((unsigned long)key);
        if (mod)
                stop = mod->jump_entries + mod->num_jump_entries;
-       preempt_enable();
+       rcu_read_unlock();
 #endif
        /* if there are no users, entry can be NULL */
        if (entry)
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to