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


Groups > linux.kernel > #1634380 > unrolled thread

[PATCH 0/3] tpm_pcr_extend() code split

Started byRoberto Sassu <roberto.sassu@huawei.com>
First post2017-05-02 14:40 +0200
Last post2017-05-03 14:50 +0200
Articles 6 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/3] tpm_pcr_extend() code split Roberto Sassu <roberto.sassu@huawei.com> - 2017-05-02 14:40 +0200
    [PATCH 2/3] tpm: move ordinals definition to include/linux/tpm_command.h Roberto Sassu <roberto.sassu@huawei.com> - 2017-05-02 14:40 +0200
      Re: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to  include/linux/tpm_command.h Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-05-03 14:50 +0200
        Re: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to  include/linux/tpm_command.h Roberto Sassu <roberto.sassu@huawei.com> - 2017-05-03 16:30 +0200
          Re: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to  include/linux/tpm_command.h Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-05-04 10:20 +0200
      Re: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to  include/linux/tpm_command.h Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2017-05-03 14:50 +0200

#1634380 — [PATCH 0/3] tpm_pcr_extend() code split

FromRoberto Sassu <roberto.sassu@huawei.com>
Date2017-05-02 14:40 +0200
Subject[PATCH 0/3] tpm_pcr_extend() code split
Message-ID<tCFfX-6Iv-7@gated-at.bofh.it>
This patch set moves TPM 1.2 specific code to a new function called
tpm1_pcr_extend(). The purpose of splitting is to isolate TPM 2.0 code,
so that it can be more easily modified to handle multiple digests.

With TPM 2.0, a Platform Configuration Register (PCR) could have multiple
values, stored in locations called banks. Each bank stores the values
of PCRs extended with the same hash algorithm.

Currently, the TPM kernel driver does not take advantage of stronger
algorithms because PCRs are always extended with a SHA1 digest, padded
with zeros to match the length of the input for the hash algorithm
being used. Shortly after these patches, a new patch set will be provided
to allow callers of tpm_pcr_extend() to pass a digest for each algorithm
supported by the TPM.

In this patch set, TPM 1.2 specific code will prepare the command buffer
with tpm_buf_init() which, in respect to the previous method, offers
protection against buffer overflow. Moreover, CPU native to big-endian
conversion has been removed from tags and ordinals definition, as it is
already done by tpm_buf_init().

Roberto Sassu (3):
  tpm: use CPU native value for TPM_TAG_RQU_COMMAND
  tpm: move ordinals definition to include/linux/tpm_command.h
  tpm: move TPM 1.2 code of tpm_pcr_extend() to tpm1_pcr_extend()

 drivers/char/tpm/tpm-interface.c | 76 +++++++++++++++++++---------------------
 drivers/char/tpm/tpm-sysfs.c     |  6 ++--
 drivers/char/tpm/tpm.h           |  2 --
 include/linux/tpm_command.h      |  7 ++++
 4 files changed, 46 insertions(+), 45 deletions(-)

-- 
2.9.3

[toc] | [next] | [standalone]


#1634382 — [PATCH 2/3] tpm: move ordinals definition to include/linux/tpm_command.h

FromRoberto Sassu <roberto.sassu@huawei.com>
Date2017-05-02 14:40 +0200
Subject[PATCH 2/3] tpm: move ordinals definition to include/linux/tpm_command.h
Message-ID<tCFfY-6Iv-23@gated-at.bofh.it>
In reply to#1634380
Move definition from tpm-interface.c to tpm_command.h, so that there is
no duplication. Also convert the ordinals in the tpm_input_header
declarations.

With the previous and this patch it will now be possible to convert TPM 1.2
functions to use tpm_buf_init(), which expect CPU native value for the
tag and ordinal arguments.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
 drivers/char/tpm/tpm-interface.c | 19 ++++++-------------
 drivers/char/tpm/tpm-sysfs.c     |  3 +--
 include/linux/tpm_command.h      |  7 +++++++
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 48f5dff..5c2c032 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -469,13 +469,11 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *buf,
 #define TPM_DIGEST_SIZE 20
 #define TPM_RET_CODE_IDX 6
 #define TPM_INTERNAL_RESULT_SIZE 200
-#define TPM_ORD_GET_CAP cpu_to_be32(101)
-#define TPM_ORD_GET_RANDOM cpu_to_be32(70)
 
 static const struct tpm_input_header tpm_getcap_header = {
 	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
 	.length = cpu_to_be32(22),
-	.ordinal = TPM_ORD_GET_CAP
+	.ordinal = cpu_to_be32(TPM_ORD_GET_CAP)
 };
 
 ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
@@ -510,14 +508,13 @@ ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
 }
 EXPORT_SYMBOL_GPL(tpm_getcap);
 
-#define TPM_ORD_STARTUP cpu_to_be32(153)
 #define TPM_ST_CLEAR cpu_to_be16(1)
 #define TPM_ST_STATE cpu_to_be16(2)
 #define TPM_ST_DEACTIVATED cpu_to_be16(3)
 static const struct tpm_input_header tpm_startup_header = {
 	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
 	.length = cpu_to_be32(12),
-	.ordinal = TPM_ORD_STARTUP
+	.ordinal = cpu_to_be32(TPM_ORD_STARTUP)
 };
 
 static int tpm_startup(struct tpm_chip *chip, __be16 startup_type)
@@ -661,7 +658,6 @@ int tpm_get_timeouts(struct tpm_chip *chip)
 }
 EXPORT_SYMBOL_GPL(tpm_get_timeouts);
 
-#define TPM_ORD_CONTINUE_SELFTEST 83
 #define CONTINUE_SELFTEST_RESULT_SIZE 10
 
 static const struct tpm_input_header continue_selftest_header = {
@@ -688,13 +684,12 @@ static int tpm_continue_selftest(struct tpm_chip *chip)
 	return rc;
 }
 
-#define TPM_ORDINAL_PCRREAD cpu_to_be32(21)
 #define READ_PCR_RESULT_SIZE 30
 #define READ_PCR_RESULT_BODY_SIZE 20
 static const struct tpm_input_header pcrread_header = {
 	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
 	.length = cpu_to_be32(14),
-	.ordinal = TPM_ORDINAL_PCRREAD
+	.ordinal = cpu_to_be32(TPM_ORD_PCRREAD)
 };
 
 int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
@@ -766,13 +761,12 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)
 }
 EXPORT_SYMBOL_GPL(tpm_pcr_read);
 
-#define TPM_ORD_PCR_EXTEND cpu_to_be32(20)
 #define EXTEND_PCR_RESULT_SIZE 34
 #define EXTEND_PCR_RESULT_BODY_SIZE 20
 static const struct tpm_input_header pcrextend_header = {
 	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
 	.length = cpu_to_be32(34),
-	.ordinal = TPM_ORD_PCR_EXTEND
+	.ordinal = cpu_to_be32(TPM_ORD_PCREXTEND)
 };
 
 /**
@@ -988,13 +982,12 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
 }
 EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
 
-#define TPM_ORD_SAVESTATE cpu_to_be32(152)
 #define SAVESTATE_RESULT_SIZE 10
 
 static const struct tpm_input_header savestate_header = {
 	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
 	.length = cpu_to_be32(10),
-	.ordinal = TPM_ORD_SAVESTATE
+	.ordinal = cpu_to_be32(TPM_ORD_SAVESTATE)
 };
 
 /*
@@ -1079,7 +1072,7 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume);
 static const struct tpm_input_header tpm_getrandom_header = {
 	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
 	.length = cpu_to_be32(14),
-	.ordinal = TPM_ORD_GET_RANDOM
+	.ordinal = cpu_to_be32(TPM_ORD_GETRANDOM)
 };
 
 /**
diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
index 69a0741..413ac2c 100644
--- a/drivers/char/tpm/tpm-sysfs.c
+++ b/drivers/char/tpm/tpm-sysfs.c
@@ -23,11 +23,10 @@
 
 #define READ_PUBEK_RESULT_SIZE 314
 #define READ_PUBEK_RESULT_MIN_BODY_SIZE (28 + 256)
-#define TPM_ORD_READPUBEK cpu_to_be32(124)
 static const struct tpm_input_header tpm_readpubek_header = {
 	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
 	.length = cpu_to_be32(30),
-	.ordinal = TPM_ORD_READPUBEK
+	.ordinal = cpu_to_be32(TPM_ORD_READPUBEK)
 };
 static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
 			  char *buf)
diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h
index 727512e..0fe58d8 100644
--- a/include/linux/tpm_command.h
+++ b/include/linux/tpm_command.h
@@ -20,6 +20,13 @@
 #define TPM_ORD_OIAP                    10
 #define TPM_ORD_SEAL                    23
 #define TPM_ORD_UNSEAL                  24
+#define TPM_ORD_GET_CAP                101
+#define TPM_ORD_STARTUP                153
+#define TPM_ORD_CONTINUE_SELFTEST       83
+#define TPM_ORD_PCRREAD                 21
+#define TPM_ORD_PCREXTEND               20
+#define TPM_ORD_SAVESTATE              152
+#define TPM_ORD_READPUBEK              124
 
 /* Other constants */
 #define SRKHANDLE                       0x40000000
-- 
2.9.3

[toc] | [prev] | [next] | [standalone]


#1634958 — Re: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to include/linux/tpm_command.h

FromJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Date2017-05-03 14:50 +0200
SubjectRe: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to include/linux/tpm_command.h
Message-ID<tD1Tb-5s5-5@gated-at.bofh.it>
In reply to#1634382
On Tue, May 02, 2017 at 02:31:50PM +0200, Roberto Sassu wrote:
> Move definition from tpm-interface.c to tpm_command.h, so that there is
> no duplication. Also convert the ordinals in the tpm_input_header
> declarations.
> 
> With the previous and this patch it will now be possible to convert TPM 1.2
> functions to use tpm_buf_init(), which expect CPU native value for the
> tag and ordinal arguments.

ORD ought not be used outside of drivers/char/tpm. TPM 1.2 trusted
keys does use this header but it should be eventually moved to
drivers/char/tpm (not done because of other stuff at this point).

/Jarkko

> 
> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> ---
>  drivers/char/tpm/tpm-interface.c | 19 ++++++-------------
>  drivers/char/tpm/tpm-sysfs.c     |  3 +--
>  include/linux/tpm_command.h      |  7 +++++++
>  3 files changed, 14 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 48f5dff..5c2c032 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -469,13 +469,11 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *buf,
>  #define TPM_DIGEST_SIZE 20
>  #define TPM_RET_CODE_IDX 6
>  #define TPM_INTERNAL_RESULT_SIZE 200
> -#define TPM_ORD_GET_CAP cpu_to_be32(101)
> -#define TPM_ORD_GET_RANDOM cpu_to_be32(70)
>  
>  static const struct tpm_input_header tpm_getcap_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(22),
> -	.ordinal = TPM_ORD_GET_CAP
> +	.ordinal = cpu_to_be32(TPM_ORD_GET_CAP)
>  };
>  
>  ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
> @@ -510,14 +508,13 @@ ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
>  }
>  EXPORT_SYMBOL_GPL(tpm_getcap);
>  
> -#define TPM_ORD_STARTUP cpu_to_be32(153)
>  #define TPM_ST_CLEAR cpu_to_be16(1)
>  #define TPM_ST_STATE cpu_to_be16(2)
>  #define TPM_ST_DEACTIVATED cpu_to_be16(3)
>  static const struct tpm_input_header tpm_startup_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(12),
> -	.ordinal = TPM_ORD_STARTUP
> +	.ordinal = cpu_to_be32(TPM_ORD_STARTUP)
>  };
>  
>  static int tpm_startup(struct tpm_chip *chip, __be16 startup_type)
> @@ -661,7 +658,6 @@ int tpm_get_timeouts(struct tpm_chip *chip)
>  }
>  EXPORT_SYMBOL_GPL(tpm_get_timeouts);
>  
> -#define TPM_ORD_CONTINUE_SELFTEST 83
>  #define CONTINUE_SELFTEST_RESULT_SIZE 10
>  
>  static const struct tpm_input_header continue_selftest_header = {
> @@ -688,13 +684,12 @@ static int tpm_continue_selftest(struct tpm_chip *chip)
>  	return rc;
>  }
>  
> -#define TPM_ORDINAL_PCRREAD cpu_to_be32(21)
>  #define READ_PCR_RESULT_SIZE 30
>  #define READ_PCR_RESULT_BODY_SIZE 20
>  static const struct tpm_input_header pcrread_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(14),
> -	.ordinal = TPM_ORDINAL_PCRREAD
> +	.ordinal = cpu_to_be32(TPM_ORD_PCRREAD)
>  };
>  
>  int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
> @@ -766,13 +761,12 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)
>  }
>  EXPORT_SYMBOL_GPL(tpm_pcr_read);
>  
> -#define TPM_ORD_PCR_EXTEND cpu_to_be32(20)
>  #define EXTEND_PCR_RESULT_SIZE 34
>  #define EXTEND_PCR_RESULT_BODY_SIZE 20
>  static const struct tpm_input_header pcrextend_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(34),
> -	.ordinal = TPM_ORD_PCR_EXTEND
> +	.ordinal = cpu_to_be32(TPM_ORD_PCREXTEND)
>  };
>  
>  /**
> @@ -988,13 +982,12 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
>  }
>  EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
>  
> -#define TPM_ORD_SAVESTATE cpu_to_be32(152)
>  #define SAVESTATE_RESULT_SIZE 10
>  
>  static const struct tpm_input_header savestate_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(10),
> -	.ordinal = TPM_ORD_SAVESTATE
> +	.ordinal = cpu_to_be32(TPM_ORD_SAVESTATE)
>  };
>  
>  /*
> @@ -1079,7 +1072,7 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume);
>  static const struct tpm_input_header tpm_getrandom_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(14),
> -	.ordinal = TPM_ORD_GET_RANDOM
> +	.ordinal = cpu_to_be32(TPM_ORD_GETRANDOM)
>  };
>  
>  /**
> diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
> index 69a0741..413ac2c 100644
> --- a/drivers/char/tpm/tpm-sysfs.c
> +++ b/drivers/char/tpm/tpm-sysfs.c
> @@ -23,11 +23,10 @@
>  
>  #define READ_PUBEK_RESULT_SIZE 314
>  #define READ_PUBEK_RESULT_MIN_BODY_SIZE (28 + 256)
> -#define TPM_ORD_READPUBEK cpu_to_be32(124)
>  static const struct tpm_input_header tpm_readpubek_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(30),
> -	.ordinal = TPM_ORD_READPUBEK
> +	.ordinal = cpu_to_be32(TPM_ORD_READPUBEK)
>  };
>  static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
>  			  char *buf)
> diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h
> index 727512e..0fe58d8 100644
> --- a/include/linux/tpm_command.h
> +++ b/include/linux/tpm_command.h
> @@ -20,6 +20,13 @@
>  #define TPM_ORD_OIAP                    10
>  #define TPM_ORD_SEAL                    23
>  #define TPM_ORD_UNSEAL                  24
> +#define TPM_ORD_GET_CAP                101
> +#define TPM_ORD_STARTUP                153
> +#define TPM_ORD_CONTINUE_SELFTEST       83
> +#define TPM_ORD_PCRREAD                 21
> +#define TPM_ORD_PCREXTEND               20
> +#define TPM_ORD_SAVESTATE              152
> +#define TPM_ORD_READPUBEK              124
>  
>  /* Other constants */
>  #define SRKHANDLE                       0x40000000
> -- 
> 2.9.3
> 
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> tpmdd-devel mailing list
> tpmdd-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tpmdd-devel

[toc] | [prev] | [next] | [standalone]


#1635031 — Re: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to include/linux/tpm_command.h

FromRoberto Sassu <roberto.sassu@huawei.com>
Date2017-05-03 16:30 +0200
SubjectRe: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to include/linux/tpm_command.h
Message-ID<tD3rX-6Af-15@gated-at.bofh.it>
In reply to#1634958
On 5/3/2017 2:48 PM, Jarkko Sakkinen wrote:
> ORD ought not be used outside of drivers/char/tpm. TPM 1.2 trusted
> keys does use this header but it should be eventually moved to
> drivers/char/tpm (not done because of other stuff at this point).

Ok. Then, I just move the ordinal conversion to the tpm_input_header
declaration.

Probably, the Reviewed-by in your previous email was for patch 1/3.

Thanks

Roberto


>
> /Jarkko
>
>>
>> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
>> ---
>>  drivers/char/tpm/tpm-interface.c | 19 ++++++-------------
>>  drivers/char/tpm/tpm-sysfs.c     |  3 +--
>>  include/linux/tpm_command.h      |  7 +++++++
>>  3 files changed, 14 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
>> index 48f5dff..5c2c032 100644
>> --- a/drivers/char/tpm/tpm-interface.c
>> +++ b/drivers/char/tpm/tpm-interface.c
>> @@ -469,13 +469,11 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *buf,
>>  #define TPM_DIGEST_SIZE 20
>>  #define TPM_RET_CODE_IDX 6
>>  #define TPM_INTERNAL_RESULT_SIZE 200
>> -#define TPM_ORD_GET_CAP cpu_to_be32(101)
>> -#define TPM_ORD_GET_RANDOM cpu_to_be32(70)
>>
>>  static const struct tpm_input_header tpm_getcap_header = {
>>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>>  	.length = cpu_to_be32(22),
>> -	.ordinal = TPM_ORD_GET_CAP
>> +	.ordinal = cpu_to_be32(TPM_ORD_GET_CAP)
>>  };
>>
>>  ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
>> @@ -510,14 +508,13 @@ ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
>>  }
>>  EXPORT_SYMBOL_GPL(tpm_getcap);
>>
>> -#define TPM_ORD_STARTUP cpu_to_be32(153)
>>  #define TPM_ST_CLEAR cpu_to_be16(1)
>>  #define TPM_ST_STATE cpu_to_be16(2)
>>  #define TPM_ST_DEACTIVATED cpu_to_be16(3)
>>  static const struct tpm_input_header tpm_startup_header = {
>>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>>  	.length = cpu_to_be32(12),
>> -	.ordinal = TPM_ORD_STARTUP
>> +	.ordinal = cpu_to_be32(TPM_ORD_STARTUP)
>>  };
>>
>>  static int tpm_startup(struct tpm_chip *chip, __be16 startup_type)
>> @@ -661,7 +658,6 @@ int tpm_get_timeouts(struct tpm_chip *chip)
>>  }
>>  EXPORT_SYMBOL_GPL(tpm_get_timeouts);
>>
>> -#define TPM_ORD_CONTINUE_SELFTEST 83
>>  #define CONTINUE_SELFTEST_RESULT_SIZE 10
>>
>>  static const struct tpm_input_header continue_selftest_header = {
>> @@ -688,13 +684,12 @@ static int tpm_continue_selftest(struct tpm_chip *chip)
>>  	return rc;
>>  }
>>
>> -#define TPM_ORDINAL_PCRREAD cpu_to_be32(21)
>>  #define READ_PCR_RESULT_SIZE 30
>>  #define READ_PCR_RESULT_BODY_SIZE 20
>>  static const struct tpm_input_header pcrread_header = {
>>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>>  	.length = cpu_to_be32(14),
>> -	.ordinal = TPM_ORDINAL_PCRREAD
>> +	.ordinal = cpu_to_be32(TPM_ORD_PCRREAD)
>>  };
>>
>>  int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
>> @@ -766,13 +761,12 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)
>>  }
>>  EXPORT_SYMBOL_GPL(tpm_pcr_read);
>>
>> -#define TPM_ORD_PCR_EXTEND cpu_to_be32(20)
>>  #define EXTEND_PCR_RESULT_SIZE 34
>>  #define EXTEND_PCR_RESULT_BODY_SIZE 20
>>  static const struct tpm_input_header pcrextend_header = {
>>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>>  	.length = cpu_to_be32(34),
>> -	.ordinal = TPM_ORD_PCR_EXTEND
>> +	.ordinal = cpu_to_be32(TPM_ORD_PCREXTEND)
>>  };
>>
>>  /**
>> @@ -988,13 +982,12 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
>>  }
>>  EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
>>
>> -#define TPM_ORD_SAVESTATE cpu_to_be32(152)
>>  #define SAVESTATE_RESULT_SIZE 10
>>
>>  static const struct tpm_input_header savestate_header = {
>>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>>  	.length = cpu_to_be32(10),
>> -	.ordinal = TPM_ORD_SAVESTATE
>> +	.ordinal = cpu_to_be32(TPM_ORD_SAVESTATE)
>>  };
>>
>>  /*
>> @@ -1079,7 +1072,7 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume);
>>  static const struct tpm_input_header tpm_getrandom_header = {
>>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>>  	.length = cpu_to_be32(14),
>> -	.ordinal = TPM_ORD_GET_RANDOM
>> +	.ordinal = cpu_to_be32(TPM_ORD_GETRANDOM)
>>  };
>>
>>  /**
>> diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
>> index 69a0741..413ac2c 100644
>> --- a/drivers/char/tpm/tpm-sysfs.c
>> +++ b/drivers/char/tpm/tpm-sysfs.c
>> @@ -23,11 +23,10 @@
>>
>>  #define READ_PUBEK_RESULT_SIZE 314
>>  #define READ_PUBEK_RESULT_MIN_BODY_SIZE (28 + 256)
>> -#define TPM_ORD_READPUBEK cpu_to_be32(124)
>>  static const struct tpm_input_header tpm_readpubek_header = {
>>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>>  	.length = cpu_to_be32(30),
>> -	.ordinal = TPM_ORD_READPUBEK
>> +	.ordinal = cpu_to_be32(TPM_ORD_READPUBEK)
>>  };
>>  static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
>>  			  char *buf)
>> diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h
>> index 727512e..0fe58d8 100644
>> --- a/include/linux/tpm_command.h
>> +++ b/include/linux/tpm_command.h
>> @@ -20,6 +20,13 @@
>>  #define TPM_ORD_OIAP                    10
>>  #define TPM_ORD_SEAL                    23
>>  #define TPM_ORD_UNSEAL                  24
>> +#define TPM_ORD_GET_CAP                101
>> +#define TPM_ORD_STARTUP                153
>> +#define TPM_ORD_CONTINUE_SELFTEST       83
>> +#define TPM_ORD_PCRREAD                 21
>> +#define TPM_ORD_PCREXTEND               20
>> +#define TPM_ORD_SAVESTATE              152
>> +#define TPM_ORD_READPUBEK              124
>>
>>  /* Other constants */
>>  #define SRKHANDLE                       0x40000000
>> --
>> 2.9.3
>>
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> tpmdd-devel mailing list
>> tpmdd-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/tpmdd-devel

[toc] | [prev] | [next] | [standalone]


#1635472 — Re: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to include/linux/tpm_command.h

FromJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Date2017-05-04 10:20 +0200
SubjectRe: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to include/linux/tpm_command.h
Message-ID<tDk9s-S5-19@gated-at.bofh.it>
In reply to#1635031
On Wed, May 03, 2017 at 04:27:20PM +0200, Roberto Sassu wrote:
> On 5/3/2017 2:48 PM, Jarkko Sakkinen wrote:
> > ORD ought not be used outside of drivers/char/tpm. TPM 1.2 trusted
> > keys does use this header but it should be eventually moved to
> > drivers/char/tpm (not done because of other stuff at this point).
> 
> Ok. Then, I just move the ordinal conversion to the tpm_input_header
> declaration.
> 
> Probably, the Reviewed-by in your previous email was for patch 1/3.

Yes, it was!

> Thanks
> 
> Roberto

/Jarkko

> 
> 
> > 
> > /Jarkko
> > 
> > > 
> > > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> > > ---
> > >  drivers/char/tpm/tpm-interface.c | 19 ++++++-------------
> > >  drivers/char/tpm/tpm-sysfs.c     |  3 +--
> > >  include/linux/tpm_command.h      |  7 +++++++
> > >  3 files changed, 14 insertions(+), 15 deletions(-)
> > > 
> > > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> > > index 48f5dff..5c2c032 100644
> > > --- a/drivers/char/tpm/tpm-interface.c
> > > +++ b/drivers/char/tpm/tpm-interface.c
> > > @@ -469,13 +469,11 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *buf,
> > >  #define TPM_DIGEST_SIZE 20
> > >  #define TPM_RET_CODE_IDX 6
> > >  #define TPM_INTERNAL_RESULT_SIZE 200
> > > -#define TPM_ORD_GET_CAP cpu_to_be32(101)
> > > -#define TPM_ORD_GET_RANDOM cpu_to_be32(70)
> > > 
> > >  static const struct tpm_input_header tpm_getcap_header = {
> > >  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
> > >  	.length = cpu_to_be32(22),
> > > -	.ordinal = TPM_ORD_GET_CAP
> > > +	.ordinal = cpu_to_be32(TPM_ORD_GET_CAP)
> > >  };
> > > 
> > >  ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
> > > @@ -510,14 +508,13 @@ ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
> > >  }
> > >  EXPORT_SYMBOL_GPL(tpm_getcap);
> > > 
> > > -#define TPM_ORD_STARTUP cpu_to_be32(153)
> > >  #define TPM_ST_CLEAR cpu_to_be16(1)
> > >  #define TPM_ST_STATE cpu_to_be16(2)
> > >  #define TPM_ST_DEACTIVATED cpu_to_be16(3)
> > >  static const struct tpm_input_header tpm_startup_header = {
> > >  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
> > >  	.length = cpu_to_be32(12),
> > > -	.ordinal = TPM_ORD_STARTUP
> > > +	.ordinal = cpu_to_be32(TPM_ORD_STARTUP)
> > >  };
> > > 
> > >  static int tpm_startup(struct tpm_chip *chip, __be16 startup_type)
> > > @@ -661,7 +658,6 @@ int tpm_get_timeouts(struct tpm_chip *chip)
> > >  }
> > >  EXPORT_SYMBOL_GPL(tpm_get_timeouts);
> > > 
> > > -#define TPM_ORD_CONTINUE_SELFTEST 83
> > >  #define CONTINUE_SELFTEST_RESULT_SIZE 10
> > > 
> > >  static const struct tpm_input_header continue_selftest_header = {
> > > @@ -688,13 +684,12 @@ static int tpm_continue_selftest(struct tpm_chip *chip)
> > >  	return rc;
> > >  }
> > > 
> > > -#define TPM_ORDINAL_PCRREAD cpu_to_be32(21)
> > >  #define READ_PCR_RESULT_SIZE 30
> > >  #define READ_PCR_RESULT_BODY_SIZE 20
> > >  static const struct tpm_input_header pcrread_header = {
> > >  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
> > >  	.length = cpu_to_be32(14),
> > > -	.ordinal = TPM_ORDINAL_PCRREAD
> > > +	.ordinal = cpu_to_be32(TPM_ORD_PCRREAD)
> > >  };
> > > 
> > >  int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
> > > @@ -766,13 +761,12 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)
> > >  }
> > >  EXPORT_SYMBOL_GPL(tpm_pcr_read);
> > > 
> > > -#define TPM_ORD_PCR_EXTEND cpu_to_be32(20)
> > >  #define EXTEND_PCR_RESULT_SIZE 34
> > >  #define EXTEND_PCR_RESULT_BODY_SIZE 20
> > >  static const struct tpm_input_header pcrextend_header = {
> > >  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
> > >  	.length = cpu_to_be32(34),
> > > -	.ordinal = TPM_ORD_PCR_EXTEND
> > > +	.ordinal = cpu_to_be32(TPM_ORD_PCREXTEND)
> > >  };
> > > 
> > >  /**
> > > @@ -988,13 +982,12 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
> > >  }
> > >  EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
> > > 
> > > -#define TPM_ORD_SAVESTATE cpu_to_be32(152)
> > >  #define SAVESTATE_RESULT_SIZE 10
> > > 
> > >  static const struct tpm_input_header savestate_header = {
> > >  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
> > >  	.length = cpu_to_be32(10),
> > > -	.ordinal = TPM_ORD_SAVESTATE
> > > +	.ordinal = cpu_to_be32(TPM_ORD_SAVESTATE)
> > >  };
> > > 
> > >  /*
> > > @@ -1079,7 +1072,7 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume);
> > >  static const struct tpm_input_header tpm_getrandom_header = {
> > >  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
> > >  	.length = cpu_to_be32(14),
> > > -	.ordinal = TPM_ORD_GET_RANDOM
> > > +	.ordinal = cpu_to_be32(TPM_ORD_GETRANDOM)
> > >  };
> > > 
> > >  /**
> > > diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
> > > index 69a0741..413ac2c 100644
> > > --- a/drivers/char/tpm/tpm-sysfs.c
> > > +++ b/drivers/char/tpm/tpm-sysfs.c
> > > @@ -23,11 +23,10 @@
> > > 
> > >  #define READ_PUBEK_RESULT_SIZE 314
> > >  #define READ_PUBEK_RESULT_MIN_BODY_SIZE (28 + 256)
> > > -#define TPM_ORD_READPUBEK cpu_to_be32(124)
> > >  static const struct tpm_input_header tpm_readpubek_header = {
> > >  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
> > >  	.length = cpu_to_be32(30),
> > > -	.ordinal = TPM_ORD_READPUBEK
> > > +	.ordinal = cpu_to_be32(TPM_ORD_READPUBEK)
> > >  };
> > >  static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
> > >  			  char *buf)
> > > diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h
> > > index 727512e..0fe58d8 100644
> > > --- a/include/linux/tpm_command.h
> > > +++ b/include/linux/tpm_command.h
> > > @@ -20,6 +20,13 @@
> > >  #define TPM_ORD_OIAP                    10
> > >  #define TPM_ORD_SEAL                    23
> > >  #define TPM_ORD_UNSEAL                  24
> > > +#define TPM_ORD_GET_CAP                101
> > > +#define TPM_ORD_STARTUP                153
> > > +#define TPM_ORD_CONTINUE_SELFTEST       83
> > > +#define TPM_ORD_PCRREAD                 21
> > > +#define TPM_ORD_PCREXTEND               20
> > > +#define TPM_ORD_SAVESTATE              152
> > > +#define TPM_ORD_READPUBEK              124
> > > 
> > >  /* Other constants */
> > >  #define SRKHANDLE                       0x40000000
> > > --
> > > 2.9.3
> > > 
> > > 
> > > ------------------------------------------------------------------------------
> > > Check out the vibrant tech community on one of the world's most
> > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > > _______________________________________________
> > > tpmdd-devel mailing list
> > > tpmdd-devel@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/tpmdd-devel

[toc] | [prev] | [next] | [standalone]


#1634961 — Re: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to include/linux/tpm_command.h

FromJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Date2017-05-03 14:50 +0200
SubjectRe: [tpmdd-devel] [PATCH 2/3] tpm: move ordinals definition to include/linux/tpm_command.h
Message-ID<tD1Tc-5s5-17@gated-at.bofh.it>
In reply to#1634382
On Tue, May 02, 2017 at 02:31:50PM +0200, Roberto Sassu wrote:
> Move definition from tpm-interface.c to tpm_command.h, so that there is
> no duplication. Also convert the ordinals in the tpm_input_header
> declarations.
> 
> With the previous and this patch it will now be possible to convert TPM 1.2
> functions to use tpm_buf_init(), which expect CPU native value for the
> tag and ordinal arguments.
> 
> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

> ---
>  drivers/char/tpm/tpm-interface.c | 19 ++++++-------------
>  drivers/char/tpm/tpm-sysfs.c     |  3 +--
>  include/linux/tpm_command.h      |  7 +++++++
>  3 files changed, 14 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 48f5dff..5c2c032 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -469,13 +469,11 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *buf,
>  #define TPM_DIGEST_SIZE 20
>  #define TPM_RET_CODE_IDX 6
>  #define TPM_INTERNAL_RESULT_SIZE 200
> -#define TPM_ORD_GET_CAP cpu_to_be32(101)
> -#define TPM_ORD_GET_RANDOM cpu_to_be32(70)
>  
>  static const struct tpm_input_header tpm_getcap_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(22),
> -	.ordinal = TPM_ORD_GET_CAP
> +	.ordinal = cpu_to_be32(TPM_ORD_GET_CAP)
>  };
>  
>  ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
> @@ -510,14 +508,13 @@ ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
>  }
>  EXPORT_SYMBOL_GPL(tpm_getcap);
>  
> -#define TPM_ORD_STARTUP cpu_to_be32(153)
>  #define TPM_ST_CLEAR cpu_to_be16(1)
>  #define TPM_ST_STATE cpu_to_be16(2)
>  #define TPM_ST_DEACTIVATED cpu_to_be16(3)
>  static const struct tpm_input_header tpm_startup_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(12),
> -	.ordinal = TPM_ORD_STARTUP
> +	.ordinal = cpu_to_be32(TPM_ORD_STARTUP)
>  };
>  
>  static int tpm_startup(struct tpm_chip *chip, __be16 startup_type)
> @@ -661,7 +658,6 @@ int tpm_get_timeouts(struct tpm_chip *chip)
>  }
>  EXPORT_SYMBOL_GPL(tpm_get_timeouts);
>  
> -#define TPM_ORD_CONTINUE_SELFTEST 83
>  #define CONTINUE_SELFTEST_RESULT_SIZE 10
>  
>  static const struct tpm_input_header continue_selftest_header = {
> @@ -688,13 +684,12 @@ static int tpm_continue_selftest(struct tpm_chip *chip)
>  	return rc;
>  }
>  
> -#define TPM_ORDINAL_PCRREAD cpu_to_be32(21)
>  #define READ_PCR_RESULT_SIZE 30
>  #define READ_PCR_RESULT_BODY_SIZE 20
>  static const struct tpm_input_header pcrread_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(14),
> -	.ordinal = TPM_ORDINAL_PCRREAD
> +	.ordinal = cpu_to_be32(TPM_ORD_PCRREAD)
>  };
>  
>  int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
> @@ -766,13 +761,12 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)
>  }
>  EXPORT_SYMBOL_GPL(tpm_pcr_read);
>  
> -#define TPM_ORD_PCR_EXTEND cpu_to_be32(20)
>  #define EXTEND_PCR_RESULT_SIZE 34
>  #define EXTEND_PCR_RESULT_BODY_SIZE 20
>  static const struct tpm_input_header pcrextend_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(34),
> -	.ordinal = TPM_ORD_PCR_EXTEND
> +	.ordinal = cpu_to_be32(TPM_ORD_PCREXTEND)
>  };
>  
>  /**
> @@ -988,13 +982,12 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
>  }
>  EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
>  
> -#define TPM_ORD_SAVESTATE cpu_to_be32(152)
>  #define SAVESTATE_RESULT_SIZE 10
>  
>  static const struct tpm_input_header savestate_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(10),
> -	.ordinal = TPM_ORD_SAVESTATE
> +	.ordinal = cpu_to_be32(TPM_ORD_SAVESTATE)
>  };
>  
>  /*
> @@ -1079,7 +1072,7 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume);
>  static const struct tpm_input_header tpm_getrandom_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(14),
> -	.ordinal = TPM_ORD_GET_RANDOM
> +	.ordinal = cpu_to_be32(TPM_ORD_GETRANDOM)
>  };
>  
>  /**
> diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
> index 69a0741..413ac2c 100644
> --- a/drivers/char/tpm/tpm-sysfs.c
> +++ b/drivers/char/tpm/tpm-sysfs.c
> @@ -23,11 +23,10 @@
>  
>  #define READ_PUBEK_RESULT_SIZE 314
>  #define READ_PUBEK_RESULT_MIN_BODY_SIZE (28 + 256)
> -#define TPM_ORD_READPUBEK cpu_to_be32(124)
>  static const struct tpm_input_header tpm_readpubek_header = {
>  	.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
>  	.length = cpu_to_be32(30),
> -	.ordinal = TPM_ORD_READPUBEK
> +	.ordinal = cpu_to_be32(TPM_ORD_READPUBEK)
>  };
>  static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
>  			  char *buf)
> diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h
> index 727512e..0fe58d8 100644
> --- a/include/linux/tpm_command.h
> +++ b/include/linux/tpm_command.h
> @@ -20,6 +20,13 @@
>  #define TPM_ORD_OIAP                    10
>  #define TPM_ORD_SEAL                    23
>  #define TPM_ORD_UNSEAL                  24
> +#define TPM_ORD_GET_CAP                101
> +#define TPM_ORD_STARTUP                153
> +#define TPM_ORD_CONTINUE_SELFTEST       83
> +#define TPM_ORD_PCRREAD                 21
> +#define TPM_ORD_PCREXTEND               20
> +#define TPM_ORD_SAVESTATE              152
> +#define TPM_ORD_READPUBEK              124
>  
>  /* Other constants */
>  #define SRKHANDLE                       0x40000000
> -- 
> 2.9.3
> 
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> tpmdd-devel mailing list
> tpmdd-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tpmdd-devel

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web