Skip to content

Commit e69a661

Browse files
Aaron Tomlinmcgrof
authored andcommitted
module: kallsyms: Ensure preemption in add_kallsyms() with PREEMPT_RT
The commit 08126db ("module: kallsyms: Fix suspicious rcu usage") under PREEMPT_RT=y, disabling preemption introduced an unbounded latency since the loop is not fixed. This change caused a regression since previously preemption was not disabled and we would dereference RCU-protected pointers explicitly. That being said, these pointers cannot change. Before kallsyms-specific data is prepared/or set-up, we ensure that the unformed module is known to be unique i.e. does not already exist (see load_module()). Therefore, we can fix this by using the common and more appropriate RCU flavour as this section of code can be safely preempted. Reported-by: Steven Rostedt <[email protected]> Fixes: 08126db ("module: kallsyms: Fix suspicious rcu usage") Signed-off-by: Aaron Tomlin <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 2cc3917 commit e69a661

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

kernel/module/kallsyms.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ void add_kallsyms(struct module *mod, const struct load_info *info)
176176
mod->kallsyms = (void __rcu *)mod->init_layout.base +
177177
info->mod_kallsyms_init_off;
178178

179-
preempt_disable();
179+
rcu_read_lock();
180180
/* The following is safe since this pointer cannot change */
181-
rcu_dereference_sched(mod->kallsyms)->symtab = (void *)symsec->sh_addr;
182-
rcu_dereference_sched(mod->kallsyms)->num_symtab = symsec->sh_size / sizeof(Elf_Sym);
181+
rcu_dereference(mod->kallsyms)->symtab = (void *)symsec->sh_addr;
182+
rcu_dereference(mod->kallsyms)->num_symtab = symsec->sh_size / sizeof(Elf_Sym);
183183
/* Make sure we get permanent strtab: don't use info->strtab. */
184-
rcu_dereference_sched(mod->kallsyms)->strtab =
184+
rcu_dereference(mod->kallsyms)->strtab =
185185
(void *)info->sechdrs[info->index.str].sh_addr;
186-
rcu_dereference_sched(mod->kallsyms)->typetab = mod->init_layout.base + info->init_typeoffs;
186+
rcu_dereference(mod->kallsyms)->typetab = mod->init_layout.base + info->init_typeoffs;
187187

188188
/*
189189
* Now populate the cut down core kallsyms for after init
@@ -193,28 +193,28 @@ void add_kallsyms(struct module *mod, const struct load_info *info)
193193
mod->core_kallsyms.strtab = s = mod->data_layout.base + info->stroffs;
194194
mod->core_kallsyms.typetab = mod->data_layout.base + info->core_typeoffs;
195195
strtab_size = info->core_typeoffs - info->stroffs;
196-
src = rcu_dereference_sched(mod->kallsyms)->symtab;
197-
for (ndst = i = 0; i < rcu_dereference_sched(mod->kallsyms)->num_symtab; i++) {
198-
rcu_dereference_sched(mod->kallsyms)->typetab[i] = elf_type(src + i, info);
196+
src = rcu_dereference(mod->kallsyms)->symtab;
197+
for (ndst = i = 0; i < rcu_dereference(mod->kallsyms)->num_symtab; i++) {
198+
rcu_dereference(mod->kallsyms)->typetab[i] = elf_type(src + i, info);
199199
if (i == 0 || is_livepatch_module(mod) ||
200200
is_core_symbol(src + i, info->sechdrs, info->hdr->e_shnum,
201201
info->index.pcpu)) {
202202
ssize_t ret;
203203

204204
mod->core_kallsyms.typetab[ndst] =
205-
rcu_dereference_sched(mod->kallsyms)->typetab[i];
205+
rcu_dereference(mod->kallsyms)->typetab[i];
206206
dst[ndst] = src[i];
207207
dst[ndst++].st_name = s - mod->core_kallsyms.strtab;
208208
ret = strscpy(s,
209-
&rcu_dereference_sched(mod->kallsyms)->strtab[src[i].st_name],
209+
&rcu_dereference(mod->kallsyms)->strtab[src[i].st_name],
210210
strtab_size);
211211
if (ret < 0)
212212
break;
213213
s += ret + 1;
214214
strtab_size -= ret + 1;
215215
}
216216
}
217-
preempt_enable();
217+
rcu_read_unlock();
218218
mod->core_kallsyms.num_symtab = ndst;
219219
}
220220

0 commit comments

Comments
 (0)