Skip to content

Commit 2ff49f8

Browse files
Sebastian Andrzej Siewiorpetrpavlu
authored andcommitted
module: Use RCU in find_symbol().
module_assert_mutex_or_preempt() is not needed in find_symbol(). The function checks for RCU-sched or the module_mutex to be acquired. The list_for_each_entry_rcu() below does the same check. Remove module_assert_mutex_or_preempt() from try_add_tainted_module(). Use RCU protection to invoke find_symbol() and update callers. 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 435bbcc commit 2ff49f8

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

kernel/module/main.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ static bool find_exported_symbol_in_section(const struct symsearch *syms,
331331

332332
/*
333333
* Find an exported symbol and return it, along with, (optional) crc and
334-
* (optional) module which owns it. Needs preempt disabled or module_mutex.
334+
* (optional) module which owns it. Needs RCU or module_mutex.
335335
*/
336336
bool find_symbol(struct find_symbol_arg *fsa)
337337
{
@@ -345,8 +345,6 @@ bool find_symbol(struct find_symbol_arg *fsa)
345345
struct module *mod;
346346
unsigned int i;
347347

348-
module_assert_mutex_or_preempt();
349-
350348
for (i = 0; i < ARRAY_SIZE(arr); i++)
351349
if (find_exported_symbol_in_section(&arr[i], NULL, fsa))
352350
return true;
@@ -812,10 +810,9 @@ void __symbol_put(const char *symbol)
812810
.gplok = true,
813811
};
814812

815-
preempt_disable();
813+
guard(rcu)();
816814
BUG_ON(!find_symbol(&fsa));
817815
module_put(fsa.owner);
818-
preempt_enable();
819816
}
820817
EXPORT_SYMBOL(__symbol_put);
821818

@@ -1369,21 +1366,18 @@ void *__symbol_get(const char *symbol)
13691366
.warn = true,
13701367
};
13711368

1372-
preempt_disable();
1373-
if (!find_symbol(&fsa))
1374-
goto fail;
1375-
if (fsa.license != GPL_ONLY) {
1376-
pr_warn("failing symbol_get of non-GPLONLY symbol %s.\n",
1377-
symbol);
1378-
goto fail;
1369+
scoped_guard(rcu) {
1370+
if (!find_symbol(&fsa))
1371+
return NULL;
1372+
if (fsa.license != GPL_ONLY) {
1373+
pr_warn("failing symbol_get of non-GPLONLY symbol %s.\n",
1374+
symbol);
1375+
return NULL;
1376+
}
1377+
if (strong_try_module_get(fsa.owner))
1378+
return NULL;
13791379
}
1380-
if (strong_try_module_get(fsa.owner))
1381-
goto fail;
1382-
preempt_enable();
13831380
return (void *)kernel_symbol_value(fsa.sym);
1384-
fail:
1385-
preempt_enable();
1386-
return NULL;
13871381
}
13881382
EXPORT_SYMBOL_GPL(__symbol_get);
13891383

kernel/module/version.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ int check_modstruct_version(const struct load_info *info,
7979
.name = "module_layout",
8080
.gplok = true,
8181
};
82+
bool have_symbol;
8283

8384
/*
8485
* Since this should be found in kernel (which can't be removed), no
85-
* locking is necessary -- use preempt_disable() to placate lockdep.
86+
* locking is necessary. Regardless use a RCU read section to keep
87+
* lockdep happy.
8688
*/
87-
preempt_disable();
88-
if (!find_symbol(&fsa)) {
89-
preempt_enable();
90-
BUG();
91-
}
92-
preempt_enable();
89+
scoped_guard(rcu)
90+
have_symbol = find_symbol(&fsa);
91+
BUG_ON(!have_symbol);
92+
9393
return check_version(info, "module_layout", mod, fsa.crc);
9494
}
9595

0 commit comments

Comments
 (0)