Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2670690ybp; Sat, 5 Oct 2019 17:39:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFKO2Uk64HpBezIeLApMDgMuAnF9E7eYFrlsNljEuuuJtfs/W79hX0H5WYal3Pfa6ypFtX X-Received: by 2002:a05:6402:1355:: with SMTP id y21mr22553153edw.303.1570322383655; Sat, 05 Oct 2019 17:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570322383; cv=none; d=google.com; s=arc-20160816; b=yOwE4r5XYLWGzHEXMbizphIix3D79bfm3dduROofWSLBNMVUOqtx51AAv1ZfY9x5Cs iYiPsjtoykzQ66yXtEL0hP5GccQkJzup7FGFDWicAO9rYwjEd0hDQK2AaZenrjewCLo1 D7HcGq6n6Y8OjSnx/g0UxiAhrwLja9L3zOxGaR4zLy80GAFPfq77iOKJA8elX98FGhPg 6a+Pk1TdwRFrTwAK56FSqYwixp9094C1fEFBfJnY90ZlUc+QzptvQTxtqH3yygcIj/1k VZMvBfFBaHm4uxK0LPLhOYbhUmMcA6aY4WYusrbboK6q83ZXT5yGo6chpSQVlZGS7DTM vleA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:to:from:subject; bh=2O4GrrXcBdZL60DYPqEXpX87Q2O1xAcOn0WvfPLq9DQ=; b=BbHMlNOAk5ytl2M/YN4UYW6dCQgFyfVDzU2hqRHaxGdcXmFSnqtt09rR+XcEOnvGg6 YCFwaCiZY+PmDtxMrNfEl9fLinBF5kKdycVEQDs2VZCjaUEDr2Dqx9K1ibVB9VFODRa7 xSeXjatrtLhakTAGbnn9OaN1optpCHkEMrbIjPs1hRCliU8rMzCoidkfvFqblxoA8RK1 1xUJ9q35C5wRjY9se9zGASV7qlBg2l6g+x4VN7iVORSSwzokIL0gxEZUJMkA2VlG60aL yrFhnkjnyZo6y+QMr1d4+E43TWTFLvu25BQQuzRt0AvCaJKi4rCMxgq18SgIVR1hOkrK pysg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c60si6331359edd.327.2019.10.05.17.39.15; Sat, 05 Oct 2019 17:39:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726957AbfJFAjH (ORCPT + 99 others); Sat, 5 Oct 2019 20:39:07 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:7498 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726921AbfJFAjE (ORCPT ); Sat, 5 Oct 2019 20:39:04 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x960b387118139 for ; Sat, 5 Oct 2019 20:39:02 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2veqbxg86a-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 05 Oct 2019 20:39:02 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 6 Oct 2019 01:39:00 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Sun, 6 Oct 2019 01:38:56 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x960ctYr57671800 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 6 Oct 2019 00:38:55 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 89019A4040; Sun, 6 Oct 2019 00:38:55 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E4502A404D; Sun, 6 Oct 2019 00:38:53 +0000 (GMT) Received: from localhost.localdomain (unknown [9.85.134.152]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Sun, 6 Oct 2019 00:38:53 +0000 (GMT) Subject: Re: [PATCH] KEYS: asym_tpm: Switch to get_random_bytes() From: Mimi Zohar To: James Bottomley , Jerry Snitselaar , Jarkko Sakkinen , David Safford , linux-integrity@vger.kernel.org, stable@vger.kernel.org, David Howells , Herbert Xu , "David S. Miller" , "open list:ASYMMETRIC KEYS" , "open list:CRYPTO API" , open list Date: Sat, 05 Oct 2019 20:38:53 -0400 In-Reply-To: <1570227068.17537.4.camel@HansenPartnership.com> References: <1570128827.5046.19.camel@linux.ibm.com> <20191003215125.GA30511@linux.intel.com> <20191003215743.GB30511@linux.intel.com> <1570140491.5046.33.camel@linux.ibm.com> <1570147177.10818.11.camel@HansenPartnership.com> <20191004182216.GB6945@linux.intel.com> <1570213491.3563.27.camel@HansenPartnership.com> <20191004183342.y63qdvspojyf3m55@cantor> <1570214574.3563.32.camel@HansenPartnership.com> <20191004200728.xoj6jlgbhv57gepc@cantor> <20191004201134.nuesk6hxtxajnxh2@cantor> <1570227068.17537.4.camel@HansenPartnership.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 (3.20.5-1.fc24) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19100600-0012-0000-0000-0000035467BF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19100600-0013-0000-0000-0000218F7549 Message-Id: <1570322333.5046.145.camel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-05_14:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910060003 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Fri, 2019-10-04 at 15:11 -0700, James Bottomley wrote: > + > +/** > + * tpm_get_random() - get random bytes influenced by the TPM's RNG > + * @chip: a &struct tpm_chip instance, %NULL for the default chip > + * @out: destination buffer for the random bytes > + * @max: the max number of bytes to write to @out > + * > + * Uses the TPM as a source of input to the kernel random number > + * generator and then takes @max bytes directly from the kernel. In > + * the worst (no other entropy) case, this will return the pure TPM > + * random number, but if the kernel RNG has any entropy at all it will > + * return a mixed entropy output which doesn't rely on a single > + * source. > + * > + * Return: number of random bytes read or a negative error value. > + */ > +int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max) > +{ > + int rc; > + > + rc = __tpm_get_random(chip, out, max); > + if (rc <= 0) > + return rc; > + /* > + * assume the TPM produces pure randomness, so the amount of > + * entropy is the number of bits returned > + */ > + add_hwgenerator_randomness(out, rc, rc * 8); > + get_random_bytes(out, rc); Using the TPM as a source of input to the kernel random number generator is fine, but please don't change the meaning of trusted keys.  The trusted-encrypted keys documentation clearly states "Trusted Keys use a TPM both to generate and to seal the keys." If you really want to use a different random number source instead of the TPM, then define a new trusted key option (eg. rng=kernel), with the default being the TPM. Mimi > + > + return rc; > +} > EXPORT_SYMBOL_GPL(tpm_get_random);