From patchwork Wed Mar 29 10:24:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 744707 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 3vtP8s42zYz9s1y for ; Wed, 29 Mar 2017 21:27:41 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ctApD-0008Gu-OA; Wed, 29 Mar 2017 10:27:35 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ctApC-0008Gf-1g; Wed, 29 Mar 2017 10:27:34 +0000 Received-SPF: pass (sog-mx-1.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-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1ctApA-00029h-Q6; Wed, 29 Mar 2017 10:27:34 +0000 Received: from 172.18.7.190 (EHLO lhreml705-cah.china.huawei.com) ([172.18.7.190]) by lhrrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DDT38609; Wed, 29 Mar 2017 10:27:25 +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:27:17 +0100 From: Roberto Sassu To: Date: Wed, 29 Mar 2017 12:24:52 +0200 Message-ID: <20170329102452.32212-5-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.0A020201.58DB8C0D.019A, 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: 69097938f4582134862e5a3dd562e698 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: 1ctApA-00029h-Q6 Cc: linux-ima-devel@lists.sourceforge.net Subject: [tpmdd-devel] [PATCH 4/4] tpm: introduce tpm_extend_pcr_digests() 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 Allow TPM users to provide a digest for each PCR bank, for the extend operation. Signed-off-by: Roberto Sassu --- drivers/char/tpm/tpm-interface.c | 31 +++++++++++++++++++++++++++++++ drivers/char/tpm/tpm.h | 6 ------ include/linux/tpm.h | 14 ++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 44e7c99..99789b2 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -876,6 +876,37 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) EXPORT_SYMBOL_GPL(tpm_pcr_extend); /** + * tpm_pcr_extend_digests - extend pcr banks values with provided digests values + * @chip_num: tpm idx # or ANY + * @pcr_idx: pcr idx to extend + * @count: size of array + * @digests: array of tpm2_digest structures + * + * The TPM driver should be built-in, but for whatever reason it + * isn't, protect against the chip disappearing, by incrementing + * the module usage count. + */ +int tpm_pcr_extend_digests(u32 chip_num, int pcr_idx, u32 count, + struct tpm2_digest *digests) +{ + struct tpm_chip *chip; + int rc = -ENODEV; + + chip = tpm_chip_find_get(chip_num); + if (chip == NULL) + return rc; + + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) + goto out; + + rc = tpm2_pcr_extend(chip, pcr_idx, count, digests); +out: + tpm_put_ops(chip); + return rc; +} +EXPORT_SYMBOL_GPL(tpm_pcr_extend_digests); + +/** * tpm_pcr_algorithms - get TPM IDs of active PCR banks algorithms * @chip_num: tpm idx # or ANY * @algorithms: array of TPM IDs diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index f15279b..e130b6d 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -34,7 +34,6 @@ #include #include #include -#include enum tpm_const { TPM_MINOR = 224, /* officially assigned */ @@ -373,11 +372,6 @@ struct tpm_cmd_t { tpm_cmd_params params; } __packed; -struct tpm2_digest { - u16 alg_id; - u8 digest[SHA512_DIGEST_SIZE]; -} __packed; - /* A string buffer type for constructing TPM commands. This is based on the * ideas of string buffer code in security/keys/trusted.h but is heap based * in order to keep the stack usage minimal. diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 6552e43..3e38112 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -22,6 +22,8 @@ #ifndef __LINUX_TPM_H__ #define __LINUX_TPM_H__ +#include + #define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */ #define TPM_ACTIVE_BANKS_MAX 7 /* Max num of active banks for TPM 2.0 */ @@ -34,6 +36,11 @@ struct tpm_chip; struct trusted_key_payload; struct trusted_key_options; +struct tpm2_digest { + u16 alg_id; + u8 digest[SHA512_DIGEST_SIZE]; +} __packed; + enum TPM_OPS_FLAGS { TPM_OPS_AUTO_STARTUP = BIT(0), }; @@ -70,6 +77,8 @@ extern enum tpm2_algorithms tpm2_pcr_algo_from_crypto(enum hash_algo crypto_id); extern int tpm_is_tpm2(u32 chip_num); extern int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf); extern int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash); +extern int tpm_pcr_extend_digests(u32 chip_num, int pcr_idx, u32 count, + struct tpm2_digest *digests); extern int tpm_pcr_algorithms(u32 chip_num, u32 count, enum tpm2_algorithms *algorithms); extern int tpm_send(u32 chip_num, void *cmd, size_t buflen); @@ -100,6 +109,11 @@ static inline int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf) { static inline int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) { return -ENODEV; } +static inline int tpm_pcr_extend_digests(u32 chip_num, int pcr_idx, u32 count, + struct tpm2_digest *digests) +{ + return -ENODEV; +} static inline int tpm_pcr_algorithms(u32 chip_num, u32 count, enum tpm2_algorithms *algorithms) {