All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sumit Garg <sumit.garg@linaro.org>
Cc: "James Bottomley" <jejb@linux.ibm.com>,
	"Jarkko Sakkinen" <jarkko@kernel.org>,
	"Mimi Zohar" <zohar@linux.ibm.com>,
	"David Howells" <dhowells@redhat.com>,
	kernel <kernel@pengutronix.de>,
	"James Morris" <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"Horia Geantă" <horia.geanta@nxp.com>,
	"Aymen Sghaier" <aymen.sghaier@nxp.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	"Udit Agarwal" <udit.agarwal@nxp.com>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Jan Luebbe" <j.luebbe@pengutronix.de>,
	"David Gstir" <david@sigma-star.at>,
	"Richard Weinberger" <richard@nod.at>,
	"Franck LENORMAND" <franck.lenormand@nxp.com>,
	"open list:ASYMMETRIC KEYS" <keyrings@vger.kernel.org>,
	"open list:HARDWARE RANDOM NUMBER GENERATOR CORE"
	<linux-crypto@vger.kernel.org>,
	linux-integrity <linux-integrity@vger.kernel.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"open list:SECURITY SUBSYSTEM"
	<linux-security-module@vger.kernel.org>
Subject: Re: [PATCH 2/4] KEYS: trusted: allow trust sources to use kernel RNG for key material
Date: Mon, 9 Aug 2021 09:52:20 +0200	[thread overview]
Message-ID: <7537c853-3641-a6d3-91d8-70fea9f01a89@pengutronix.de> (raw)
In-Reply-To: <CAFA6WYOskwZNe5Wb5PTtnSHQBonSXZ48eEex0w9jQ+JW4vG=+w@mail.gmail.com>

Hello Sumit,

On 22.07.21 08:31, Sumit Garg wrote:
> On Wed, 21 Jul 2021 at 22:19, Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
>>
>> The two existing trusted key sources don't make use of the kernel RNG,
>> but instead let the hardware that does the sealing/unsealing also
>> generate the random key material. While a previous change offers users
>> the choice to use the kernel RNG instead for both, new trust sources
>> may want to unconditionally use the kernel RNG for generating key
>> material, like it's done elsewhere in the kernel.
>>
>> This is especially prudent for hardware that has proven-in-production
>> HWRNG drivers implemented, as otherwise code would have to be duplicated
>> only to arrive at a possibly worse result.
>>
>> Make this possible by turning struct trusted_key_ops::get_random
>> into an optional member. If a driver leaves it NULL, kernel RNG
>> will be used instead.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
>> ---
>> To: James Bottomley <jejb@linux.ibm.com>
>> To: Jarkko Sakkinen <jarkko@kernel.org>
>> To: Mimi Zohar <zohar@linux.ibm.com>
>> To: David Howells <dhowells@redhat.com>
>> Cc: James Morris <jmorris@namei.org>
>> Cc: "Serge E. Hallyn" <serge@hallyn.com>
>> Cc: "Horia Geantă" <horia.geanta@nxp.com>
>> Cc: Aymen Sghaier <aymen.sghaier@nxp.com>
>> Cc: Herbert Xu <herbert@gondor.apana.org.au>
>> Cc: "David S. Miller" <davem@davemloft.net>
>> Cc: Udit Agarwal <udit.agarwal@nxp.com>
>> Cc: Eric Biggers <ebiggers@kernel.org>
>> Cc: Jan Luebbe <j.luebbe@pengutronix.de>
>> Cc: David Gstir <david@sigma-star.at>
>> Cc: Richard Weinberger <richard@nod.at>
>> Cc: Franck LENORMAND <franck.lenormand@nxp.com>
>> Cc: Sumit Garg <sumit.garg@linaro.org>
>> Cc: keyrings@vger.kernel.org
>> Cc: linux-crypto@vger.kernel.org
>> Cc: linux-integrity@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> Cc: linux-security-module@vger.kernel.org
>> ---
>>  include/keys/trusted-type.h               | 2 +-
>>  security/keys/trusted-keys/trusted_core.c | 2 +-
>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/keys/trusted-type.h b/include/keys/trusted-type.h
>> index d89fa2579ac0..4eb64548a74f 100644
>> --- a/include/keys/trusted-type.h
>> +++ b/include/keys/trusted-type.h
>> @@ -64,7 +64,7 @@ struct trusted_key_ops {
>>         /* Unseal a key. */
>>         int (*unseal)(struct trusted_key_payload *p, char *datablob);
>>
>> -       /* Get a randomized key. */
>> +       /* Optional: Get a randomized key. */
>>         int (*get_random)(unsigned char *key, size_t key_len);
>>
>>         /* Exit key interface. */
>> diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c
>> index 569af9af8df0..d2b7626cde8b 100644
>> --- a/security/keys/trusted-keys/trusted_core.c
>> +++ b/security/keys/trusted-keys/trusted_core.c
>> @@ -334,7 +334,7 @@ static int __init init_trusted(void)
>>                         continue;
>>
>>                 get_random = trusted_key_sources[i].ops->get_random;
>> -               if (trusted_kernel_rng)
>> +               if (trusted_kernel_rng || !get_random)
>>                         get_random = kernel_get_random;
>>
> 
> For ease of understanding, I would prefer to write it as:
> 
>                   get_random = trusted_key_sources[i].ops->get_random ?:
>                                          kernel_get_random;
>                   if (trusted_kernel_rng)
>                         get_random = kernel_get_random;
> 
> With that:
> 
> Acked-by: Sumit Garg <sumit.garg@linaro.org>

I don't think it improves readability to split up the conditional.
At least I need to take a second pass over the code to understand
the second conditional.

Cheers,
Ahmad

> 
> -Sumit
> 
>>                 static_call_update(trusted_key_init,
>> --
>> git-series 0.9.1
> 


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

  reply	other threads:[~2021-08-09  7:52 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-21 16:48 [PATCH 0/4] KEYS: trusted: Introduce support for NXP CAAM-based trusted keys Ahmad Fatoum
2021-07-21 16:48 ` [PATCH 1/4] KEYS: trusted: allow users to use kernel RNG for key material Ahmad Fatoum
2021-07-22  6:17   ` Sumit Garg
2021-07-21 16:48 ` [PATCH 2/4] KEYS: trusted: allow trust sources " Ahmad Fatoum
2021-07-22  6:31   ` Sumit Garg
2021-08-09  7:52     ` Ahmad Fatoum [this message]
2021-08-09  9:56       ` Jarkko Sakkinen
2021-08-10  5:24         ` Sumit Garg
2021-07-21 16:48 ` [PATCH 3/4] crypto: caam - add in-kernel interface for blob generator Ahmad Fatoum
2021-08-10 11:29   ` David Gstir
2021-08-11 10:22     ` Ahmad Fatoum
2021-08-11 10:43       ` David Gstir
2021-07-21 16:48 ` [PATCH 4/4] KEYS: trusted: Introduce support for NXP CAAM-based trusted keys Ahmad Fatoum
2021-08-06 15:12 ` [PATCH 0/4] " Ahmad Fatoum
2021-08-09  9:35   ` Jarkko Sakkinen
2021-08-09 10:16     ` Ahmad Fatoum
2021-08-10 11:28       ` David Gstir
2021-08-20 16:25         ` Ahmad Fatoum
2021-08-20 15:39 ` Tim Harvey
2021-08-20 16:19   ` Ahmad Fatoum
2021-08-20 20:20     ` Tim Harvey
2021-08-20 20:36       ` Ahmad Fatoum
2021-08-20 21:19         ` Tim Harvey
2021-08-23 13:29           ` Ahmad Fatoum
2021-08-23 17:50             ` Tim Harvey
2021-08-24  7:33               ` Ahmad Fatoum
2021-08-24 15:23                 ` Tim Harvey
2021-08-25  9:34                   ` Ahmad Fatoum

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=7537c853-3641-a6d3-91d8-70fea9f01a89@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=aymen.sghaier@nxp.com \
    --cc=davem@davemloft.net \
    --cc=david@sigma-star.at \
    --cc=dhowells@redhat.com \
    --cc=ebiggers@kernel.org \
    --cc=franck.lenormand@nxp.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=j.luebbe@pengutronix.de \
    --cc=jarkko@kernel.org \
    --cc=jejb@linux.ibm.com \
    --cc=jmorris@namei.org \
    --cc=kernel@pengutronix.de \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=richard@nod.at \
    --cc=serge@hallyn.com \
    --cc=sumit.garg@linaro.org \
    --cc=udit.agarwal@nxp.com \
    --cc=zohar@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.