From patchwork Wed Mar 29 10:24:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 744704 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vtP710V8xz9s2P for ; Wed, 29 Mar 2017 21:26:05 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ctAne-0003qu-Oa; Wed, 29 Mar 2017 10:25:58 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ctAnd-0003qe-G1; Wed, 29 Mar 2017 10:25:57 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of huawei.com designates 194.213.3.17 as permitted sender) client-ip=194.213.3.17; envelope-from=roberto.sassu@huawei.com; helo=lhrrgout.huawei.com; Received: from lhrrgout.huawei.com ([194.213.3.17]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1ctAnc-0003pu-MM; Wed, 29 Mar 2017 10:25:57 +0000 Received: from 172.18.7.190 (EHLO lhreml705-cah.china.huawei.com) ([172.18.7.190]) by lhrrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DJW89170; Wed, 29 Mar 2017 10:25:49 +0000 (GMT) Received: from sgx1.huawei.com (10.204.66.17) by smtpsuk.huawei.com (10.201.108.46) with Microsoft SMTP Server (TLS) id 14.3.301.0; Wed, 29 Mar 2017 11:25:42 +0100 From: Roberto Sassu To: Date: Wed, 29 Mar 2017 12:24:49 +0200 Message-ID: <20170329102452.32212-2-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170329102452.32212-1-roberto.sassu@huawei.com> References: <20170329102452.32212-1-roberto.sassu@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.204.66.17] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.58DB8BAD.012D, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 55aa52dd3026355fb9f897e4a3a74cc3 X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1ctAnc-0003pu-MM Cc: linux-ima-devel@lists.sourceforge.net Subject: [tpmdd-devel] [PATCH 1/4] tpm: check whether all digests have been provided for TPM 2.0 extend X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces@lists.sourceforge.net TCG mandates that all PCR banks must be extended during the same operation. tpm2_pcr_extend() will check whether all digests have been provided. The check is necessary because tpm2_pcr_extend() will be called by a new function, allowing callers to provide a digest for each PCR bank. Signed-off-by: Roberto Sassu --- drivers/char/tpm/tpm2-cmd.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index 881aea9..f4d534c 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -284,6 +284,26 @@ struct tpm2_null_auth_area { __be16 auth_size; } __packed; +static bool tpm2_digests_all_banks(struct tpm_chip *chip, u32 count, + struct tpm2_digest *digests) +{ + int i, j; + + for (i = 0; i < ARRAY_SIZE(chip->active_banks) && + chip->active_banks[i] != TPM2_ALG_ERROR; i++) { + for (j = 0; j < count; j++) + if (digests[j].alg_id == chip->active_banks[i]) + break; + if (j == count) { + pr_err("missing TPM algorithm 0x%x\n", + chip->active_banks[i]); + return false; + } + } + + return true; +} + /** * tpm2_pcr_extend() - extend a PCR value * @@ -306,6 +326,9 @@ int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count, if (count > ARRAY_SIZE(chip->active_banks)) return -EINVAL; + if (!tpm2_digests_all_banks(chip, count, digests)) + return -EINVAL; + rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_PCR_EXTEND); if (rc) return rc;