Skip to contentSkip to conversation

tpm: add vendor flag to command code validation

PATCH In review Julien Gomes 2 participants 4 messages Feb 8, 2023 – Feb 13, 2023

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

PATCH 1/1 tpm: add vendor flag to command code validation

Some TPM 2.0 devices have support for additional commands which are not part of the TPM 2.0 specifications.
These commands are identified with bit 29 of the 32 bits command codes. Contrarily to other fields of the TPMA_CC spec structure used to list available commands, the Vendor flag also has to be present in the command code itself (TPM_CC) when called.

Add this flag to tpm_find_cc() mask to prevent blocking vendor command codes that can actually be supported by the underlying TPM device.

---
 drivers/char/tpm/tpm2-cmd.c | 4 +++-
 include/linux/tpm.h         | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm2-cmd.c +3 -1
index 65d03867e114..93545be190a5 100644
@@ -777,10 +777,12 @@ int tpm2_auto_startup(struct tpm_chip *chip)
 
 int tpm2_find_cc(struct tpm_chip *chip, u32 cc)
 {
+	u32 cc_mask;
 	int i;
 
+	cc_mask = 1 << TPM2_CC_ATTR_VENDOR | GENMASK(15, 0);
 	for (i = 0; i < chip->nr_commands; i++)
-		if (cc == (chip->cc_attrs_tbl[i] & GENMASK(15, 0)))
+		if (cc == (chip->cc_attrs_tbl[i] & cc_mask))
 			return i;
 
 	return -1;
include/linux/tpm.h +1 -0
index dfeb25a0362d..4dc97b9f65fb 100644
@@ -265,6 +265,7 @@ enum tpm2_startup_types {
 enum tpm2_cc_attrs {
 	TPM2_CC_ATTR_CHANDLES	= 25,
 	TPM2_CC_ATTR_RHANDLE	= 28,
+	TPM2_CC_ATTR_VENDOR	= 29,
 };
 
 #define TPM_VID_INTEL    0x8086
Signature · 1 line
2.39.1
maintainer
#1 lore raw
Quoted 49 lines · Julien Gomes

Some TPM 2.0 devices have support for additional commands which are not part of the TPM 2.0 specifications.
These commands are identified with bit 29 of the 32 bits command codes. Contrarily to other fields of the TPMA_CC spec structure used to list available commands, the Vendor flag also has to be present in the command code itself (TPM_CC) when called.

Add this flag to tpm_find_cc() mask to prevent blocking vendor command codes that can actually be supported by the underlying TPM device.

---
 drivers/char/tpm/tpm2-cmd.c | 4 +++-
 include/linux/tpm.h         | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm2-cmd.c +3 -1
index 65d03867e114..93545be190a5 100644
@@ -777,10 +777,12 @@ int tpm2_auto_startup(struct tpm_chip *chip)
 
 int tpm2_find_cc(struct tpm_chip *chip, u32 cc)
 {
+	u32 cc_mask;
 	int i;
 
+	cc_mask = 1 << TPM2_CC_ATTR_VENDOR | GENMASK(15, 0);
 	for (i = 0; i < chip->nr_commands; i++)
-		if (cc == (chip->cc_attrs_tbl[i] & GENMASK(15, 0)))
+		if (cc == (chip->cc_attrs_tbl[i] & cc_mask))
 			return i;
 
 	return -1;
include/linux/tpm.h +1 -0
index dfeb25a0362d..4dc97b9f65fb 100644
@@ -265,6 +265,7 @@ enum tpm2_startup_types {
 enum tpm2_cc_attrs {
 	TPM2_CC_ATTR_CHANDLES	= 25,
 	TPM2_CC_ATTR_RHANDLE	= 28,
+	TPM2_CC_ATTR_VENDOR	= 29,
 };
 
 #define TPM_VID_INTEL    0x8086
Signature · 1 line
2.39.1

Just checking: did you run testing/selftests/tpm2?

BR, Jarkko

#2 lore raw
Quoted 46 lines · Jarkko Sakkinen
Quoted 45 lines · Julien Gomes

Some TPM 2.0 devices have support for additional commands which are not part of the TPM 2.0 specifications.
These commands are identified with bit 29 of the 32 bits command codes. Contrarily to other fields of the TPMA_CC spec structure used to list available commands, the Vendor flag also has to be present in the command code itself (TPM_CC) when called.

Add this flag to tpm_find_cc() mask to prevent blocking vendor command codes that can actually be supported by the underlying TPM device.

---
  drivers/char/tpm/tpm2-cmd.c | 4 +++-
  include/linux/tpm.h         | 1 +
  2 files changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm2-cmd.c +3 -1
index 65d03867e114..93545be190a5 100644
@@ -777,10 +777,12 @@ int tpm2_auto_startup(struct tpm_chip *chip)
 
  int tpm2_find_cc(struct tpm_chip *chip, u32 cc)
  {
+	u32 cc_mask;
  	int i;
 
+	cc_mask = 1 << TPM2_CC_ATTR_VENDOR | GENMASK(15, 0);
  	for (i = 0; i < chip->nr_commands; i++)
-		if (cc == (chip->cc_attrs_tbl[i] & GENMASK(15, 0)))
+		if (cc == (chip->cc_attrs_tbl[i] & cc_mask))
  			return i;
 
  	return -1;
include/linux/tpm.h +1 -0
index dfeb25a0362d..4dc97b9f65fb 100644
@@ -265,6 +265,7 @@ enum tpm2_startup_types {
  enum tpm2_cc_attrs {
  	TPM2_CC_ATTR_CHANDLES	= 25,
  	TPM2_CC_ATTR_RHANDLE	= 28,
+	TPM2_CC_ATTR_VENDOR	= 29,
  };
 
Quoted 8 lines
Quoted 4 lines
include/linux/tpm.h +0 -0
  #define TPM_VID_INTEL    0x8086
Signature · 1 line
2.39.1

Just checking: did you run testing/selftests/tpm2?

BR, Jarkko

I didn't know about these, good call.
Just ran the three test suites on a vm with a swtpm, as I don't have a physical box with TPM 2.0 able to run latest kernels handy, all passed.

Signature · 1 line
Julien Gomes
maintainer Tested-by Reviewed-by
#3 lore raw
Quoted 50 lines · Julien Gomes
Quoted 49 lines · Jarkko Sakkinen
Quoted 45 lines · Julien Gomes

Some TPM 2.0 devices have support for additional commands which are not part of the TPM 2.0 specifications.
These commands are identified with bit 29 of the 32 bits command codes. Contrarily to other fields of the TPMA_CC spec structure used to list available commands, the Vendor flag also has to be present in the command code itself (TPM_CC) when called.

Add this flag to tpm_find_cc() mask to prevent blocking vendor command codes that can actually be supported by the underlying TPM device.

---
  drivers/char/tpm/tpm2-cmd.c | 4 +++-
  include/linux/tpm.h         | 1 +
  2 files changed, 4 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm2-cmd.c +3 -1
index 65d03867e114..93545be190a5 100644
@@ -777,10 +777,12 @@ int tpm2_auto_startup(struct tpm_chip *chip)
  int tpm2_find_cc(struct tpm_chip *chip, u32 cc)
  {
+	u32 cc_mask;
  	int i;
+	cc_mask = 1 << TPM2_CC_ATTR_VENDOR | GENMASK(15, 0);
  	for (i = 0; i < chip->nr_commands; i++)
-		if (cc == (chip->cc_attrs_tbl[i] & GENMASK(15, 0)))
+		if (cc == (chip->cc_attrs_tbl[i] & cc_mask))
  			return i;
  	return -1;
include/linux/tpm.h +1 -0
index dfeb25a0362d..4dc97b9f65fb 100644
@@ -265,6 +265,7 @@ enum tpm2_startup_types {
  enum tpm2_cc_attrs {
  	TPM2_CC_ATTR_CHANDLES	= 25,
  	TPM2_CC_ATTR_RHANDLE	= 28,
+	TPM2_CC_ATTR_VENDOR	= 29,
  };
  #define TPM_VID_INTEL    0x8086
Signature · 1 line
2.39.1

Just checking: did you run testing/selftests/tpm2?

Quoted 5 lines
Quoted 1 line

BR, Jarkko

I didn't know about these, good call.
Just ran the three test suites on a vm with a swtpm, as I don't have a physical box with TPM 2.0 able to run latest kernels handy, all passed.

Neither broke on my side, thanks.

BR, Jarkko