From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E92133E35F; Thu, 29 Jan 2026 16:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.154 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769703553; cv=none; b=YqXWUjsq6gvgOEkKWS9zinTKdeKys2FGIzKx1O1jqbcp2IADA8NJLVP1THCY4w6/l3t2lCKRVP30ACMP/EY/qlnwoLDd/WFkQpbRmF8F9zMkfEln2/5CHmeJ9e41g/49sXPHDlKlMzV+vohH1rbY3r1a+LyoyVl8ur9O64s+TU8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769703553; c=relaxed/simple; bh=B3UA3hNrFo9BU/nOejIsF2QM+GSGPXVwTM8pl0g0+nE=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=EceyCtNg3CCBxn9krHe3d9EHtczzVJFVyQrzRYxw1aKJ2QzzMfSZ3G0a5jK5UePl+rXmrrpJXp40LnZaLq+ga1JxDQmIea3IryaS9Oonv7OS6UNqQp2KXR1X2nTjToSx3Q7ktDXRrt1LrQzTSAbvpEtDKiucyMzEorME+sD+tBo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=14.137.139.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.18.224.196]) by frasgout12.his.huawei.com (SkyGuard) with ESMTPS id 4f245b6R62ztfjS; Fri, 30 Jan 2026 00:16:35 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.47]) by mail.maildlp.com (Postfix) with ESMTP id 513834009B; Fri, 30 Jan 2026 00:19:07 +0800 (CST) Received: from [10.204.63.22] (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwBHhAZyiHtpQVzcAg--.46756S2; Thu, 29 Jan 2026 17:19:06 +0100 (CET) Message-ID: Subject: Re: [PATCH v9 01/11] KEYS: trusted: Use get_random-fallback for TPM From: Roberto Sassu To: Jarkko Sakkinen , linux-integrity@vger.kernel.org Cc: Eric Biggers , James Bottomley , Mimi Zohar , David Howells , Paul Moore , James Morris , "Serge E. Hallyn" , "open list:KEYS-TRUSTED" , "open list:SECURITY SUBSYSTEM" , open list Date: Thu, 29 Jan 2026 17:18:55 +0100 In-Reply-To: <20260125192526.782202-2-jarkko@kernel.org> References: <20260125192526.782202-1-jarkko@kernel.org> <20260125192526.782202-2-jarkko@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.3-0ubuntu1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID:LxC2BwBHhAZyiHtpQVzcAg--.46756S2 X-Coremail-Antispam: 1UD129KBjvJXoWxZry3Kw43Ww48ZF4xZw4xWFg_yoW5Cr15pF W8KF12qws7trZ7J3s3Ca1IkF1a934rKrW3Gr4rK34qgFsxJF1xJry0vFW5Ka4jyrWqgF1a qFWxXFyjga4DAw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvjb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWUJVW8JwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AF wI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4 xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43 MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I 0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWU JVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUF1 v3UUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAIBGl60h0SsgAAsy On Sun, 2026-01-25 at 21:25 +0200, Jarkko Sakkinen wrote: > 1. tpm2_get_random() is costly when TCG_TPM2_HMAC is enabled and thus its > use should be pooled rather than directly used. This both reduces > latency and improves its predictability. >=20 > 2. Linux is better off overall if every subsystem uses the same source fo= r > generating the random numbers required. >=20 > Thus, unset '.get_random', which causes fallback to kernel_get_random(). >=20 > One might argue that TPM RNG should be used for the generated trusted key= s, > so that they have matching entropy with the TPM internally generated > objects. >=20 > This argument does have some weight into it but as far cryptography goes, > FIPS certification sets the exact bar, not which exact FIPS certified RNG > will be used. Thus, the rational choice is obviously to pick the lowest > latency path, which is kernel RNG. >=20 > Finally, there is an actual defence in depth benefit when using kernel RN= G > as it helps to mitigate TPM firmware bugs concerning RNG implementation, > given the obfuscation by the other entropy sources. >=20 > Reviewed-by: Eric Biggers > Signed-off-by: Jarkko Sakkinen > --- > v7: > - A new patch. Simplifies follow up patches. > --- > security/keys/trusted-keys/trusted_tpm1.c | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) >=20 > diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/tr= usted-keys/trusted_tpm1.c > index 636acb66a4f6..7ce7e31bcdfb 100644 > --- a/security/keys/trusted-keys/trusted_tpm1.c > +++ b/security/keys/trusted-keys/trusted_tpm1.c > @@ -6,6 +6,16 @@ > * See Documentation/security/keys/trusted-encrypted.rst > */ > =20 > +/** > + * DOC: Random Number Generation > + * > + * tpm_get_random() was previously used here as the RNG in order to have= equal > + * entropy with the objects fully inside the TPM. However, as far as goe= s, > + * kernel RNG is equally fine, as long as long as it is FIPS certified. = Also, > + * using kernel RNG has the benefit of mitigating bugs in the TPM firmwa= re > + * associated with the RNG. > + */ If we switch to the kernel RNG that is better, and the TPM one is flawed, I guess we are going to have big problems anyway, since the TPM random number generator is used by the TPM itself internally. I think it makes sense to leave as it is. Thanks Roberto > + > #include > #include > #include > @@ -936,11 +946,6 @@ static int trusted_tpm_unseal(struct trusted_key_pay= load *p, char *datablob) > return ret; > } > =20 > -static int trusted_tpm_get_random(unsigned char *key, size_t key_len) > -{ > - return tpm_get_random(chip, key, key_len); > -} > - > static int __init init_digests(void) > { > int i; > @@ -992,6 +997,5 @@ struct trusted_key_ops trusted_key_tpm_ops =3D { > .init =3D trusted_tpm_init, > .seal =3D trusted_tpm_seal, > .unseal =3D trusted_tpm_unseal, > - .get_random =3D trusted_tpm_get_random, > .exit =3D trusted_tpm_exit, > };