Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5623862pxv; Wed, 21 Jul 2021 09:50:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8Sb/QazOhLyVWStvpQcV4l+ex+H0KhXKWazd58qgpByOHRE4V2+wVYu7dVrEcPbX9gVN8 X-Received: by 2002:a05:6402:1acf:: with SMTP id ba15mr48230985edb.167.1626886246583; Wed, 21 Jul 2021 09:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626886246; cv=none; d=google.com; s=arc-20160816; b=wT7XygKRAobjvpTvjpXltufUjkHETppjtiZXnBEHtzca5c0jIYCamtmh3ZP+5h8dT/ gDhdUInDADqR+2mB5eZaO5pUssvsoIrXunxaW8+NNu0CAe9bJJcWDshO91V+gcYymG16 T6EJaQ8WDA8i4ZJA4NIoGLAxDVnU5vNXYxDjTZ0hJAgoNuW6JewuL3gn9QFmI6aIr4Uj uZIKewh3Wsdmxln8XkgyQNQCHwsslOeHywP8ELtdJ3YhzBX/JXuX9t5ODsr+0XqVM5QR XGA6YBoJqes7laGX8Eb/4o6kPVCmAG5rpnM/wneM3AXKamwL5fgByUQvcjWtmwew4eT5 MDxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xg2qnJspJabwmKr5AiJb/s1acOGO45IhStm/jG1toTU=; b=0e0Wz6tHKj7KR1GVTsQPSaQ3ULtlZZuFNfvVQb3YUX3wcLCssrwenKZX029+G4f1O5 wSrqHyIn5Y9FveNs3VqCoEcd0KPx3O9Qv1FenUsPco5gebRbF2fdG2tLksuoZXH7KRc0 CU7MCJUYR2NJxdOVB8ZKdSiqgH0YV9dYx0TfctcHD0Q0q/ci8rR/xjVXHkWeLLmwrrCy gzVbXdjQ5azSwyyJcxJbQcHZdAgXmoPJ1ETzkUEALYYjK5KkR3N2B0cSabhzwTqvDmuY 4RsScOweSr3S3bs8dIBpww5X8hVzGQ4T4DZt4J/DZNZh6CZoXBfBDyQ9v2nmZAdPWKcD 3iEA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e8si21314227eja.349.2021.07.21.09.50.09; Wed, 21 Jul 2021 09:50:46 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233326AbhGUQJA (ORCPT + 99 others); Wed, 21 Jul 2021 12:09:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235368AbhGUQI6 (ORCPT ); Wed, 21 Jul 2021 12:08:58 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 867A4C061575 for ; Wed, 21 Jul 2021 09:49:34 -0700 (PDT) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m6FP7-0004wi-46; Wed, 21 Jul 2021 18:49:05 +0200 Received: from afa by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1m6FP4-0003EP-3g; Wed, 21 Jul 2021 18:49:02 +0200 From: Ahmad Fatoum To: James Bottomley , Jarkko Sakkinen , Mimi Zohar , David Howells Cc: kernel@pengutronix.de, Ahmad Fatoum , James Morris , "Serge E. Hallyn" , =?UTF-8?q?Horia=20Geant=C4=83?= , Aymen Sghaier , Herbert Xu , "David S. Miller" , Udit Agarwal , Jan Luebbe , Eric Biggers , David Gstir , Richard Weinberger , Franck LENORMAND , Sumit Garg , keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH 1/4] KEYS: trusted: allow users to use kernel RNG for key material Date: Wed, 21 Jul 2021 18:48:52 +0200 Message-Id: <3b93fda0155af1a8776e9cc9984ecdb39ce827e4.1626885907.git-series.a.fatoum@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: afa@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-crypto@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org 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ă" 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(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/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 initialized successfully during iteration. + trusted.kernel_rng = [KEYS] + Format: + When set to true (1), the kernel random number pool + is used to generate key material for trusted keys. + The default is to leave the RNG's choice to each + individual trust source. + tsc= 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/Documentation/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 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. The random number generator in use differs according to the +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 vary + 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 CSPRNG which can be seeded via multiple entropy sources. +Optionally, users may specify ``trusted.kernel_rng=1`` on the kernel +command-line to override the used RNG with the kernel's random number pool. + Encrypted Keys -------------- diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-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 = { }; 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 = 0; for (i = 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 = trusted_key_sources[i].ops->get_random; + if (trusted_kernel_rng) + get_random = 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 = trusted_key_sources[i].ops->migratable; -- git-series 0.9.1