From: "Mickaël Salaün" <mic@digikod.net>
To: David Howells <dhowells@redhat.com>,
David Woodhouse <dwmw2@infradead.org>,
Jarkko Sakkinen <jarkko@kernel.org>
Cc: "Mickaël Salaün" <mic@digikod.net>,
"David S . Miller" <davem@davemloft.net>,
"Eric Snowberg" <eric.snowberg@oracle.com>,
"Mickaël Salaün" <mic@linux.microsoft.com>,
"Paul Moore" <paul@paul-moore.com>,
keyrings@vger.kernel.org, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v1 2/2] certs: Remove panic() calls from system_trusted_keyring_init()
Date: Fri, 11 Mar 2022 18:47:41 +0100 [thread overview]
Message-ID: <20220311174741.250424-3-mic@digikod.net> (raw)
In-Reply-To: <20220311174741.250424-1-mic@digikod.net>
From: Mickaël Salaün <mic@linux.microsoft.com>
Replace panic() calls from device_initcall(system_trusted_keyring_init)
with proper error handling using -ENODEV.
Suggested-by: Jarkko Sakkinen <jarkko@kernel.org> [1]
Link: https://lore.kernel.org/r/Yik0C2t7G272YZ73@iki.fi [1]
Signed-off-by: Mickaël Salaün <mic@linux.microsoft.com>
Link: https://lore.kernel.org/r/20220311174741.250424-3-mic@digikod.net
---
certs/system_keyring.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/certs/system_keyring.c b/certs/system_keyring.c
index 05b66ce9d1c9..428046a7aa7f 100644
--- a/certs/system_keyring.c
+++ b/certs/system_keyring.c
@@ -148,8 +148,10 @@ static __init int system_trusted_keyring_init(void)
KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH),
KEY_ALLOC_NOT_IN_QUOTA,
NULL, NULL);
- if (IS_ERR(builtin_trusted_keys))
- panic("Can't allocate builtin trusted keyring\n");
+ if (IS_ERR(builtin_trusted_keys)) {
+ pr_err("Can't allocate builtin trusted keyring\n");
+ return -ENODEV;
+ }
#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
secondary_trusted_keys =
@@ -161,14 +163,26 @@ static __init int system_trusted_keyring_init(void)
KEY_ALLOC_NOT_IN_QUOTA,
get_builtin_and_secondary_restriction(),
NULL);
- if (IS_ERR(secondary_trusted_keys))
- panic("Can't allocate secondary trusted keyring\n");
+ if (IS_ERR(secondary_trusted_keys)) {
+ pr_err("Can't allocate secondary trusted keyring\n");
+ goto err_secondary;
+ }
- if (key_link(secondary_trusted_keys, builtin_trusted_keys) < 0)
- panic("Can't link trusted keyrings\n");
+ if (key_link(secondary_trusted_keys, builtin_trusted_keys) < 0) {
+ pr_err("Can't link trusted keyrings\n");
+ goto err_link;
+ }
#endif
return 0;
+
+err_link:
+ key_put(secondary_trusted_keys);
+
+err_secondary:
+ key_put(builtin_trusted_keys);
+
+ return -ENODEV;
}
/*
--
2.35.1
next prev parent reply other threads:[~2022-03-11 17:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-11 17:47 [PATCH v1 0/2] Remove panic() from keyring init calls Mickaël Salaün
2022-03-11 17:47 ` [PATCH v1 1/2] certs: Remove panic() calls from blacklist_init() Mickaël Salaün
2022-03-11 22:00 ` Paul Moore
2022-03-20 21:04 ` Jarkko Sakkinen
2022-03-11 17:47 ` Mickaël Salaün [this message]
2022-03-17 7:36 ` [PATCH v1 2/2] certs: Remove panic() calls from system_trusted_keyring_init() Jarkko Sakkinen
2022-03-17 8:30 ` Mickaël Salaün
2022-03-17 8:31 ` Mickaël Salaün
2022-03-20 21:07 ` Jarkko Sakkinen
2022-03-20 21:06 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220311174741.250424-3-mic@digikod.net \
--to=mic@digikod.net \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=dwmw2@infradead.org \
--cc=eric.snowberg@oracle.com \
--cc=jarkko@kernel.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mic@linux.microsoft.com \
--cc=paul@paul-moore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox