Skip to contentSkip to conversation

tpm, tpm_tis: fix TPM 2.0 probing

PATCH In review Jarkko Sakkinen 3 participants 8 messages Feb 4, 2015 – Feb 12, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm, tpm_tis: fix TPM 2.0 probing

If during transmission system error was returned, the logic was to incorrectly deduce that chip is a TPM 1.x chip. This patch fixes this issue. Also, this patch changes probing so that message tag is used as the measure for TPM 2.x, which should be much more stable. A separate function called tpm2_probe() is encapsulated because it can be used with any chipset.

---
 drivers/char/tpm/tpm.h      |  3 ++-
 drivers/char/tpm/tpm2-cmd.c | 40 +++++++++++++++++++++++++++++++++-------
 drivers/char/tpm/tpm_tis.c  | 11 ++++-------
 3 files changed, 39 insertions(+), 15 deletions(-)
drivers/char/tpm/tpm.h +2 -1
index 7b0727c..a4b0f5e 100644
@@ -435,4 +435,5 @@ extern int tpm2_startup(struct tpm_chip *chip, u16 startup_type);
 extern int tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type);
 extern unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *, u32);
 extern int tpm2_do_selftest(struct tpm_chip *chip);
-extern int tpm2_gen_interrupt(struct tpm_chip *chip, bool quiet);
+extern int tpm2_gen_interrupt(struct tpm_chip *chip);
+extern int tpm2_probe(struct tpm_chip *chip);
drivers/char/tpm/tpm2-cmd.c +33 -7
index 1abe650..49cd354 100644
@@ -598,20 +598,46 @@ EXPORT_SYMBOL_GPL(tpm2_do_selftest);
 /**
  * tpm2_gen_interrupt() - generate an interrupt
  * @chip: TPM chip to use
- * @quiet: surpress the error message
  *
  * 0 is returned when the operation is successful. If a negative number is
  * returned it remarks a POSIX error code. If a positive number is returned
  * it remarks a TPM error.
  */
-int tpm2_gen_interrupt(struct tpm_chip *chip, bool quiet)
+int tpm2_gen_interrupt(struct tpm_chip *chip)
 {
-	const char *desc = NULL;
 	u32 dummy;
 
-	if (!quiet)
-		desc = "attempting to generate an interrupt";
-
-	return tpm2_get_tpm_pt(chip, TPM2_CAP_TPM_PROPERTIES, &dummy, desc);
+	return tpm2_get_tpm_pt(chip, 0x100, &dummy,
+			       "attempting to generate an interrupt");
 }
 EXPORT_SYMBOL_GPL(tpm2_gen_interrupt);
+
+/**
+ * tpm2_probe() - probe TPM 2.0
+ * @chip: TPM chip to use
+ *
+ * Send idempotent TPM 2.0 command and see whether TPM 2.0 chip replied based on
+ * the reply tag.
+ */
+int tpm2_probe(struct tpm_chip *chip)
+{
+	struct tpm2_cmd cmd;
+	int rc;
+
+	cmd.header.in = tpm2_get_tpm_pt_header;
+	cmd.params.get_tpm_pt_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
+	cmd.params.get_tpm_pt_in.property_id = cpu_to_be32(0x100);
+	cmd.params.get_tpm_pt_in.property_cnt = cpu_to_be32(1);
+
+	rc = tpm_transmit(chip, (const char *) &cmd, sizeof(cmd));
+	if (rc <  0)
+		return rc;
+	else if (rc < TPM_HEADER_SIZE)
+		return -EFAULT;
+
+	if (be16_to_cpu(cmd.header.out.tag) == TPM2_ST_NO_SESSIONS)
+		chip->flags |= TPM_CHIP_FLAG_TPM2;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(tpm2_probe);
drivers/char/tpm/tpm_tis.c +4 -7
index 6725bef..ee6e0bd 100644
@@ -639,12 +639,9 @@ static int tpm_tis_init(struct device *dev, acpi_handle acpi_dev_handle,
 		goto out_err;
 	}
 
-	/* Every TPM 2.x command has a higher ordinal than TPM 1.x commands.
-	 * Therefore, we can use an idempotent TPM 2.x command to probe TPM 2.x.
-	 */
-	rc = tpm2_gen_interrupt(chip, true);
-	if (rc == 0 || rc == TPM2_RC_INITIALIZE)
-		chip->flags |= TPM_CHIP_FLAG_TPM2;
+	rc = tpm2_probe(chip);
+	if (rc)
+		goto out_err;
 
 	vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0));
 	chip->vendor.manufacturer_id = vendor;
@@ -747,7 +744,7 @@ static int tpm_tis_init(struct device *dev, acpi_handle acpi_dev_handle,
 
 			/* Generate Interrupts */
 			if (chip->flags & TPM_CHIP_FLAG_TPM2)
-				tpm2_gen_interrupt(chip, false);
+				tpm2_gen_interrupt(chip);
 			else
 				tpm_gen_interrupt(chip);
 
Signature · 1 line
2.1.4
maintainer
#1 lore raw

Am Mittwoch, 4. Februar 2015, 15:21:09 schrieb Jarkko Sakkinen:

Quoted 4 lines

If during transmission system error was returned, the logic was to incorrectly deduce that chip is a TPM 1.x chip. This patch fixes this issue. Also, this patch changes probing so that message tag is used as the measure for TPM 2.x, which should be much more stable.

Is it aware that some TPMs may respond with 0x00C1 as TAG for TPM1.2 commands?

Quoted 39 lines

A separate function
called tpm2_probe() is encapsulated because it can be used with any chipset.

---
 drivers/char/tpm/tpm.h      |  3 ++-
 drivers/char/tpm/tpm2-cmd.c | 40 +++++++++++++++++++++++++++++++++-------
 drivers/char/tpm/tpm_tis.c  | 11 ++++-------
 3 files changed, 39 insertions(+), 15 deletions(-)
drivers/char/tpm/tpm.h +0 -0
index 7b0727c..a4b0f5e 100644
@@ -435,4 +435,5 @@ extern int tpm2_startup(struct tpm_chip *chip, u16

startup_type); extern int tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); extern unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *, u32); extern int tpm2_do_selftest(struct tpm_chip *chip);

drivers/char/tpm/tpm.h +2 -1
-extern int tpm2_gen_interrupt(struct tpm_chip *chip, bool quiet);
+extern int tpm2_gen_interrupt(struct tpm_chip *chip);
+extern int tpm2_probe(struct tpm_chip *chip);
drivers/char/tpm/tpm2-cmd.c +0 -1
index 1abe650..49cd354 100644
@@ -598,20 +598,46 @@ EXPORT_SYMBOL_GPL(tpm2_do_selftest);
 /**
  * tpm2_gen_interrupt() - generate an interrupt
  * @chip: TPM chip to use
- * @quiet: surpress the error message
  *
  * 0 is returned when the operation is successful. If a negative number is
  * returned it remarks a POSIX error code. If a positive number is

returned * it remarks a TPM error.
*/

drivers/char/tpm/tpm2-cmd.c +1 -1
-int tpm2_gen_interrupt(struct tpm_chip *chip, bool quiet)
+int tpm2_gen_interrupt(struct tpm_chip *chip)

drivers/char/tpm/tpm2-cmd.c EXPORT_SYMBOL_GPL(tpm2_do_selftest); · line 611

Quoted 10 lines
drivers/char/tpm/tpm2-cmd.c +2 -5
 {
-	const char *desc = NULL;
 	u32 dummy;
 
-	if (!quiet)
-		desc = "attempting to generate an interrupt";
-
-	return tpm2_get_tpm_pt(chip, TPM2_CAP_TPM_PROPERTIES, &dummy, desc);
+	return tpm2_get_tpm_pt(chip, 0x100, &dummy,
+			       "attempting to generate an interrupt");

Why the change from TPM2_CAP_TPM_PROPERTIES = 6 to 0x100 and what does 0x100 stand for?

Quoted 61 lines

}
EXPORT_SYMBOL_GPL(tpm2_gen_interrupt);

drivers/char/tpm/tpm2-cmd.c +6 -0
+
+/**
+ * tpm2_probe() - probe TPM 2.0
+ * @chip: TPM chip to use
+ *
+ * Send idempotent TPM 2.0 command and see whether TPM 2.0 chip replied

based on + * the reply tag.
+ */

drivers/char/tpm/tpm2-cmd.c +22 -0
+int tpm2_probe(struct tpm_chip *chip)
+{
+	struct tpm2_cmd cmd;
+	int rc;
+
+	cmd.header.in = tpm2_get_tpm_pt_header;
+	cmd.params.get_tpm_pt_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
+	cmd.params.get_tpm_pt_in.property_id = cpu_to_be32(0x100);
+	cmd.params.get_tpm_pt_in.property_cnt = cpu_to_be32(1);
+
+	rc = tpm_transmit(chip, (const char *) &cmd, sizeof(cmd));
+	if (rc <  0)
+		return rc;
+	else if (rc < TPM_HEADER_SIZE)
+		return -EFAULT;
+
+	if (be16_to_cpu(cmd.header.out.tag) == TPM2_ST_NO_SESSIONS)
+		chip->flags |= TPM_CHIP_FLAG_TPM2;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(tpm2_probe);
drivers/char/tpm/tpm_tis.c +4 -7
index 6725bef..ee6e0bd 100644
@@ -639,12 +639,9 @@ static int tpm_tis_init(struct device *dev,
 acpi_handle acpi_dev_handle, goto out_err;
 	}
 
-	/* Every TPM 2.x command has a higher ordinal than TPM 1.x commands.
-	 * Therefore, we can use an idempotent TPM 2.x command to probe TPM 2.x.
-	 */
-	rc = tpm2_gen_interrupt(chip, true);
-	if (rc == 0 || rc == TPM2_RC_INITIALIZE)
-		chip->flags |= TPM_CHIP_FLAG_TPM2;
+	rc = tpm2_probe(chip);
+	if (rc)
+		goto out_err;
 
 	vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0));
 	chip->vendor.manufacturer_id = vendor;
@@ -747,7 +744,7 @@ static int tpm_tis_init(struct device *dev, acpi_handle
 acpi_dev_handle,
 
 			/* Generate Interrupts */
 			if (chip->flags & TPM_CHIP_FLAG_TPM2)
-				tpm2_gen_interrupt(chip, false);
+				tpm2_gen_interrupt(chip);
 			else
 				tpm_gen_interrupt(chip);
#2 lore raw
Quoted 6 lines · Peter Hüwe

Am Mittwoch, 4. Februar 2015, 15:21:09 schrieb Jarkko Sakkinen:

Quoted 4 lines

If during transmission system error was returned, the logic was to incorrectly deduce that chip is a TPM 1.x chip. This patch fixes this issue. Also, this patch changes probing so that message tag is used as the measure for TPM 2.x, which should be much more stable.

Is it aware that some TPMs may respond with 0x00C1 as TAG for TPM1.2 commands?

I guess none of the TPM 1.2 command answer with the tag 0x8002?

Quoted 43 lines
Quoted 43 lines

A separate function
called tpm2_probe() is encapsulated because it can be used with any chipset.

---
 drivers/char/tpm/tpm.h      |  3 ++-
 drivers/char/tpm/tpm2-cmd.c | 40 +++++++++++++++++++++++++++++++++-------
 drivers/char/tpm/tpm_tis.c  | 11 ++++-------
 3 files changed, 39 insertions(+), 15 deletions(-)
drivers/char/tpm/tpm.h +0 -0
index 7b0727c..a4b0f5e 100644
@@ -435,4 +435,5 @@ extern int tpm2_startup(struct tpm_chip *chip, u16

startup_type); extern int tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); extern unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *, u32); extern int tpm2_do_selftest(struct tpm_chip *chip);

drivers/char/tpm/tpm.h +2 -1
-extern int tpm2_gen_interrupt(struct tpm_chip *chip, bool quiet);
+extern int tpm2_gen_interrupt(struct tpm_chip *chip);
+extern int tpm2_probe(struct tpm_chip *chip);
drivers/char/tpm/tpm2-cmd.c +0 -1
index 1abe650..49cd354 100644
@@ -598,20 +598,46 @@ EXPORT_SYMBOL_GPL(tpm2_do_selftest);
 /**
  * tpm2_gen_interrupt() - generate an interrupt
  * @chip: TPM chip to use
- * @quiet: surpress the error message
  *
  * 0 is returned when the operation is successful. If a negative number is
  * returned it remarks a POSIX error code. If a positive number is

returned * it remarks a TPM error.
*/

drivers/char/tpm/tpm2-cmd.c +1 -2
-int tpm2_gen_interrupt(struct tpm_chip *chip, bool quiet)
+int tpm2_gen_interrupt(struct tpm_chip *chip)
 {
-	const char *desc = NULL;
 	u32 dummy;
Quoted 8 lines

drivers/char/tpm/tpm2-cmd.c EXPORT_SYMBOL_GPL(tpm2_do_selftest); · line 611

Quoted 6 lines
drivers/char/tpm/tpm2-cmd.c +2 -4
-	if (!quiet)
-		desc = "attempting to generate an interrupt";
-
-	return tpm2_get_tpm_pt(chip, TPM2_CAP_TPM_PROPERTIES, &dummy, desc);
+	return tpm2_get_tpm_pt(chip, 0x100, &dummy,
+			       "attempting to generate an interrupt");

Why the change from TPM2_CAP_TPM_PROPERTIES = 6 to 0x100 and what does 0x100 stand for?

In TPM 2.0 there are two levels: capabilities and properties. Using capability ID of "TPM properties" property set was a sloppy mistake although it didn't matter because interrupt is still generate.

The properties in the "TPM properties" property set start with the index 0x100.

Quoted 55 lines
Quoted 55 lines

}
EXPORT_SYMBOL_GPL(tpm2_gen_interrupt);

drivers/char/tpm/tpm2-cmd.c +6 -0
+
+/**
+ * tpm2_probe() - probe TPM 2.0
+ * @chip: TPM chip to use
+ *
+ * Send idempotent TPM 2.0 command and see whether TPM 2.0 chip replied

based on + * the reply tag.
+ */

drivers/char/tpm/tpm2-cmd.c +22 -0
+int tpm2_probe(struct tpm_chip *chip)
+{
+	struct tpm2_cmd cmd;
+	int rc;
+
+	cmd.header.in = tpm2_get_tpm_pt_header;
+	cmd.params.get_tpm_pt_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES);
+	cmd.params.get_tpm_pt_in.property_id = cpu_to_be32(0x100);
+	cmd.params.get_tpm_pt_in.property_cnt = cpu_to_be32(1);
+
+	rc = tpm_transmit(chip, (const char *) &cmd, sizeof(cmd));
+	if (rc <  0)
+		return rc;
+	else if (rc < TPM_HEADER_SIZE)
+		return -EFAULT;
+
+	if (be16_to_cpu(cmd.header.out.tag) == TPM2_ST_NO_SESSIONS)
+		chip->flags |= TPM_CHIP_FLAG_TPM2;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(tpm2_probe);
drivers/char/tpm/tpm_tis.c +3 -6
index 6725bef..ee6e0bd 100644
@@ -639,12 +639,9 @@ static int tpm_tis_init(struct device *dev,
 acpi_handle acpi_dev_handle, goto out_err;
 	}
 
-	/* Every TPM 2.x command has a higher ordinal than TPM 1.x commands.
-	 * Therefore, we can use an idempotent TPM 2.x command to probe TPM 2.x.
-	 */
-	rc = tpm2_gen_interrupt(chip, true);
-	if (rc == 0 || rc == TPM2_RC_INITIALIZE)
-		chip->flags |= TPM_CHIP_FLAG_TPM2;
+	rc = tpm2_probe(chip);
+	if (rc)
+		goto out_err;
 
 	vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0));
 	chip->vendor.manufacturer_id = vendor;
@@ -747,7 +744,7 @@ static int tpm_tis_init(struct device *dev, acpi_handle
 acpi_dev_handle,
 
Quoted 6 lines

drivers/char/tpm/tpm_tis.c static int tpm_tis_init(struct device *dev, acpi_handle acpi_dev_handle, · line 749

Quoted 6 lines
drivers/char/tpm/tpm_tis.c +1 -1
 			/* Generate Interrupts */
 			if (chip->flags & TPM_CHIP_FLAG_TPM2)
-				tpm2_gen_interrupt(chip, false);
+				tpm2_gen_interrupt(chip);
 			else
 				tpm_gen_interrupt(chip);

/Jarkko

#3 lore raw

Ok, good.
I'll apply it later today.
Peter

Signature · 1 line
Sent from my mobile.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/

_______________________________________________
TrouSerS-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/trousers-tech

#4 lore raw
In reply to Jarkko Sakkinen
Quoted 8 lines · Jarkko Sakkinen
Quoted 6 lines · Peter Hüwe

Am Mittwoch, 4. Februar 2015, 15:21:09 schrieb Jarkko Sakkinen:

Quoted 4 lines

If during transmission system error was returned, the logic was to incorrectly deduce that chip is a TPM 1.x chip. This patch fixes this issue. Also, this patch changes probing so that message tag is used as the measure for TPM 2.x, which should be much more stable.

Is it aware that some TPMs may respond with 0x00C1 as TAG for TPM1.2 commands?

I guess none of the TPM 1.2 command answer with the tag 0x8002?

FYI: pdf page 26 , section 6.1 explains the predictable return value for a TPM1.2 command seen by a TPM2

http://www.trustedcomputinggroup.org/files/static_page_files/8C68ADA8-1A4B-B294-D0FC06D3773F7DAA/TPM%20Rev%202.0%20Part%203%20-%20Commands%2001.16-code.pdf

Following this:

Sending a TPM1.2 command to a TPM2 should return a TPM1.2 header (tag = 0xc4) and error code (TPM_BADTAG = 0x1e)

Sending a TPM 2 command to a TPM 2 will give a TPM 2 tag in the header. Sending a TPM 2 command to a TPM 1.2 will give a TPM 1.2 tag in the header and an error code.

Stefan

#5 lore raw
Quoted 16 lines · Stefan Berger
Quoted 8 lines · Jarkko Sakkinen
Quoted 6 lines · Peter Hüwe

Am Mittwoch, 4. Februar 2015, 15:21:09 schrieb Jarkko Sakkinen:

Quoted 4 lines

If during transmission system error was returned, the logic was to incorrectly deduce that chip is a TPM 1.x chip. This patch fixes this issue. Also, this patch changes probing so that message tag is used as the measure for TPM 2.x, which should be much more stable.

Is it aware that some TPMs may respond with 0x00C1 as TAG for TPM1.2 commands?

I guess none of the TPM 1.2 command answer with the tag 0x8002?

FYI: pdf page 26 , section 6.1 explains the predictable return value for a TPM1.2 command seen by a TPM2

http://www.trustedcomputinggroup.org/files/static_page_files/8C68ADA8-1A4B-B294-D0FC06D3773F7DAA/TPM%20Rev%202.0%20Part%203%20-%20Commands%2001.16-code.pdf

Quoted 8 lines

Following this:

Sending a TPM1.2 command to a TPM2 should return a TPM1.2 header (tag = 0xc4) and error code (TPM_BADTAG = 0x1e)

Sending a TPM 2 command to a TPM 2 will give a TPM 2 tag in the header. Sending a TPM 2 command to a TPM 1.2 will give a TPM 1.2 tag in the header and an error code.

Thank you for the information. Do you think that for some reason tpm2_probe() shoould instead check that value is not this error instead of checking that tag is 0x80002?

Quoted 1 line

Stefan

/Jarkko

#6 lore raw
Quoted 21 lines · Jarkko Sakkinen
Quoted 20 lines · Stefan Berger
Quoted 8 lines · Jarkko Sakkinen
Quoted 6 lines · Peter Hüwe

Am Mittwoch, 4. Februar 2015, 15:21:09 schrieb Jarkko Sakkinen:

Quoted 4 lines

If during transmission system error was returned, the logic was to incorrectly deduce that chip is a TPM 1.x chip. This patch fixes this issue. Also, this patch changes probing so that message tag is used as the measure for TPM 2.x, which should be much more stable.

Is it aware that some TPMs may respond with 0x00C1 as TAG for TPM1.2 commands?

I guess none of the TPM 1.2 command answer with the tag 0x8002?

FYI: pdf page 26 , section 6.1 explains the predictable return value for a TPM1.2 command seen by a TPM2

http://www.trustedcomputinggroup.org/files/static_page_files/8C68ADA8-1A4B-B294-D0FC06D3773F7DAA/TPM%20Rev%202.0%20Part%203%20-%20Commands%2001.16-code.pdf

Following this:

Sending a TPM1.2 command to a TPM2 should return a TPM1.2 header (tag = 0xc4) and error code (TPM_BADTAG = 0x1e)

Quoted 6 lines
Quoted 3 lines

Sending a TPM 2 command to a TPM 2 will give a TPM 2 tag in the header. Sending a TPM 2 command to a TPM 1.2 will give a TPM 1.2 tag in the header and an error code.

Thank you for the information. Do you think that for some reason tpm2_probe() shoould instead check that value is not this error instead of checking that tag is 0x80002?

Following your path, you are checking for TPM2_ST_NO_SESSION (0x8001), which looks correct to me. A TPM1.2 would never send this tag back.

Stefan

#7 lore raw
Quoted 25 lines · Stefan Berger
Quoted 24 lines · Jarkko Sakkinen
Quoted 23 lines · Stefan Berger
Quoted 8 lines · Jarkko Sakkinen
Quoted 6 lines · Peter Hüwe

Am Mittwoch, 4. Februar 2015, 15:21:09 schrieb Jarkko Sakkinen:

Quoted 4 lines

If during transmission system error was returned, the logic was to incorrectly deduce that chip is a TPM 1.x chip. This patch fixes this issue. Also, this patch changes probing so that message tag is used as the measure for TPM 2.x, which should be much more stable.

Is it aware that some TPMs may respond with 0x00C1 as TAG for TPM1.2 commands?

I guess none of the TPM 1.2 command answer with the tag 0x8002?

FYI: pdf page 26 , section 6.1 explains the predictable return value for a TPM1.2 command seen by a TPM2

http://www.trustedcomputinggroup.org/files/static_page_files/8C68ADA8-1A4B-B294-D0FC06D3773F7DAA/TPM%20Rev%202.0%20Part%203%20-%20Commands%2001.16-code.pdf

Following this:

Sending a TPM1.2 command to a TPM2 should return a TPM1.2 header (tag = 0xc4) and error code (TPM_BADTAG = 0x1e)

Sending a TPM 2 command to a TPM 2 will give a TPM 2 tag in the header. Sending a TPM 2 command to a TPM 1.2 will give a TPM 1.2 tag in the header and an error code.

Quoted 6 lines
Quoted 3 lines

Thank you for the information. Do you think that for some reason tpm2_probe() shoould instead check that value is not this error instead of checking that tag is 0x80002?

Following your path, you are checking for TPM2_ST_NO_SESSION (0x8001), which looks correct to me. A TPM1.2 would never send this tag back.

OK, perfect :)

Quoted 1 line

Stefan

/Jarkko