Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2465679pxt; Mon, 9 Aug 2021 00:54:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrhEQJ+EcSKwvj1sWDiopjs0FVqvfOy8Bn9Tc4MicYWg9bqh5PTF9LW5AUJZkRrYHQsNl+ X-Received: by 2002:a05:6402:5112:: with SMTP id m18mr2760192edd.47.1628495664895; Mon, 09 Aug 2021 00:54:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628495664; cv=none; d=google.com; s=arc-20160816; b=N75Jd/+tMzZyvfeAxamduSzcHOUCtmtj39Z76lwyylWXOqaXyfCq17LJUu/NsiJQLh zX7HR02QyhHUU1EivdKwR9NIvBDKa67hQaOJO/393tP0drB4nPUhWy/sZ+Trovv3DL5U nzvZD33UJue2hsYXloiDPAS37hrXgdxHnmNdYpBnT61ldFuaxgd32kMkk7dyUOdiD795 8XJ0BBYjYjSMwZazj/hBDZsBramdVMwEvt35xkaTWah0VxZ1PaeeX8mBjYav8msIEl3r +GCHBromOUL9MgrvxwfGCgh6SMvwaCVFnJ6cMFEcUrhbkNTu/msGjxMc5Wt24H+GcNdV XLiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=FWJbqf2BIRyXGbf3nKgpWolTd+JXN75/TisUJiHDHPc=; b=Qrr4NIves3QgYD+Inkmil4hhR5LNTJ7FS5jA4kszlbyfwCi7VqJKyvg6rhpeURIVF2 r0+04mWOmbXXfG6X+eXu/xvW++GcN/NetvPjphWUojbLd05NMGb9lhp5h9lRSmERdhxY wNpEfPCsu0oekhcqSH9VHx524AdXQ2FH09snJl8G67NCG8BMG9JEbkNcuEmj8oez4fy/ UdsLJmiPRO/2OYL6bXLlrTewLPuELqDGy3JAOyi//C0/H+4gTiwGfPu+foV6Z1nFIg3C ytwelhL/OdW93yiYpo4RmNewsN68dRGTB95fvJ51snpAFnTkd05XQs29MfNTM2dKDpef BmBQ== 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 l9si26065edv.398.2021.08.09.00.53.55; Mon, 09 Aug 2021 00:54:24 -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 S233651AbhHIHww (ORCPT + 99 others); Mon, 9 Aug 2021 03:52:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233620AbhHIHww (ORCPT ); Mon, 9 Aug 2021 03:52:52 -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 5558CC0613D3 for ; Mon, 9 Aug 2021 00:52:31 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[127.0.0.1]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1mD05D-0004PL-Ob; Mon, 09 Aug 2021 09:52:27 +0200 Subject: Re: [PATCH 2/4] KEYS: trusted: allow trust sources to use kernel RNG for key material To: Sumit Garg 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 , Eric Biggers , Jan Luebbe , 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" References: <7b771da7b09a01c8b4da2ed21f05251ea797b2e8.1626885907.git-series.a.fatoum@pengutronix.de> From: Ahmad Fatoum Message-ID: <7537c853-3641-a6d3-91d8-70fea9f01a89@pengutronix.de> Date: Mon, 9 Aug 2021 09:52:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: a.fatoum@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 Hello Sumit, On 22.07.21 08:31, Sumit Garg wrote: > 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 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 >> --- >> 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: Eric Biggers >> Cc: Jan Luebbe >> 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 >> --- >> 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 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 |