Skip to content

Commit 31de287

Browse files
committed
KEYS: trusted: Rollback init_trusted() consistently
Do bind neither static calls nor trusted_key_exit() before a successful init, in order to maintain a consistent state. In addition, depart the init_trusted() in the case of a real error (i.e. getting back something else than -ENODEV). Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Closes: https://lore.kernel.org/linux-integrity/CAHk-=whOPoLaWM8S8GgoOPT7a2+nMH5h3TLKtn=R_3w4R1_Uvg@mail.gmail.com/ Cc: stable@vger.kernel.org # v5.13+ Fixes: 5d0682b ("KEYS: trusted: Add generic trusted keys framework") Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent e017769 commit 31de287

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

security/keys/trusted-keys/trusted_core.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,17 +358,17 @@ static int __init init_trusted(void)
358358
if (!get_random)
359359
get_random = kernel_get_random;
360360

361-
static_call_update(trusted_key_seal,
362-
trusted_key_sources[i].ops->seal);
363-
static_call_update(trusted_key_unseal,
364-
trusted_key_sources[i].ops->unseal);
365-
static_call_update(trusted_key_get_random,
366-
get_random);
367-
trusted_key_exit = trusted_key_sources[i].ops->exit;
368-
migratable = trusted_key_sources[i].ops->migratable;
369-
370361
ret = trusted_key_sources[i].ops->init();
371-
if (!ret)
362+
if (!ret) {
363+
static_call_update(trusted_key_seal, trusted_key_sources[i].ops->seal);
364+
static_call_update(trusted_key_unseal, trusted_key_sources[i].ops->unseal);
365+
static_call_update(trusted_key_get_random, get_random);
366+
367+
trusted_key_exit = trusted_key_sources[i].ops->exit;
368+
migratable = trusted_key_sources[i].ops->migratable;
369+
}
370+
371+
if (!ret || ret != -ENODEV)
372372
break;
373373
}
374374

0 commit comments

Comments
 (0)