Skip to content

Commit 01bbafc

Browse files
b49020torvalds
authored andcommitted
KEYS: trusted: Remove redundant static calls usage
Static calls invocations aren't well supported from module __init and __exit functions. Especially the static call from cleanup_trusted() led to a crash on x86 kernel with CONFIG_DEBUG_VIRTUAL=y. However, the usage of static call invocations for trusted_key_init() and trusted_key_exit() don't add any value from either a performance or security perspective. Hence switch to use indirect function calls instead. Note here that although it will fix the current crash report, ultimately the static call infrastructure should be fixed to either support its future usage from module __init and __exit functions or not. Reported-and-tested-by: Hyeonggon Yoo <[email protected]> Link: https://lore.kernel.org/lkml/ZRhKq6e5nF%2F4ZIV1@fedora/#t Fixes: 5d0682b ("KEYS: trusted: Add generic trusted keys framework") Signed-off-by: Sumit Garg <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 87813e1 commit 01bbafc

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

security/keys/trusted-keys/trusted_core.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@ static const struct trusted_key_source trusted_key_sources[] = {
4444
#endif
4545
};
4646

47-
DEFINE_STATIC_CALL_NULL(trusted_key_init, *trusted_key_sources[0].ops->init);
4847
DEFINE_STATIC_CALL_NULL(trusted_key_seal, *trusted_key_sources[0].ops->seal);
4948
DEFINE_STATIC_CALL_NULL(trusted_key_unseal,
5049
*trusted_key_sources[0].ops->unseal);
5150
DEFINE_STATIC_CALL_NULL(trusted_key_get_random,
5251
*trusted_key_sources[0].ops->get_random);
53-
DEFINE_STATIC_CALL_NULL(trusted_key_exit, *trusted_key_sources[0].ops->exit);
52+
static void (*trusted_key_exit)(void);
5453
static unsigned char migratable;
5554

5655
enum {
@@ -359,19 +358,16 @@ static int __init init_trusted(void)
359358
if (!get_random)
360359
get_random = kernel_get_random;
361360

362-
static_call_update(trusted_key_init,
363-
trusted_key_sources[i].ops->init);
364361
static_call_update(trusted_key_seal,
365362
trusted_key_sources[i].ops->seal);
366363
static_call_update(trusted_key_unseal,
367364
trusted_key_sources[i].ops->unseal);
368365
static_call_update(trusted_key_get_random,
369366
get_random);
370-
static_call_update(trusted_key_exit,
371-
trusted_key_sources[i].ops->exit);
367+
trusted_key_exit = trusted_key_sources[i].ops->exit;
372368
migratable = trusted_key_sources[i].ops->migratable;
373369

374-
ret = static_call(trusted_key_init)();
370+
ret = trusted_key_sources[i].ops->init();
375371
if (!ret)
376372
break;
377373
}
@@ -388,7 +384,8 @@ static int __init init_trusted(void)
388384

389385
static void __exit cleanup_trusted(void)
390386
{
391-
static_call_cond(trusted_key_exit)();
387+
if (trusted_key_exit)
388+
(*trusted_key_exit)();
392389
}
393390

394391
late_initcall(init_trusted);

0 commit comments

Comments
 (0)