From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F141FC43216 for ; Tue, 10 Aug 2021 05:25:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD1326101D for ; Tue, 10 Aug 2021 05:25:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237660AbhHJFZY (ORCPT ); Tue, 10 Aug 2021 01:25:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237643AbhHJFZV (ORCPT ); Tue, 10 Aug 2021 01:25:21 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D68DC061798 for ; Mon, 9 Aug 2021 22:24:59 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id n6so13974733ljp.9 for ; Mon, 09 Aug 2021 22:24:59 -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=CFWqBCQp2YlhCV7jSxWtmoCr8RILzISB86MNoTEBHeU=; b=kOohwNbQp4KuzGJcZF4yy50pxkQN5Pb3iyD+ksrmfBVybK+TUfjtOwUyb7bKShe8tW SdRFWAigtNDsjm+fYfhVo3pIxT6X/DNEHzlL1Yb+k45momrT3GI3kLzx/UC1L3NV5WvG 6dFgkqQwdB9tsG044F0FDPRv7bPPwEyO0WdNtgH2iU48kKdX3L++yX8EzxA0ZGhCs3f8 fJ5M+aYhbYV2OGcTpV+3ZpCUjy6t4JcreBfppE3CEU/cX5lIAyYfeMjg11Z4yiCF8DEQ bxpEyJUVg8TveXXvdXTMtRzWZrcVTWIQZBTGaawTSWC3BK3cVJm1GvVbvcK1fDoPfnOF sDYg== 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=CFWqBCQp2YlhCV7jSxWtmoCr8RILzISB86MNoTEBHeU=; b=XW6KBHTUHRkPT0tlxDxEfT3CRm6gOEzpJj/QqDeYs/0OQZAT3p8o7qLwjwRXXMswXu nYlV1G3eJTb3/Tx30nt9jwMf2CLDX+zOrJBu8BISgnxJqPCtr5UwV1qVgLZ/OVz3dNy5 a74FoF5qJ/TDnQHoBm3Ja70iJm49Eod37s6MGjGEdJ/i9/0m4TgjxcK2aFytI5Q5QFUF 2ZBdSVYZNiBV8ZoAGUSUNwHdivjfT/AwHQFarhEAN3SrMp1f9MIwzoiRDHlWptQx09lt VtINKmZ4/MYcg6F5shWpjFka7fAk55GCSU58KWNGJg5HiswTf9gJ2noIKgAIdJpFzM8A MbsQ== X-Gm-Message-State: AOAM532LsbDEq8cvkxLh9OEqm8x2+nSkAI4m/BqprDdLjqpGW2HO9B45 DCFDGwCQTNfQiYe8VV9wRdZNVXnBgYoLjMgkhEVyXQ== X-Google-Smtp-Source: ABdhPJwAO97YdfcdCAmTaAWes9GxsrI5CP30XQe+NgCZoBVV5RVlt4j0z3ZrFIcGb4t5MvWxg/JuOLFUnrMQtk2HCJI= X-Received: by 2002:a05:651c:516:: with SMTP id o22mr17678549ljp.152.1628573097700; Mon, 09 Aug 2021 22:24:57 -0700 (PDT) MIME-Version: 1.0 References: <7b771da7b09a01c8b4da2ed21f05251ea797b2e8.1626885907.git-series.a.fatoum@pengutronix.de> <7537c853-3641-a6d3-91d8-70fea9f01a89@pengutronix.de> <20210809095647.7xcxjeot5gyvmlpj@kernel.org> In-Reply-To: <20210809095647.7xcxjeot5gyvmlpj@kernel.org> From: Sumit Garg Date: Tue, 10 Aug 2021 10:54:46 +0530 Message-ID: Subject: Re: [PATCH 2/4] KEYS: trusted: allow trust sources to use kernel RNG for key material To: Jarkko Sakkinen Cc: Ahmad Fatoum , James Bottomley , 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" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 9 Aug 2021 at 15:26, Jarkko Sakkinen wrote: > > On Mon, Aug 09, 2021 at 09:52:20AM +0200, Ahmad Fatoum wrote: > > 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 RN= G, > > >> but instead let the hardware that does the sealing/unsealing also > > >> generate the random key material. While a previous change offers use= rs > > >> 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-productio= n > > >> HWRNG drivers implemented, as otherwise code would have to be duplic= ated > > >> 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=C4=83" > > >> 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/ke= ys/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 =3D trusted_key_sources[i].ops->get_rando= m; > > >> - if (trusted_kernel_rng) > > >> + if (trusted_kernel_rng || !get_random) > > >> get_random =3D kernel_get_random; > > >> > > > > > > For ease of understanding, I would prefer to write it as: > > > > > > get_random =3D trusted_key_sources[i].ops->get_rand= om ?: > > > kernel_get_random; > > > if (trusted_kernel_rng) > > > get_random =3D 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. > > Ternary operators are pain to read, unless a super trivial case. > > I'd stick to what you did. Fair enough, I am fine with the current patch. -Sumit > > /Jarkko