Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1563876

[PATCH v6 1/2] tpm: implement TPM 2.0 capability to get active PCR banks

From Nayna Jain <nayna@linux.vnet.ibm.com>
Newsgroups linux.kernel
Subject [PATCH v6 1/2] tpm: implement TPM 2.0 capability to get active PCR banks
Date 2017-01-20 20:30 +0100
Message-ID <t1N2N-2Ry-5@gated-at.bofh.it> (permalink)
References <t1LX4-2d6-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


This patch implements the TPM 2.0 capability TPM_CAP_PCRS to
retrieve the active PCR banks from the TPM. This is needed
to enable extending all active banks as recommended by TPM 2.0
TCG Specification.

Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/char/tpm/tpm.h      |  5 ++++
 drivers/char/tpm/tpm2-cmd.c | 59 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 1ae9768..c291f19 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -97,6 +97,7 @@ enum tpm2_return_codes {
 };
 
 enum tpm2_algorithms {
+	TPM2_ALG_ERROR		= 0x0000,
 	TPM2_ALG_SHA1		= 0x0004,
 	TPM2_ALG_KEYEDHASH	= 0x0008,
 	TPM2_ALG_SHA256		= 0x000B,
@@ -127,6 +128,7 @@ enum tpm2_permanent_handles {
 };
 
 enum tpm2_capabilities {
+	TPM2_CAP_PCRS		= 5,
 	TPM2_CAP_TPM_PROPERTIES = 6,
 };
 
@@ -187,6 +189,8 @@ struct tpm_chip {
 
 	const struct attribute_group *groups[3];
 	unsigned int groups_cnt;
+
+	u16 active_banks[7];
 #ifdef CONFIG_ACPI
 	acpi_handle acpi_dev_handle;
 	char ppi_version[TPM_PPI_VERSION_LEN + 1];
@@ -545,4 +549,5 @@ int tpm2_auto_startup(struct tpm_chip *chip);
 void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type);
 unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
 int tpm2_probe(struct tpm_chip *chip);
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
 #endif
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 6eda239..0e000a3 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -998,3 +998,62 @@ int tpm2_auto_startup(struct tpm_chip *chip)
 		rc = -ENODEV;
 	return rc;
 }
+
+struct tpm2_pcr_selection {
+	__be16  hash_alg;
+	u8  size_of_select;
+	u8  pcr_select[3];
+} __packed;
+
+/**
+ * tpm2_get_pcr_allocation() - get TPM active PCR banks.
+ *
+ * @chip: TPM chip to use.
+ *
+ * Return: Same as with tpm_transmit_cmd.
+ */
+ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
+{
+	struct tpm2_pcr_selection pcr_selection;
+	struct tpm_buf buf;
+	void *marker;
+	unsigned int count = 0;
+	int rc;
+	int i;
+
+	rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY);
+	if (rc)
+		return rc;
+
+	tpm_buf_append_u32(&buf, TPM2_CAP_PCRS);
+	tpm_buf_append_u32(&buf, 0);
+	tpm_buf_append_u32(&buf, 1);
+
+	rc = tpm_transmit_cmd(chip, buf.data, PAGE_SIZE, 0,
+			      "get tpm pcr allocation");
+	if (rc < 0)
+		goto out;
+
+	count = be32_to_cpup(
+		(__be32 *)&buf.data[TPM_HEADER_SIZE + 5]);
+
+	if (count > ARRAY_SIZE(chip->active_banks)) {
+		rc = -ENODEV;
+		goto out;
+	}
+
+	marker = &buf.data[TPM_HEADER_SIZE + 9];
+	for (i = 0; i < count; i++) {
+		memcpy(&pcr_selection, marker, sizeof(pcr_selection));
+		chip->active_banks[i] = be16_to_cpu(pcr_selection.hash_alg);
+		marker = marker + sizeof(struct tpm2_pcr_selection);
+	}
+
+out:
+	if (count < ARRAY_SIZE(chip->active_banks))
+		chip->active_banks[count] = TPM2_ALG_ERROR;
+
+	tpm_buf_destroy(&buf);
+
+	return rc;
+}
-- 
2.5.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v6 0/2] enhance TPM 2.0 extend function to support multiple PCR banks  Nayna Jain <nayna@linux.vnet.ibm.com> - 2017-01-20 19:20 +0100
  [PATCH v6 1/2] tpm: implement TPM 2.0 capability to get active PCR banks Nayna Jain <nayna@linux.vnet.ibm.com> - 2017-01-20 20:30 +0100
    Re: [tpmdd-devel] [PATCH v6 1/2] tpm: implement TPM 2.0 capability to  get active PCR banks Stefan Berger <stefanb@linux.vnet.ibm.com> - 2017-01-26 13:30 +0100
      Re: [tpmdd-devel] [PATCH v6 1/2] tpm: implement TPM 2.0 capability  to get active PCR banks Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-01-27 07:40 +0100
  Re: [PATCH v6 0/2] enhance TPM 2.0 extend function to support  multiple PCR banks Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-01-20 22:00 +0100
  [PATCH v6 2/2] tpm: enhance TPM 2.0 PCR extend to support multiple banks Nayna Jain <nayna@linux.vnet.ibm.com> - 2017-01-21 00:00 +0100
    Re: [PATCH v6 2/2] tpm: enhance TPM 2.0 PCR extend to support  multiple banks Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-01-23 16:20 +0100
      Re: [PATCH v6 2/2] tpm: enhance TPM 2.0 PCR extend to support  multiple banks Nayna <nayna@linux.vnet.ibm.com> - 2017-01-23 17:50 +0100
        Re: [PATCH v6 2/2] tpm: enhance TPM 2.0 PCR extend to support  multiple banks Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-01-24 13:00 +0100
          Re: [PATCH v6 2/2] tpm: enhance TPM 2.0 PCR extend to support  multiple banks Nayna <nayna@linux.vnet.ibm.com> - 2017-01-24 14:10 +0100
            Re: [PATCH v6 2/2] tpm: enhance TPM 2.0 PCR extend to support  multiple banks Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-01-25 20:50 +0100
  Re: [PATCH v6 0/2] enhance TPM 2.0 extend function to support  multiple PCR banks Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-01-25 21:50 +0100
    Re: [tpmdd-devel] [PATCH v6 0/2] enhance TPM 2.0 extend function to  support multiple PCR banks Stefan Berger <stefanb@linux.vnet.ibm.com> - 2017-01-25 22:10 +0100
      Re: [tpmdd-devel] [PATCH v6 0/2] enhance TPM 2.0 extend function to  support multiple PCR banks Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-01-25 23:10 +0100
        Re: [tpmdd-devel] [PATCH v6 0/2] enhance TPM 2.0 extend function to  support multiple PCR banks Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-01-26 00:00 +0100
          Re: [tpmdd-devel] [PATCH v6 0/2] enhance TPM 2.0 extend function to  support multiple PCR banks Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-01-26 00:00 +0100
    Re: [PATCH v6 0/2] enhance TPM 2.0 extend function to support  multiple PCR banks Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-01-26 00:40 +0100
      Re: [PATCH v6 0/2] enhance TPM 2.0 extend function to support  multiple PCR banks Nayna <nayna@linux.vnet.ibm.com> - 2017-01-26 15:40 +0100
    Re: [PATCH v6 0/2] enhance TPM 2.0 extend function to support  multiple PCR banks Nayna <nayna@linux.vnet.ibm.com> - 2017-01-27 18:30 +0100
      Re: [PATCH v6 0/2] enhance TPM 2.0 extend function to support  multiple PCR banks Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-01-29 16:20 +0100
    Re: [PATCH v6 0/2] enhance TPM 2.0 extend function to support  multiple PCR banks Nayna <nayna@linux.vnet.ibm.com> - 2017-01-27 19:40 +0100

csiph-web