diff mbox series

[v2,1/1] certs: Explain the rationale to call panic()

Message ID 20220322111323.542184-2-mic@digikod.net (mailing list archive)
State New
Headers show
Series Explain panic() calls for keyring initialization | expand

Commit Message

Mickaël Salaün March 22, 2022, 11:13 a.m. UTC
From: Mickaël Salaün <mic@linux.microsoft.com>

The blacklist_init() function calls panic() for memory allocation
errors.  This change documents the reason why we don't return -ENODEV.

Suggested-by: Paul Moore <paul@paul-moore.com> [1]
Requested-by: Jarkko Sakkinen <jarkko@kernel.org> [1]
Link: https://lore.kernel.org/r/YjeW2r6Wv55Du0bJ@iki.fi [1]
Reviewed-by: Paul Moore <paul@paul-moore.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Mickaël Salaün <mic@linux.microsoft.com>
Link: https://lore.kernel.org/r/20220322111323.542184-2-mic@digikod.net
---

Changes since v1:
* Fix commit subject spelling spotted by David Woodhouse.
* Reword one sentence as suggested by Paul Moore.
* Add Reviewed-by Paul Moore.
* Add Reviewed-by Jarkko Sakkinen.
---
 certs/blacklist.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Tyler Hicks March 22, 2022, 5:39 p.m. UTC | #1
On 2022-03-22 12:13:23, Mickaël Salaün wrote:
> From: Mickaël Salaün <mic@linux.microsoft.com>
> 
> The blacklist_init() function calls panic() for memory allocation
> errors.  This change documents the reason why we don't return -ENODEV.
> 
> Suggested-by: Paul Moore <paul@paul-moore.com> [1]
> Requested-by: Jarkko Sakkinen <jarkko@kernel.org> [1]
> Link: https://lore.kernel.org/r/YjeW2r6Wv55Du0bJ@iki.fi [1]
> Reviewed-by: Paul Moore <paul@paul-moore.com>
> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
> Signed-off-by: Mickaël Salaün <mic@linux.microsoft.com>
> Link: https://lore.kernel.org/r/20220322111323.542184-2-mic@digikod.net

Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com>

Tyler

> ---
> 
> Changes since v1:
> * Fix commit subject spelling spotted by David Woodhouse.
> * Reword one sentence as suggested by Paul Moore.
> * Add Reviewed-by Paul Moore.
> * Add Reviewed-by Jarkko Sakkinen.
> ---
>  certs/blacklist.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/certs/blacklist.c b/certs/blacklist.c
> index 486ce0dd8e9c..25094ea73600 100644
> --- a/certs/blacklist.c
> +++ b/certs/blacklist.c
> @@ -307,6 +307,15 @@ static int restrict_link_for_blacklist(struct key *dest_keyring,
>  
>  /*
>   * Initialise the blacklist
> + *
> + * The blacklist_init() function is registered as an initcall via
> + * device_initcall().  As a result if the blacklist_init() function fails for
> + * any reason the kernel continues to execute.  While cleanly returning -ENODEV
> + * could be acceptable for some non-critical kernel parts, if the blacklist
> + * keyring fails to load it defeats the certificate/key based deny list for
> + * signed modules.  If a critical piece of security functionality that users
> + * expect to be present fails to initialize, panic()ing is likely the right
> + * thing to do.
>   */
>  static int __init blacklist_init(void)
>  {
> -- 
> 2.35.1
>
Jarkko Sakkinen March 22, 2022, 8:31 p.m. UTC | #2
On Tue, Mar 22, 2022 at 12:13:23PM +0100, Mickaël Salaün wrote:
> From: Mickaël Salaün <mic@linux.microsoft.com>
> 
> The blacklist_init() function calls panic() for memory allocation
> errors.  This change documents the reason why we don't return -ENODEV.
> 
> Suggested-by: Paul Moore <paul@paul-moore.com> [1]
> Requested-by: Jarkko Sakkinen <jarkko@kernel.org> [1]
> Link: https://lore.kernel.org/r/YjeW2r6Wv55Du0bJ@iki.fi [1]
> Reviewed-by: Paul Moore <paul@paul-moore.com>
> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
> Signed-off-by: Mickaël Salaün <mic@linux.microsoft.com>
> Link: https://lore.kernel.org/r/20220322111323.542184-2-mic@digikod.net
> ---
> 
> Changes since v1:
> * Fix commit subject spelling spotted by David Woodhouse.
> * Reword one sentence as suggested by Paul Moore.
> * Add Reviewed-by Paul Moore.
> * Add Reviewed-by Jarkko Sakkinen.
> ---
>  certs/blacklist.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/certs/blacklist.c b/certs/blacklist.c
> index 486ce0dd8e9c..25094ea73600 100644
> --- a/certs/blacklist.c
> +++ b/certs/blacklist.c
> @@ -307,6 +307,15 @@ static int restrict_link_for_blacklist(struct key *dest_keyring,
>  
>  /*
>   * Initialise the blacklist
> + *
> + * The blacklist_init() function is registered as an initcall via
> + * device_initcall().  As a result if the blacklist_init() function fails for
> + * any reason the kernel continues to execute.  While cleanly returning -ENODEV
> + * could be acceptable for some non-critical kernel parts, if the blacklist
> + * keyring fails to load it defeats the certificate/key based deny list for
> + * signed modules.  If a critical piece of security functionality that users
> + * expect to be present fails to initialize, panic()ing is likely the right
> + * thing to do.
>   */
>  static int __init blacklist_init(void)
>  {
> -- 
> 2.35.1
> 

Thank you, I'll put this into my "queue" folder and apply as soon I have
bandwidth.

BR, Jarkko
David Howells March 30, 2022, 12:53 p.m. UTC | #3
Mickaël Salaün <mic@digikod.net> wrote:

> The blacklist_init() function calls panic() for memory allocation
> errors.  This change documents the reason why we don't return -ENODEV.

Why, though?

This is only called whilst the kernel is booting.  If you hit ENOMEM, you
aren't likely to get much further with the boot process.

David
diff mbox series

Patch

diff --git a/certs/blacklist.c b/certs/blacklist.c
index 486ce0dd8e9c..25094ea73600 100644
--- a/certs/blacklist.c
+++ b/certs/blacklist.c
@@ -307,6 +307,15 @@  static int restrict_link_for_blacklist(struct key *dest_keyring,
 
 /*
  * Initialise the blacklist
+ *
+ * The blacklist_init() function is registered as an initcall via
+ * device_initcall().  As a result if the blacklist_init() function fails for
+ * any reason the kernel continues to execute.  While cleanly returning -ENODEV
+ * could be acceptable for some non-critical kernel parts, if the blacklist
+ * keyring fails to load it defeats the certificate/key based deny list for
+ * signed modules.  If a critical piece of security functionality that users
+ * expect to be present fails to initialize, panic()ing is likely the right
+ * thing to do.
  */
 static int __init blacklist_init(void)
 {