kallsyms: Disable preemption for find_kallsyms_symbol_value
Subsystems (2)
Jiri Olsa
reviewerPATCH 1/1 kallsyms: Disable preemption for find_kallsyms_symbol_value
Artem reported suspicious RCU usage [1]. The reason is that verifier calls find_kallsyms_symbol_value with preemption enabled which will trigger suspicious RCU usage warning in rcu_dereference_sched call.
Disabling preemption in find_kallsyms_symbol_value and adding __find_kallsyms_symbol_value function.
[1] https://lore.kernel.org/bpf/[email protected]/
--- kernel/module/kallsyms.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
kernel/module/kallsyms.c +13 -3
@@ -442,7 +442,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, }/* Given a module and name of symbol, find and return the symbol's value */ -unsigned long find_kallsyms_symbol_value (struct module *mod,const char *name) +static unsigned long __find_kallsyms_symbol_value (struct module *mod,const char *name) {unsigned int i;struct mod_kallsyms *kallsyms =rcu_dereference_sched (mod->kallsyms);
@@ -466,7 +466,7 @@ static unsigned long __module_kallsyms_lookup_name(const char *name)if (colon) { mod =find_module_all (name, colon - name, false);if (mod) -return find_kallsyms_symbol_value (mod, colon +1 ); +return __find_kallsyms_symbol_value (mod, colon +1 );return 0 ; }
@@ -475,7 +475,7 @@ static unsigned long __module_kallsyms_lookup_name(const char *name)if (mod->state ==MODULE_STATE_UNFORMED )continue ; - ret =find_kallsyms_symbol_value (mod, name); + ret =__find_kallsyms_symbol_value (mod, name);if (ret)return ret; }
@@ -494,6 +494,16 @@ unsigned long module_kallsyms_lookup_name(const char *name)return ret; } +unsigned long find_kallsyms_symbol_value (struct module *mod,const char *name) +{ +unsigned long ret; + +preempt_disable (); + ret =__find_kallsyms_symbol_value (mod, name); +preempt_enable (); +return ret; +} + int module_kallsyms_on_each_symbol(const char *modname, int (*fn)(void *, const char *, struct module *, unsigned long),
Signature · 1 line
2.39.2
Quoted 6 lines · Jiri Olsa
Artem reported suspicious RCU usage [1]. The reason is that verifier calls
find_kallsyms_symbol_valuewith preemption enabled which will trigger suspicious RCU usage warning inrcu_dereference_schedcall.Disabling preemption in
find_kallsyms_symbol_valueand adding__find_kallsyms_symbol_valuefunction.
Quoted 58 lines
Fixes 31bf1dbccfb0 ("bpf: Fix attaching fentry/fexit/fmod_ret/lsm to modules")[1] https://lore.kernel.org/bpf/[email protected]/
Reported-by Artem Savkov <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- kernel/module/kallsyms.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)kernel/module/kallsyms.c +13
-3@@ -442,7 +442,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, }/* Given a module and name of symbol, find and return the symbol's value */ -unsigned long find_kallsyms_symbol_value (struct module *mod,const char *name) +static unsigned long __find_kallsyms_symbol_value (struct module *mod,const char *name) {unsigned int i;struct mod_kallsyms *kallsyms =rcu_dereference_sched (mod->kallsyms);@@ -466,7 +466,7 @@ static unsigned long __module_kallsyms_lookup_name(const char *name)if (colon) { mod =find_module_all (name, colon - name, false);if (mod) -return find_kallsyms_symbol_value (mod, colon +1 ); +return __find_kallsyms_symbol_value (mod, colon +1 );return 0 ; }@@ -475,7 +475,7 @@ static unsigned long __module_kallsyms_lookup_name(const char *name)if (mod->state ==MODULE_STATE_UNFORMED )continue ; - ret =find_kallsyms_symbol_value (mod, name); + ret =__find_kallsyms_symbol_value (mod, name);if (ret)return ret; }@@ -494,6 +494,16 @@ unsigned long module_kallsyms_lookup_name(const char *name)return ret; } +unsigned long find_kallsyms_symbol_value (struct module *mod,const char *name) +{ +unsigned long ret; + +preempt_disable (); + ret =__find_kallsyms_symbol_value (mod, name); +preempt_enable (); +return ret; +} + int module_kallsyms_on_each_symbol(const char *modname, int (*fn)(void *, const char *, struct module *, unsigned long),
Signature · 2 lines
Regards, Zhen Lei
Quoted 6 lines · Jiri Olsa
Artem reported suspicious RCU usage [1]. The reason is that verifier calls
find_kallsyms_symbol_valuewith preemption enabled which will trigger suspicious RCU usage warning inrcu_dereference_schedcall.Disabling preemption in
find_kallsyms_symbol_valueand adding__find_kallsyms_symbol_valuefunction.
Quoted 59 lines
Fixes 31bf1dbccfb0 ("bpf: Fix attaching fentry/fexit/fmod_ret/lsm to modules")[1] https://lore.kernel.org/bpf/[email protected]/
Reported-by Artem Savkov <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- kernel/module/kallsyms.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)kernel/module/kallsyms.c +13
-3@@ -442,7 +442,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, }/* Given a module and name of symbol, find and return the symbol's value */ -unsigned long find_kallsyms_symbol_value (struct module *mod,const char *name) +static unsigned long __find_kallsyms_symbol_value (struct module *mod,const char *name) {unsigned int i;struct mod_kallsyms *kallsyms =rcu_dereference_sched (mod->kallsyms);@@ -466,7 +466,7 @@ static unsigned long __module_kallsyms_lookup_name(const char *name)if (colon) { mod =find_module_all (name, colon - name, false);if (mod) -return find_kallsyms_symbol_value (mod, colon +1 ); +return __find_kallsyms_symbol_value (mod, colon +1 );return 0 ; }@@ -475,7 +475,7 @@ static unsigned long __module_kallsyms_lookup_name(const char *name)if (mod->state ==MODULE_STATE_UNFORMED )continue ; - ret =find_kallsyms_symbol_value (mod, name); + ret =__find_kallsyms_symbol_value (mod, name);if (ret)return ret; }@@ -494,6 +494,16 @@ unsigned long module_kallsyms_lookup_name(const char *name)return ret; } +unsigned long find_kallsyms_symbol_value (struct module *mod,const char *name) +{ +unsigned long ret; + +preempt_disable (); + ret =__find_kallsyms_symbol_value (mod, name); +preempt_enable (); +return ret; +} + int module_kallsyms_on_each_symbol(const char *modname, int (*fn)(void *, const char *, struct module *, unsigned long),Signature · 1 line
2.39.2
Signature · 1 line
Artem
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 8 lines · On Tue, 4 Apr 2023 00:02:54 +0200 you wrote:
Artem reported suspicious RCU usage [1]. The reason is that verifier calls
find_kallsyms_symbol_valuewith preemption enabled which will trigger suspicious RCU usage warning inrcu_dereference_schedcall.Disabling preemption in
find_kallsyms_symbol_valueand adding__find_kallsyms_symbol_valuefunction.[...]
Here is the summary with links:
- [bpf-next] kallsyms: Disable preemption for find_kallsyms_symbol_value
https://git.kernel.org/bpf/bpf-next/c/d099f594ad56
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 11 lines · Jiri Olsa
Artem reported suspicious RCU usage [1]. The reason is that verifier calls
find_kallsyms_symbol_valuewith preemption enabled which will trigger suspicious RCU usage warning inrcu_dereference_schedcall.Disabling preemption in
find_kallsyms_symbol_valueand adding__find_kallsyms_symbol_valuefunction.Fixes 31bf1dbccfb0 ("bpf: Fix attaching fentry/fexit/fmod_ret/lsm to modules")[1] https://lore.kernel.org/bpf/[email protected]/
Reported-by Artem Savkov <[email protected]>Signed-off-by Jiri Olsa <[email protected]>
Just for record:
Best Regards,
Petr
Quoted 66 lines · Jiri Olsa
Artem reported suspicious RCU usage [1]. The reason is that verifier calls
find_kallsyms_symbol_valuewith preemption enabled which will trigger suspicious RCU usage warning inrcu_dereference_schedcall.Disabling preemption in
find_kallsyms_symbol_valueand adding__find_kallsyms_symbol_valuefunction.Fixes 31bf1dbccfb0 ("bpf: Fix attaching fentry/fexit/fmod_ret/lsm to modules")[1] https://lore.kernel.org/bpf/[email protected]/
Reported-by Artem Savkov <[email protected]>Signed-off-by Jiri Olsa <[email protected]>--- kernel/module/kallsyms.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)kernel/module/kallsyms.c +13
-3@@ -442,7 +442,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, }/* Given a module and name of symbol, find and return the symbol's value */ -unsigned long find_kallsyms_symbol_value (struct module *mod,const char *name) +static unsigned long __find_kallsyms_symbol_value (struct module *mod,const char *name) {unsigned int i;struct mod_kallsyms *kallsyms =rcu_dereference_sched (mod->kallsyms);@@ -466,7 +466,7 @@ static unsigned long __module_kallsyms_lookup_name(const char *name)if (colon) { mod =find_module_all (name, colon - name, false);if (mod) -return find_kallsyms_symbol_value (mod, colon +1 ); +return __find_kallsyms_symbol_value (mod, colon +1 );return 0 ; }@@ -475,7 +475,7 @@ static unsigned long __module_kallsyms_lookup_name(const char *name)if (mod->state ==MODULE_STATE_UNFORMED )continue ; - ret =find_kallsyms_symbol_value (mod, name); + ret =__find_kallsyms_symbol_value (mod, name);if (ret)return ret; }@@ -494,6 +494,16 @@ unsigned long module_kallsyms_lookup_name(const char *name)return ret; } +unsigned long find_kallsyms_symbol_value (struct module *mod,const char *name) +{ +unsigned long ret; + +preempt_disable (); + ret =__find_kallsyms_symbol_value (mod, name); +preempt_enable (); +return ret; +} + int module_kallsyms_on_each_symbol(const char *modname, int (*fn)(void *, const char *, struct module *, unsigned long),Signature · 1 line
2.39.2
Signature · 1 line
Aaron Tomlin