linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mimi Zohar <zohar@linux.ibm.com>
To: Roberto Sassu <roberto.sassu@huawei.com>,
	jarkko.sakkinen@linux.intel.com
Cc: linux-integrity@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, silviu.vlasceanu@huawei.com
Subject: Re: [PATCH v3 5/5] tpm: ensure that output of PCR read contains the correct digest size
Date: Thu, 01 Nov 2018 12:52:10 -0400	[thread overview]
Message-ID: <1541091130.4035.41.camel@linux.ibm.com> (raw)
In-Reply-To: <20181030154711.2782-6-roberto.sassu@huawei.com>

On Tue, 2018-10-30 at 16:47 +0100, Roberto Sassu wrote:
> This patch ensures that the digest size returned by the TPM during a PCR
> read matches the size of the algorithm passed as argument to
> tpm2_pcr_read(). The check is performed after information about the PCR
> banks has been retrieved.
> 
> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> ---
>  drivers/char/tpm/tpm2-cmd.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 8e821e7b4674..477dcc30fc53 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -187,15 +187,28 @@ struct tpm2_pcr_read_out {
>  int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx,
>  		  struct tpm_digest *digest_struct, u16 *digest_size_ptr)
>  {
> +	int i;
>  	int rc;
>  	struct tpm_buf buf;
>  	struct tpm2_pcr_read_out *out;
>  	u8 pcr_select[TPM2_PCR_SELECT_MIN] = {0};
>  	u16 digest_size;
> +	u16 expected_digest_size = 0;
>  
>  	if (pcr_idx >= TPM2_PLATFORM_PCR)
>  		return -EINVAL;
>  
> +	if (!digest_size_ptr) {
> +		for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
> +		     chip->active_banks[i].alg_id != digest_struct->alg_id; i++)
> +			;
> +
> +		if (i == ARRAY_SIZE(chip->active_banks))
> +			return -EINVAL;
> +
> +		expected_digest_size = chip->active_banks[i].digest_size;
> +	}
> +
>  	rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_PCR_READ);
>  	if (rc)
>  		return rc;
> @@ -215,7 +228,8 @@ int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx,
>  
>  	out = (struct tpm2_pcr_read_out *)&buf.data[TPM_HEADER_SIZE];
>  	digest_size = be16_to_cpu(out->digest_size);
> -	if (digest_size > sizeof(digest_struct->digest)) {
> +	if ((digest_size_ptr && digest_size > sizeof(digest_struct->digest)) ||

The returned digest size should never be larger than the structure
field.  The digest_size_ptr test is unnecessary.

Mimi

> +	    (!digest_size_ptr && digest_size != expected_digest_size)) {
>  		rc = -EINVAL;
>  		goto out;
>  	}


      parent reply	other threads:[~2018-11-01 16:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-30 15:47 [PATCH v3 0/5] tpm: retrieve digest size of unknown algorithms from TPM Roberto Sassu
2018-10-30 15:47 ` [PATCH v3 1/5] tpm: change the end marker of the active_banks array to zero Roberto Sassu
2018-10-30 19:45   ` Jarkko Sakkinen
2018-10-31 14:43   ` Mimi Zohar
2018-11-01 14:42     ` Mimi Zohar
2018-11-05  8:10       ` Roberto Sassu
2018-11-05 13:02         ` Mimi Zohar
2018-11-05  8:07     ` Roberto Sassu
2018-10-30 15:47 ` [PATCH v3 2/5] tpm: rename and export tpm2_digest and tpm2_algorithms Roberto Sassu
2018-10-30 15:47 ` [PATCH v3 3/5] tpm: modify tpm_pcr_read() definition to pass a TPM hash algorithm Roberto Sassu
2018-10-30 15:47 ` [PATCH v3 4/5] tpm: retrieve digest size of unknown algorithms with PCR read Roberto Sassu
2018-11-01 16:02   ` Mimi Zohar
2018-11-01 16:23     ` Mimi Zohar
2018-11-05  9:47     ` Roberto Sassu
2018-11-05 12:01       ` Jarkko Sakkinen
2018-11-05 13:09         ` Roberto Sassu
2018-11-05 14:48           ` Mimi Zohar
2018-11-05 17:13           ` Jarkko Sakkinen
2018-11-05 17:10         ` Jarkko Sakkinen
2018-10-30 15:47 ` [PATCH v3 5/5] tpm: ensure that output of PCR read contains the correct digest size Roberto Sassu
2018-10-30 19:52   ` Jarkko Sakkinen
2018-10-31  8:16     ` Roberto Sassu
2018-11-01 14:32       ` Jarkko Sakkinen
2018-11-01 16:52   ` Mimi Zohar [this message]

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=1541091130.4035.41.camel@linux.ibm.com \
    --to=zohar@linux.ibm.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=roberto.sassu@huawei.com \
    --cc=silviu.vlasceanu@huawei.com \
    /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).