[PATCH v7 11/14] platform/cznic: turris-signing-key: Flush key GC on key release
From: Jarkko Sakkinen
Date: Sun Nov 29 2026 - 12:07:15 EST
turris_signing_key_release() unlinks and puts the device's signing key
when the parent device unbinds.
Once keys pin the kernel module of their key type, flush key garbage
collection in turris_signing_key_release() so the module reference is
released synchronously before module unload. Also allocate the keyring
before registering the key type during module initialization.
Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
---
drivers/platform/cznic/turris-signing-key.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/drivers/platform/cznic/turris-signing-key.c b/drivers/platform/cznic/turris-signing-key.c
index 3827178565e2..fc06a44f96f3 100644
--- a/drivers/platform/cznic/turris-signing-key.c
+++ b/drivers/platform/cznic/turris-signing-key.c
@@ -129,6 +129,7 @@ static void turris_signing_key_release(void *key)
{
key_unlink(turris_signing_keyring, key);
key_put(key);
+ key_gc_flush(&turris_signing_key_type);
}
int
@@ -158,10 +159,6 @@ static int turris_signing_key_init(void)
{
int err;
- err = register_key_type(&turris_signing_key_type);
- if (err)
- return err;
-
turris_signing_keyring = keyring_alloc(".turris-signing-keys",
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, current_cred(),
(KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW |
@@ -171,18 +168,22 @@ static int turris_signing_key_init(void)
NULL, NULL);
if (IS_ERR(turris_signing_keyring)) {
pr_err("Cannot allocate Turris keyring\n");
-
- unregister_key_type(&turris_signing_key_type);
-
return PTR_ERR(turris_signing_keyring);
}
+ err = register_key_type(&turris_signing_key_type);
+ if (err) {
+ key_put(turris_signing_keyring);
+ return err;
+ }
+
return 0;
}
module_init(turris_signing_key_init);
static void turris_signing_key_exit(void)
{
+ key_revoke(turris_signing_keyring);
key_put(turris_signing_keyring);
unregister_key_type(&turris_signing_key_type);
}
--
2.47.3