Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp286874pxv; Wed, 21 Jul 2021 23:18:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpqSEaKRIWBu7YzQznwBqXf46fIebvLHaqBP6/ui7ExfWqUEiz7EQSVJhZ7oxC64WxqFSU X-Received: by 2002:a05:6602:584:: with SMTP id v4mr21818205iox.181.1626934708718; Wed, 21 Jul 2021 23:18:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626934708; cv=none; d=google.com; s=arc-20160816; b=SN3daxPlWNP4++Mx2dzVJBJQuKZJMWlL7l+t9avH2ATSPhyRHTuriSQOc0U2h0Zt0u XbbwE2qug1COMlThGdKX6Yc2N6+iAaGEsT/nGG0O2jgcNNU1/fl8/ENX0jwsxggdubdn 2BfaFJ3vt/wy1nhyHsQ1eYuwoQsjRnQBEg8cCdJJroc2wPAAPB6VyYDuThh7Wx4nDtEy Iv13ma2xZQzFP6jcL9SprAo4smls5KFHAawyyHpglo2XmIGHaUPojokAvpUn/VuQkUTV A2v0+0gsQ/XsAFOP8wDFu8z4SXG9O4MyprQh/Z3IeDBkHBBbTGnk6c6TX35jX+vUYSqV js9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=WORoTGHF102QmcPLJnYL0wl9JDz1GesGd0P0NJ/o4VY=; b=gCW9AfV5UThR0y9QOWRui/jMd32RxGWGGT3wZUxtLW6cmDljsSFCD4S+UaLhhcWP9u U0BW9d7bYUKOfNPg2HukdlCgOUyeAaYwiMz1S/6K+ZAkyqXYTP7Zu6qgSPeiMXMR5Hu7 u5ku74RCm/w+cvB2863SqPnzX0nXQZMgKYdRi37k40ktWf7r++OhpFz7lZf3m0IQJdy9 APIALo/aFABwTDOHOb6BSUgyZMqDxV0+tt6mZCzoqCjTyKaC5VXsWv/x0m4v0GxU25Ed MtuedwC/tvAzelu70EXChTYSV/vaPf5dkkRjXfR7rqxeTkNawl7Icqfj0rIRStDVIZHq yaCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IHTNNSIG; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d18si28296296ilo.140.2021.07.21.23.18.04; Wed, 21 Jul 2021 23:18:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IHTNNSIG; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230490AbhGVFhT (ORCPT + 99 others); Thu, 22 Jul 2021 01:37:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230474AbhGVFhS (ORCPT ); Thu, 22 Jul 2021 01:37:18 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D942EC0613D3 for ; Wed, 21 Jul 2021 23:17:53 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id y42so6809893lfa.3 for ; Wed, 21 Jul 2021 23:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=WORoTGHF102QmcPLJnYL0wl9JDz1GesGd0P0NJ/o4VY=; b=IHTNNSIGRh52lvqCaFt1jBoEW1/opFfVCgkb3Ln7p1RrwsNMrPogYpKHKMMe9ZTH+C Uqjx6nU7X5lHZNtAN8gMsvTGS201uow8OyfcWgp3zzsVPXuTzeQpm/UUdNedfMCXntId ISSOQCRoPSssGaJBTa/LKtraNnxMiWYjk1SRg0Ft+x4aBgzji4CD9BwNRrQfp8pKGSLO WdWy5q3j5ewpdwNwB52IwOcvRn3Zx1KZPg6I/AEg7XnE8o4p8/Mkjd9UR493w0QTtIa4 kFIPi3a4t4xPHnCcYC3hZhRtGpszwAFy+MWqjWqxpfsP7PHayUf1qyhDTjG3I54knlkp WyRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=WORoTGHF102QmcPLJnYL0wl9JDz1GesGd0P0NJ/o4VY=; b=fnqc0/0J08NWRHzCRkVEMGIvkX4Z+SkV4R/twCZpwB4+h4cquYcIv2srKn2uEER7pm t4lAZRmmF/aeom0wAwEJQxMJa7keBzDpTcqnXcIPVnHm59Rbf6/CHIdK/nAXCSxD3W3k 6h9mzdg4oDtKBm/ZcAnvux6svuQlh1u/bd3duTJTdnSaptfSfTuitIYbtafWuPUF2phd 8fSP4wtOjUit+6+F3Wwf5Ohk8Ovohw/FsQWazESGsdggdeQZvUBq7sz943GdlnkcTpKk 1/Qnzar4F9FHV62f3bh27GdowGX59/w0wEB7sBNM1HrM/b24oz+JmW+TPTU5UwAqMIiF UwSg== X-Gm-Message-State: AOAM531gWGbL1ZlI0LAPNXrFIkySsatKdWRu+UInjqWnixQk4g2mNs8z i42HC1N6ohfZvo6Y0GfTJDpJBdv3lURSS6iLa3fZDw== X-Received: by 2002:a19:6e0d:: with SMTP id j13mr27727553lfc.108.1626934672014; Wed, 21 Jul 2021 23:17:52 -0700 (PDT) MIME-Version: 1.0 References: <3b93fda0155af1a8776e9cc9984ecdb39ce827e4.1626885907.git-series.a.fatoum@pengutronix.de> In-Reply-To: <3b93fda0155af1a8776e9cc9984ecdb39ce827e4.1626885907.git-series.a.fatoum@pengutronix.de> From: Sumit Garg Date: Thu, 22 Jul 2021 11:47:40 +0530 Message-ID: Subject: Re: [PATCH 1/4] KEYS: trusted: allow users to use kernel RNG for key material To: Ahmad Fatoum Cc: James Bottomley , Jarkko Sakkinen , Mimi Zohar , David Howells , kernel , James Morris , "Serge E. Hallyn" , =?UTF-8?Q?Horia_Geant=C4=83?= , Aymen Sghaier , Herbert Xu , "David S. Miller" , Udit Agarwal , Jan Luebbe , Eric Biggers , David Gstir , Richard Weinberger , Franck LENORMAND , "open list:ASYMMETRIC KEYS" , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , linux-integrity , Linux Kernel Mailing List , "open list:SECURITY SUBSYSTEM" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, 21 Jul 2021 at 22:19, Ahmad Fatoum wrote: > > The two existing trusted key sources don't make use of the kernel RNG, > but instead let the hardware doing the sealing/unsealing also > generate the random key material. However, Users may want to place > less trust into the quality of the trust source's random number > generator and instead use the kernel entropy pool, which can be > seeded from multiple entropy sources. > > Make this possible by adding a new trusted.kernel_rng parameter, > that will force use of the kernel RNG. In its absence, it's up > to the trust source to decide, which random numbers to use, > maintaining the existing behavior. > > Suggested-by: Jarkko Sakkinen > Signed-off-by: Ahmad Fatoum > --- > To: James Bottomley > To: Jarkko Sakkinen > To: Mimi Zohar > To: David Howells > Cc: James Morris > Cc: "Serge E. Hallyn" > Cc: "Horia Geant=C4=83" > Cc: Aymen Sghaier > Cc: Herbert Xu > Cc: "David S. Miller" > Cc: Udit Agarwal > Cc: Jan Luebbe > Cc: Eric Biggers > Cc: David Gstir > Cc: Richard Weinberger > Cc: Franck LENORMAND > Cc: Sumit Garg > 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 > --- > Documentation/admin-guide/kernel-parameters.txt | 7 ++++++- > Documentation/security/keys/trusted-encrypted.rst | 20 +++++++++------- > security/keys/trusted-keys/trusted_core.c | 17 +++++++++++++- > 3 files changed, 35 insertions(+), 9 deletions(-) > Sounds like a reasonable approach to me. Acked-by: Sumit Garg -Sumit > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentat= ion/admin-guide/kernel-parameters.txt > index bdb22006f713..0267ead88902 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -5734,6 +5734,13 @@ > first trust source as a backend which is initiali= zed > successfully during iteration. > > + trusted.kernel_rng =3D [KEYS] > + Format: > + When set to true (1), the kernel random number po= ol > + is used to generate key material for trusted keys= . > + The default is to leave the RNG's choice to each > + individual trust source. > + > tsc=3D Disable clocksource stability checks for TSC. > Format: > [x86] reliable: mark tsc clocksource as reliable,= this > diff --git a/Documentation/security/keys/trusted-encrypted.rst b/Document= ation/security/keys/trusted-encrypted.rst > index 80d5a5af62a1..1d4b4b8f12f0 100644 > --- a/Documentation/security/keys/trusted-encrypted.rst > +++ b/Documentation/security/keys/trusted-encrypted.rst > @@ -87,22 +87,26 @@ Key Generation > Trusted Keys > ------------ > > -New keys are created from random numbers generated in the trust source. = They > -are encrypted/decrypted using a child key in the storage key hierarchy. > -Encryption and decryption of the child key must be protected by a strong > -access control policy within the trust source. > +New keys are created from random numbers. They are encrypted/decrypted u= sing > +a child key in the storage key hierarchy. Encryption and decryption of t= he > +child key must be protected by a strong access control policy within the > +trust source. The random number generator in use differs according to th= e > +selected trust source: > > - * TPM (hardware device) based RNG > + * TPM: hardware device based RNG > > - Strength of random numbers may vary from one device manufacturer to > - another. > + Keys are generated within the TPM. Strength of random numbers may v= ary > + from one device manufacturer to another. > > - * TEE (OP-TEE based on Arm TrustZone) based RNG > + * TEE: OP-TEE based on Arm TrustZone based RNG > > RNG is customizable as per platform needs. It can either be direct = output > from platform specific hardware RNG or a software based Fortuna CSP= RNG > which can be seeded via multiple entropy sources. > > +Optionally, users may specify ``trusted.kernel_rng=3D1`` on the kernel > +command-line to override the used RNG with the kernel's random number po= ol. > + > Encrypted Keys > -------------- > > diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/tr= usted-keys/trusted_core.c > index 8cab69e5d0da..569af9af8df0 100644 > --- a/security/keys/trusted-keys/trusted_core.c > +++ b/security/keys/trusted-keys/trusted_core.c > @@ -16,12 +16,17 @@ > #include > #include > #include > +#include > #include > #include > #include > #include > #include > > +static bool trusted_kernel_rng; > +module_param_named(kernel_rng, trusted_kernel_rng, bool, 0); > +MODULE_PARM_DESC(kernel_rng, "Generate key material from kernel RNG"); > + > static char *trusted_key_source; > module_param_named(source, trusted_key_source, charp, 0); > MODULE_PARM_DESC(source, "Select trusted keys source (tpm or tee)"); > @@ -312,8 +317,14 @@ struct key_type key_type_trusted =3D { > }; > EXPORT_SYMBOL_GPL(key_type_trusted); > > +static int kernel_get_random(unsigned char *key, size_t key_len) > +{ > + return get_random_bytes_wait(key, key_len) ?: key_len; > +} > + > static int __init init_trusted(void) > { > + int (*get_random)(unsigned char *key, size_t key_len); > int i, ret =3D 0; > > for (i =3D 0; i < ARRAY_SIZE(trusted_key_sources); i++) { > @@ -322,6 +333,10 @@ static int __init init_trusted(void) > strlen(trusted_key_sources[i].name))) > continue; > > + get_random =3D trusted_key_sources[i].ops->get_random; > + if (trusted_kernel_rng) > + get_random =3D kernel_get_random; > + > static_call_update(trusted_key_init, > trusted_key_sources[i].ops->init); > static_call_update(trusted_key_seal, > @@ -329,7 +344,7 @@ static int __init init_trusted(void) > static_call_update(trusted_key_unseal, > trusted_key_sources[i].ops->unseal); > static_call_update(trusted_key_get_random, > - trusted_key_sources[i].ops->get_random= ); > + get_random); > static_call_update(trusted_key_exit, > trusted_key_sources[i].ops->exit); > migratable =3D trusted_key_sources[i].ops->migratable; > -- > git-series 0.9.1