Skip to content

Commit c4fadf3

Browse files
Sebastian Andrzej Siewiorpetrpavlu
authored andcommitted
module: Use RCU in module_get_kallsym().
The modules list and module::kallsyms can be accessed under RCU assumption. Iterate the modules with RCU protection, use rcu_dereference() to access the kallsyms pointer. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Pavlu <[email protected]>
1 parent f013692 commit c4fadf3

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

kernel/module/kallsyms.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,13 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
381381
{
382382
struct module *mod;
383383

384-
preempt_disable();
384+
guard(rcu)();
385385
list_for_each_entry_rcu(mod, &modules, list) {
386386
struct mod_kallsyms *kallsyms;
387387

388388
if (mod->state == MODULE_STATE_UNFORMED)
389389
continue;
390-
kallsyms = rcu_dereference_sched(mod->kallsyms);
390+
kallsyms = rcu_dereference(mod->kallsyms);
391391
if (symnum < kallsyms->num_symtab) {
392392
const Elf_Sym *sym = &kallsyms->symtab[symnum];
393393

@@ -396,12 +396,10 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
396396
strscpy(name, kallsyms_symbol_name(kallsyms, symnum), KSYM_NAME_LEN);
397397
strscpy(module_name, mod->name, MODULE_NAME_LEN);
398398
*exported = is_exported(name, *value, mod);
399-
preempt_enable();
400399
return 0;
401400
}
402401
symnum -= kallsyms->num_symtab;
403402
}
404-
preempt_enable();
405403
return -ERANGE;
406404
}
407405

0 commit comments

Comments
 (0)