tpmdd-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Roberto Sassu <roberto.sassu@huawei.com>
Cc: tpmdd-devel@lists.sourceforge.net,
	linux-ima-devel@lists.sourceforge.net,
	linux-security-module@vger.kernel.org, keyrings@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [tpmdd-devel] [PATCH v3 2/6] tpm: use tpm2_pcr_read_tpm_buf() in tpm2_do_selftest()
Date: Fri, 23 Jun 2017 11:55:11 +0200	[thread overview]
Message-ID: <20170623095511.3yxnrzujwnaliozz@linux.intel.com> (raw)
In-Reply-To: <20170621142941.32674-3-roberto.sassu@huawei.com>

On Wed, Jun 21, 2017 at 04:29:37PM +0200, Roberto Sassu wrote:
> tpm2_do_selftest() performs a PCR read during the TPM initialization phase.
> This patch replaces the PCR read code with a call to
> tpm2_pcr_read_tpm_buf(). tpm2_do_selftest() parses the result of the
> TPM command, in order to retrieve the return code.
> 
> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>

Work this out with a call to tpm2_pcr_read() instead.

/Jarkko

> ---
>  drivers/char/tpm/tpm2-cmd.c | 32 ++++++++++----------------------
>  1 file changed, 10 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index afd1b63..6a9fe0d 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -227,16 +227,6 @@ static const u8 tpm2_ordinal_duration[TPM2_CC_LAST - TPM2_CC_FIRST + 1] = {
>  	TPM_UNDEFINED		/* 18f */
>  };
>  
> -#define TPM2_PCR_READ_IN_SIZE \
> -	(sizeof(struct tpm_input_header) + \
> -	 sizeof(struct tpm2_pcr_read_in))
> -
> -static const struct tpm_input_header tpm2_pcrread_header = {
> -	.tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
> -	.length = cpu_to_be32(TPM2_PCR_READ_IN_SIZE),
> -	.ordinal = cpu_to_be32(TPM2_CC_PCR_READ)
> -};
> -
>  static int tpm2_pcr_read_tpm_buf(struct tpm_chip *chip, int pcr_idx,
>  				 enum tpm2_algorithms algo, struct tpm_buf *buf,
>  				 char *msg)
> @@ -938,7 +928,8 @@ static int tpm2_do_selftest(struct tpm_chip *chip)
>  	unsigned int loops;
>  	unsigned int delay_msec = 100;
>  	unsigned long duration;
> -	struct tpm2_cmd cmd;
> +	struct tpm_buf buf;
> +	tpm_cmd_header *header;
>  	int i;
>  
>  	duration = tpm2_calc_ordinal_duration(chip, TPM2_CC_SELF_TEST);
> @@ -951,20 +942,17 @@ static int tpm2_do_selftest(struct tpm_chip *chip)
>  
>  	for (i = 0; i < loops; i++) {
>  		/* Attempt to read a PCR value */
> -		cmd.header.in = tpm2_pcrread_header;
> -		cmd.params.pcrread_in.pcr_selects_cnt = cpu_to_be32(1);
> -		cmd.params.pcrread_in.hash_alg = cpu_to_be16(TPM2_ALG_SHA1);
> -		cmd.params.pcrread_in.pcr_select_size = TPM2_PCR_SELECT_MIN;
> -		cmd.params.pcrread_in.pcr_select[0] = 0x01;
> -		cmd.params.pcrread_in.pcr_select[1] = 0x00;
> -		cmd.params.pcrread_in.pcr_select[2] = 0x00;
> -
> -		rc = tpm_transmit_cmd(chip, NULL, &cmd, sizeof(cmd), 0, 0,
> -				      NULL);
> +		rc = tpm2_pcr_read_tpm_buf(chip, 0, TPM2_ALG_SHA1, &buf, NULL);
> +		if (rc >= 0) {
> +			header = (tpm_cmd_header *)buf.data;
> +			rc = be32_to_cpu(header->out.return_code);
> +		}
> +
> +		tpm_buf_destroy(&buf);
> +
>  		if (rc < 0)
>  			break;
>  
> -		rc = be32_to_cpu(cmd.header.out.return_code);
>  		if (rc != TPM2_RC_TESTING)
>  			break;
>  
> -- 
> 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

  reply	other threads:[~2017-06-23  9:55 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-21 14:29 [PATCH v3 0/6] Updated API for TPM 2.0 PCR extend Roberto Sassu
2017-06-21 14:29 ` [PATCH v3 4/6] tpm: replace TPM algorithms IDs with tpm_pcr_bank_info structs in tpm_chip Roberto Sassu
2017-06-23 10:32   ` Jarkko Sakkinen
2017-06-21 14:29 ` [PATCH v3 5/6] tpm: introduce tpm_get_pcr_banks_info() Roberto Sassu
2017-06-23 10:35   ` Jarkko Sakkinen
2017-06-21 14:29 ` [PATCH v3 6/6] tpm: pass multiple digests to tpm_pcr_extend() Roberto Sassu
     [not found]   ` <20170621142941.32674-7-roberto.sassu-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2017-06-23 10:37     ` Jarkko Sakkinen
     [not found] ` <20170621142941.32674-1-roberto.sassu-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2017-06-21 14:29   ` [PATCH v3 1/6] tpm: use tpm_buf functions to perform a PCR read Roberto Sassu
2017-06-22 10:14     ` [tpmdd-devel] " Jarkko Sakkinen
     [not found]       ` <20170622101404.blfpqcryrbe35ha4-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-22 11:54         ` Roberto Sassu
2017-06-23 10:56           ` [tpmdd-devel] " Jarkko Sakkinen
2017-06-21 14:29   ` [PATCH v3 2/6] tpm: use tpm2_pcr_read_tpm_buf() in tpm2_do_selftest() Roberto Sassu
2017-06-23  9:55     ` Jarkko Sakkinen [this message]
2017-06-23 10:22       ` [tpmdd-devel] " Roberto Sassu
2017-06-21 14:29   ` [PATCH v3 3/6] tpm: introduce tpm_pcr_bank_info structure with digest_size from TPM Roberto Sassu
2017-06-23 10:26     ` Jarkko Sakkinen
     [not found]       ` <20170623102606.3xkuqbslr3g3o22s-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-23 11:25         ` Roberto Sassu
     [not found]     ` <20170621142941.32674-4-roberto.sassu-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2017-06-27 15:24       ` Mimi Zohar
2017-06-24  9:03   ` [PATCH v3 0/6] Updated API for TPM 2.0 PCR extend Jarkko Sakkinen
     [not found]     ` <20170624090325.kbqhwkrx5qvtxveg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-26  6:58       ` Roberto Sassu
2017-06-26  7:21       ` Roberto Sassu
2017-06-28 17:10         ` Jarkko Sakkinen
2017-06-26 12:33     ` [Linux-ima-devel] " Mimi Zohar
2017-06-26 14:56       ` Roberto Sassu
2017-06-26 17:12         ` Mimi Zohar
2017-06-28 17:28       ` Jarkko Sakkinen
2017-06-28 22:28         ` Mimi Zohar
2017-07-05 15:18         ` [tpmdd-devel] " Ken Goldman
2017-07-05 16:06           ` Mimi Zohar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170623095511.3yxnrzujwnaliozz@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-ima-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=roberto.sassu@huawei.com \
    --cc=tpmdd-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).