From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roberto Sassu Date: Wed, 21 Jun 2017 14:29:40 +0000 Subject: [PATCH v3 5/6] tpm: introduce tpm_get_pcr_banks_info() Message-Id: <20170621142941.32674-6-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit List-Id: References: <20170621142941.32674-1-roberto.sassu@huawei.com> In-Reply-To: <20170621142941.32674-1-roberto.sassu@huawei.com> To: linux-security-module@vger.kernel.org This function copies the array of tpm_pcr_bank_info structures to the memory address specified by the caller. It assumes that the caller allocated an array with the same number of elements of the active_banks array (member of the tpm_chip structure). This number is defined in include/linux/tpm.h (TPM_ACTIVE_BANKS_MAX definition). A tpm_pcr_bank_info structure is also returned if the TPM version is 1.2. The advantage of this choice is that the code for extending a PCR with multiple digests will work regardless of the TPM version. Signed-off-by: Roberto Sassu --- drivers/char/tpm/tpm-interface.c | 33 +++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm.h | 2 +- include/linux/tpm.h | 8 ++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index a11598a..cf0cdb2 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -916,6 +916,39 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) EXPORT_SYMBOL_GPL(tpm_pcr_extend); /** + * tpm_get_pcr_banks_info() - get PCR banks information + * @chip_num: tpm idx # or ANY + * @active_banks: array of tpm_pcr_bank_info structures + * + * Return: < 0 on error, and the number of active PCR banks on success. + */ +int tpm_get_pcr_banks_info(u32 chip_num, struct tpm_pcr_bank_info *active_banks) +{ + struct tpm_chip *chip; + int count = 1; + + chip = tpm_chip_find_get(chip_num); + if (chip = NULL) + return -ENODEV; + + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { + active_banks[0].alg_id = TPM2_ALG_SHA1; + active_banks[0].crypto_id = HASH_ALGO_SHA1; + active_banks[0].digest_size = hash_digest_size[HASH_ALGO_SHA1]; + goto out; + } + + for (count = 0; count < ARRAY_SIZE(chip->active_banks) && + chip->active_banks[count].alg_id != TPM2_ALG_ERROR; count++) + memcpy(&active_banks[count], &chip->active_banks[count], + sizeof(*active_banks)); +out: + tpm_put_ops(chip); + return count; +} +EXPORT_SYMBOL_GPL(tpm_get_pcr_banks_info); + +/** * tpm_do_selftest - have the TPM continue its selftest and wait until it * can receive further commands * @chip: TPM chip to use diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index d285bc6..75ec0d1 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -208,7 +208,7 @@ struct tpm_chip { const struct attribute_group *groups[3]; unsigned int groups_cnt; - struct tpm_pcr_bank_info active_banks[7]; + struct tpm_pcr_bank_info active_banks[TPM_ACTIVE_BANKS_MAX]; #ifdef CONFIG_ACPI acpi_handle acpi_dev_handle; char ppi_version[TPM_PPI_VERSION_LEN + 1]; diff --git a/include/linux/tpm.h b/include/linux/tpm.h index ff06738..49ec8fc 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -25,6 +25,7 @@ #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 */ /* * Chip num is this value or a valid tpm idx @@ -76,6 +77,8 @@ struct tpm_pcr_bank_info { 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_get_pcr_banks_info(u32 chip_num, + struct tpm_pcr_bank_info *active_banks); extern int tpm_send(u32 chip_num, void *cmd, size_t buflen); extern int tpm_get_random(u32 chip_num, u8 *data, size_t max); extern int tpm_seal_trusted(u32 chip_num, @@ -95,6 +98,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_get_pcr_banks_info(u32 chip_num, + struct tpm_pcr_bank_info *active_banks) +{ + return -ENODEV; +} static inline int tpm_send(u32 chip_num, void *cmd, size_t buflen) { return -ENODEV; } -- 2.9.3 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752871AbdFUOew (ORCPT ); Wed, 21 Jun 2017 10:34:52 -0400 Received: from lhrrgout.huawei.com ([194.213.3.17]:29087 "EHLO lhrrgout.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751754AbdFUOet (ORCPT ); Wed, 21 Jun 2017 10:34:49 -0400 From: Roberto Sassu To: CC: , , , , Roberto Sassu Subject: [PATCH v3 5/6] tpm: introduce tpm_get_pcr_banks_info() Date: Wed, 21 Jun 2017 16:29:40 +0200 Message-ID: <20170621142941.32674-6-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170621142941.32674-1-roberto.sassu@huawei.com> References: <20170621142941.32674-1-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.204.65.245] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.594A8402.003C,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: 657eb80c4d1e23e58c98d3580efaa439 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function copies the array of tpm_pcr_bank_info structures to the memory address specified by the caller. It assumes that the caller allocated an array with the same number of elements of the active_banks array (member of the tpm_chip structure). This number is defined in include/linux/tpm.h (TPM_ACTIVE_BANKS_MAX definition). A tpm_pcr_bank_info structure is also returned if the TPM version is 1.2. The advantage of this choice is that the code for extending a PCR with multiple digests will work regardless of the TPM version. Signed-off-by: Roberto Sassu --- drivers/char/tpm/tpm-interface.c | 33 +++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm.h | 2 +- include/linux/tpm.h | 8 ++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index a11598a..cf0cdb2 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -916,6 +916,39 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) EXPORT_SYMBOL_GPL(tpm_pcr_extend); /** + * tpm_get_pcr_banks_info() - get PCR banks information + * @chip_num: tpm idx # or ANY + * @active_banks: array of tpm_pcr_bank_info structures + * + * Return: < 0 on error, and the number of active PCR banks on success. + */ +int tpm_get_pcr_banks_info(u32 chip_num, struct tpm_pcr_bank_info *active_banks) +{ + struct tpm_chip *chip; + int count = 1; + + chip = tpm_chip_find_get(chip_num); + if (chip == NULL) + return -ENODEV; + + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { + active_banks[0].alg_id = TPM2_ALG_SHA1; + active_banks[0].crypto_id = HASH_ALGO_SHA1; + active_banks[0].digest_size = hash_digest_size[HASH_ALGO_SHA1]; + goto out; + } + + for (count = 0; count < ARRAY_SIZE(chip->active_banks) && + chip->active_banks[count].alg_id != TPM2_ALG_ERROR; count++) + memcpy(&active_banks[count], &chip->active_banks[count], + sizeof(*active_banks)); +out: + tpm_put_ops(chip); + return count; +} +EXPORT_SYMBOL_GPL(tpm_get_pcr_banks_info); + +/** * tpm_do_selftest - have the TPM continue its selftest and wait until it * can receive further commands * @chip: TPM chip to use diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index d285bc6..75ec0d1 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -208,7 +208,7 @@ struct tpm_chip { const struct attribute_group *groups[3]; unsigned int groups_cnt; - struct tpm_pcr_bank_info active_banks[7]; + struct tpm_pcr_bank_info active_banks[TPM_ACTIVE_BANKS_MAX]; #ifdef CONFIG_ACPI acpi_handle acpi_dev_handle; char ppi_version[TPM_PPI_VERSION_LEN + 1]; diff --git a/include/linux/tpm.h b/include/linux/tpm.h index ff06738..49ec8fc 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -25,6 +25,7 @@ #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 */ /* * Chip num is this value or a valid tpm idx @@ -76,6 +77,8 @@ struct tpm_pcr_bank_info { 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_get_pcr_banks_info(u32 chip_num, + struct tpm_pcr_bank_info *active_banks); extern int tpm_send(u32 chip_num, void *cmd, size_t buflen); extern int tpm_get_random(u32 chip_num, u8 *data, size_t max); extern int tpm_seal_trusted(u32 chip_num, @@ -95,6 +98,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_get_pcr_banks_info(u32 chip_num, + struct tpm_pcr_bank_info *active_banks) +{ + return -ENODEV; +} static inline int tpm_send(u32 chip_num, void *cmd, size_t buflen) { return -ENODEV; } -- 2.9.3 From mboxrd@z Thu Jan 1 00:00:00 1970 From: roberto.sassu@huawei.com (Roberto Sassu) Date: Wed, 21 Jun 2017 16:29:40 +0200 Subject: [PATCH v3 5/6] tpm: introduce tpm_get_pcr_banks_info() In-Reply-To: <20170621142941.32674-1-roberto.sassu@huawei.com> References: <20170621142941.32674-1-roberto.sassu@huawei.com> Message-ID: <20170621142941.32674-6-roberto.sassu@huawei.com> To: linux-security-module@vger.kernel.org List-Id: linux-security-module.vger.kernel.org This function copies the array of tpm_pcr_bank_info structures to the memory address specified by the caller. It assumes that the caller allocated an array with the same number of elements of the active_banks array (member of the tpm_chip structure). This number is defined in include/linux/tpm.h (TPM_ACTIVE_BANKS_MAX definition). A tpm_pcr_bank_info structure is also returned if the TPM version is 1.2. The advantage of this choice is that the code for extending a PCR with multiple digests will work regardless of the TPM version. Signed-off-by: Roberto Sassu --- drivers/char/tpm/tpm-interface.c | 33 +++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm.h | 2 +- include/linux/tpm.h | 8 ++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index a11598a..cf0cdb2 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -916,6 +916,39 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) EXPORT_SYMBOL_GPL(tpm_pcr_extend); /** + * tpm_get_pcr_banks_info() - get PCR banks information + * @chip_num: tpm idx # or ANY + * @active_banks: array of tpm_pcr_bank_info structures + * + * Return: < 0 on error, and the number of active PCR banks on success. + */ +int tpm_get_pcr_banks_info(u32 chip_num, struct tpm_pcr_bank_info *active_banks) +{ + struct tpm_chip *chip; + int count = 1; + + chip = tpm_chip_find_get(chip_num); + if (chip == NULL) + return -ENODEV; + + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { + active_banks[0].alg_id = TPM2_ALG_SHA1; + active_banks[0].crypto_id = HASH_ALGO_SHA1; + active_banks[0].digest_size = hash_digest_size[HASH_ALGO_SHA1]; + goto out; + } + + for (count = 0; count < ARRAY_SIZE(chip->active_banks) && + chip->active_banks[count].alg_id != TPM2_ALG_ERROR; count++) + memcpy(&active_banks[count], &chip->active_banks[count], + sizeof(*active_banks)); +out: + tpm_put_ops(chip); + return count; +} +EXPORT_SYMBOL_GPL(tpm_get_pcr_banks_info); + +/** * tpm_do_selftest - have the TPM continue its selftest and wait until it * can receive further commands * @chip: TPM chip to use diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index d285bc6..75ec0d1 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -208,7 +208,7 @@ struct tpm_chip { const struct attribute_group *groups[3]; unsigned int groups_cnt; - struct tpm_pcr_bank_info active_banks[7]; + struct tpm_pcr_bank_info active_banks[TPM_ACTIVE_BANKS_MAX]; #ifdef CONFIG_ACPI acpi_handle acpi_dev_handle; char ppi_version[TPM_PPI_VERSION_LEN + 1]; diff --git a/include/linux/tpm.h b/include/linux/tpm.h index ff06738..49ec8fc 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -25,6 +25,7 @@ #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 */ /* * Chip num is this value or a valid tpm idx @@ -76,6 +77,8 @@ struct tpm_pcr_bank_info { 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_get_pcr_banks_info(u32 chip_num, + struct tpm_pcr_bank_info *active_banks); extern int tpm_send(u32 chip_num, void *cmd, size_t buflen); extern int tpm_get_random(u32 chip_num, u8 *data, size_t max); extern int tpm_seal_trusted(u32 chip_num, @@ -95,6 +98,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_get_pcr_banks_info(u32 chip_num, + struct tpm_pcr_bank_info *active_banks) +{ + return -ENODEV; +} static inline int tpm_send(u32 chip_num, void *cmd, size_t buflen) { return -ENODEV; } -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roberto Sassu Subject: [PATCH v3 5/6] tpm: introduce tpm_get_pcr_banks_info() Date: Wed, 21 Jun 2017 16:29:40 +0200 Message-ID: <20170621142941.32674-6-roberto.sassu@huawei.com> References: <20170621142941.32674-1-roberto.sassu@huawei.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <20170621142941.32674-1-roberto.sassu@huawei.com> Sender: linux-kernel-owner@vger.kernel.org To: tpmdd-devel@lists.sourceforge.net Cc: linux-ima-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, Roberto Sassu List-Id: tpmdd-devel@lists.sourceforge.net This function copies the array of tpm_pcr_bank_info structures to the memory address specified by the caller. It assumes that the caller allocated an array with the same number of elements of the active_banks array (member of the tpm_chip structure). This number is defined in include/linux/tpm.h (TPM_ACTIVE_BANKS_MAX definition). A tpm_pcr_bank_info structure is also returned if the TPM version is 1.2. The advantage of this choice is that the code for extending a PCR with multiple digests will work regardless of the TPM version. Signed-off-by: Roberto Sassu --- drivers/char/tpm/tpm-interface.c | 33 +++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm.h | 2 +- include/linux/tpm.h | 8 ++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index a11598a..cf0cdb2 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -916,6 +916,39 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash) EXPORT_SYMBOL_GPL(tpm_pcr_extend); /** + * tpm_get_pcr_banks_info() - get PCR banks information + * @chip_num: tpm idx # or ANY + * @active_banks: array of tpm_pcr_bank_info structures + * + * Return: < 0 on error, and the number of active PCR banks on success. + */ +int tpm_get_pcr_banks_info(u32 chip_num, struct tpm_pcr_bank_info *active_banks) +{ + struct tpm_chip *chip; + int count = 1; + + chip = tpm_chip_find_get(chip_num); + if (chip == NULL) + return -ENODEV; + + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { + active_banks[0].alg_id = TPM2_ALG_SHA1; + active_banks[0].crypto_id = HASH_ALGO_SHA1; + active_banks[0].digest_size = hash_digest_size[HASH_ALGO_SHA1]; + goto out; + } + + for (count = 0; count < ARRAY_SIZE(chip->active_banks) && + chip->active_banks[count].alg_id != TPM2_ALG_ERROR; count++) + memcpy(&active_banks[count], &chip->active_banks[count], + sizeof(*active_banks)); +out: + tpm_put_ops(chip); + return count; +} +EXPORT_SYMBOL_GPL(tpm_get_pcr_banks_info); + +/** * tpm_do_selftest - have the TPM continue its selftest and wait until it * can receive further commands * @chip: TPM chip to use diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index d285bc6..75ec0d1 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -208,7 +208,7 @@ struct tpm_chip { const struct attribute_group *groups[3]; unsigned int groups_cnt; - struct tpm_pcr_bank_info active_banks[7]; + struct tpm_pcr_bank_info active_banks[TPM_ACTIVE_BANKS_MAX]; #ifdef CONFIG_ACPI acpi_handle acpi_dev_handle; char ppi_version[TPM_PPI_VERSION_LEN + 1]; diff --git a/include/linux/tpm.h b/include/linux/tpm.h index ff06738..49ec8fc 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -25,6 +25,7 @@ #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 */ /* * Chip num is this value or a valid tpm idx @@ -76,6 +77,8 @@ struct tpm_pcr_bank_info { 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_get_pcr_banks_info(u32 chip_num, + struct tpm_pcr_bank_info *active_banks); extern int tpm_send(u32 chip_num, void *cmd, size_t buflen); extern int tpm_get_random(u32 chip_num, u8 *data, size_t max); extern int tpm_seal_trusted(u32 chip_num, @@ -95,6 +98,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_get_pcr_banks_info(u32 chip_num, + struct tpm_pcr_bank_info *active_banks) +{ + return -ENODEV; +} static inline int tpm_send(u32 chip_num, void *cmd, size_t buflen) { return -ENODEV; } -- 2.9.3