From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Nayna Jain <nayna@linux.vnet.ibm.com>
Cc: linux-integrity@vger.kernel.org, zohar@linux.vnet.ibm.com,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, peterhuewe@gmx.de,
tpmdd@selhorst.net, jgunthorpe@obsidianresearch.com
Subject: Re: [PATCH v3] tpm: check selftest status before retrying full selftest
Date: Fri, 18 May 2018 10:04:08 +0300 [thread overview]
Message-ID: <20180518070408.GA9461@linux.intel.com> (raw)
In-Reply-To: <20180515071712.9331-1-nayna@linux.vnet.ibm.com>
On Tue, May 15, 2018 at 12:47:12PM +0530, Nayna Jain wrote:
> TPM 2.0 supports TPM2_GetTestResult[1], which can be used to check the
> selftest status. This patch implements the tpm2_get_selftest_result()
> function to check the selftest status before trying full selftest.
>
> [1] As per TCG Specification, Trusted Platform Module Library,
> Part 2 - Commands, Section 10.4:
>
> "This command(TPM2_GetTestResult) returns manufacturer-specific information
> regarding the results of a self-test and an indication of the test status.
>
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Tested-by: Mimi Zohar <zohar@linux.vnet.ibm.com> (on Pi with TPM 2.0)
> Tested-by: Stefan Berger <stefanb@linux.vnet.ibm.com> (With QEMU with
> swtpm TPM 2.0)
> ---
>
> Changelog:
>
> v3:
> * modified to check the selftest status before full selftest command is run
> * fixed the patch description
> * includes Jarkko's feedbacks
>
> v2:
> * changed the subject and updated patch description
> * removed the logs
>
> drivers/char/tpm/tpm.h | 2 ++
> drivers/char/tpm/tpm2-cmd.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 46 insertions(+)
>
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index af3bb87d3ea1..1de4240b52c4 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -114,6 +114,7 @@ enum tpm2_return_codes {
> TPM2_RC_FAILURE = 0x0101,
> TPM2_RC_DISABLED = 0x0120,
> TPM2_RC_COMMAND_CODE = 0x0143,
> + TPM2_RC_NEEDS_TEST = 0x0153,
> TPM2_RC_TESTING = 0x090A, /* RC_WARN */
> TPM2_RC_REFERENCE_H0 = 0x0910,
> TPM2_RC_RETRY = 0x0922,
> @@ -144,6 +145,7 @@ enum tpm2_command_codes {
> TPM2_CC_FLUSH_CONTEXT = 0x0165,
> TPM2_CC_GET_CAPABILITY = 0x017A,
> TPM2_CC_GET_RANDOM = 0x017B,
> + TPM2_CC_GET_TEST_RESULT = 0x017C,
> TPM2_CC_PCR_READ = 0x017E,
> TPM2_CC_PCR_EXTEND = 0x0182,
> TPM2_CC_LAST = 0x018F,
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 96c77c8e7f40..811bcf221208 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -825,6 +825,43 @@ unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
> EXPORT_SYMBOL_GPL(tpm2_calc_ordinal_duration);
>
> /**
> + * tpm2_get_selftest_result() - get the status of selftest
> + * @chip: TPM chip to use
> + *
> + * Return: TPM return code, errno otherwise
* Return:
* TPM return code,
* -errno otherwise
> + */
> +static int tpm2_get_selftest_result(struct tpm_chip *chip)
> +{
> + struct tpm_buf buf;
> + int rc;
> + int test_result;
> + uint16_t data_size;
> + int len;
> + const struct tpm_output_header *header;
> +
> + rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_TEST_RESULT);
> + if (rc)
> + return rc;
> +
> + len = tpm_transmit(chip, NULL, buf.data, PAGE_SIZE, 0);
> + if (len < 0)
> + return len;
> +
> + header = (struct tpm_output_header *)buf.data;
> +
> + rc = be32_to_cpu(header->return_code);
> + if (rc)
> + return rc;
> +
> + data_size = be16_to_cpup((__be16 *)&buf.data[TPM_HEADER_SIZE]);
> +
> + test_result = be32_to_cpup((__be32 *)
> + (&buf.data[TPM_HEADER_SIZE + 2 + data_size]));
Why you can't just use rc here like is done in every other function?
Sorry, did missed this in the previous review.
> +
> + return test_result;
> +}
> +
> +/**
> * tpm2_do_selftest() - ensure that all self tests have passed
> *
> * @chip: TPM chip to use
> @@ -857,6 +894,13 @@ static int tpm2_do_selftest(struct tpm_chip *chip)
> rc = TPM2_RC_SUCCESS;
> if (rc == TPM2_RC_INITIALIZE || rc == TPM2_RC_SUCCESS)
> return rc;
> +
> + rc = tpm2_get_selftest_result(chip);
> + dev_dbg(&chip->dev, "self test result is %04x\n", rc);
Please remove this dev_dbg() (also this one).
> +
> + if (rc == TPM2_RC_TESTING || rc == TPM2_RC_SUCCESS)
> + return TPM2_RC_SUCCESS;
> +
> }
>
> return rc;
> --
> 2.13.6
>
/Jarkko
WARNING: multiple messages have this Message-ID (diff)
From: jarkko.sakkinen@linux.intel.com (Jarkko Sakkinen)
To: linux-security-module@vger.kernel.org
Subject: [PATCH v3] tpm: check selftest status before retrying full selftest
Date: Fri, 18 May 2018 10:04:08 +0300 [thread overview]
Message-ID: <20180518070408.GA9461@linux.intel.com> (raw)
In-Reply-To: <20180515071712.9331-1-nayna@linux.vnet.ibm.com>
On Tue, May 15, 2018 at 12:47:12PM +0530, Nayna Jain wrote:
> TPM 2.0 supports TPM2_GetTestResult[1], which can be used to check the
> selftest status. This patch implements the tpm2_get_selftest_result()
> function to check the selftest status before trying full selftest.
>
> [1] As per TCG Specification, Trusted Platform Module Library,
> Part 2 - Commands, Section 10.4:
>
> "This command(TPM2_GetTestResult) returns manufacturer-specific information
> regarding the results of a self-test and an indication of the test status.
>
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> Tested-by: Mimi Zohar <zohar@linux.vnet.ibm.com> (on Pi with TPM 2.0)
> Tested-by: Stefan Berger <stefanb@linux.vnet.ibm.com> (With QEMU with
> swtpm TPM 2.0)
> ---
>
> Changelog:
>
> v3:
> * modified to check the selftest status before full selftest command is run
> * fixed the patch description
> * includes Jarkko's feedbacks
>
> v2:
> * changed the subject and updated patch description
> * removed the logs
>
> drivers/char/tpm/tpm.h | 2 ++
> drivers/char/tpm/tpm2-cmd.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 46 insertions(+)
>
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index af3bb87d3ea1..1de4240b52c4 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -114,6 +114,7 @@ enum tpm2_return_codes {
> TPM2_RC_FAILURE = 0x0101,
> TPM2_RC_DISABLED = 0x0120,
> TPM2_RC_COMMAND_CODE = 0x0143,
> + TPM2_RC_NEEDS_TEST = 0x0153,
> TPM2_RC_TESTING = 0x090A, /* RC_WARN */
> TPM2_RC_REFERENCE_H0 = 0x0910,
> TPM2_RC_RETRY = 0x0922,
> @@ -144,6 +145,7 @@ enum tpm2_command_codes {
> TPM2_CC_FLUSH_CONTEXT = 0x0165,
> TPM2_CC_GET_CAPABILITY = 0x017A,
> TPM2_CC_GET_RANDOM = 0x017B,
> + TPM2_CC_GET_TEST_RESULT = 0x017C,
> TPM2_CC_PCR_READ = 0x017E,
> TPM2_CC_PCR_EXTEND = 0x0182,
> TPM2_CC_LAST = 0x018F,
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 96c77c8e7f40..811bcf221208 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -825,6 +825,43 @@ unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
> EXPORT_SYMBOL_GPL(tpm2_calc_ordinal_duration);
>
> /**
> + * tpm2_get_selftest_result() - get the status of selftest
> + * @chip: TPM chip to use
> + *
> + * Return: TPM return code, errno otherwise
* Return:
* TPM return code,
* -errno otherwise
> + */
> +static int tpm2_get_selftest_result(struct tpm_chip *chip)
> +{
> + struct tpm_buf buf;
> + int rc;
> + int test_result;
> + uint16_t data_size;
> + int len;
> + const struct tpm_output_header *header;
> +
> + rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_TEST_RESULT);
> + if (rc)
> + return rc;
> +
> + len = tpm_transmit(chip, NULL, buf.data, PAGE_SIZE, 0);
> + if (len < 0)
> + return len;
> +
> + header = (struct tpm_output_header *)buf.data;
> +
> + rc = be32_to_cpu(header->return_code);
> + if (rc)
> + return rc;
> +
> + data_size = be16_to_cpup((__be16 *)&buf.data[TPM_HEADER_SIZE]);
> +
> + test_result = be32_to_cpup((__be32 *)
> + (&buf.data[TPM_HEADER_SIZE + 2 + data_size]));
Why you can't just use rc here like is done in every other function?
Sorry, did missed this in the previous review.
> +
> + return test_result;
> +}
> +
> +/**
> * tpm2_do_selftest() - ensure that all self tests have passed
> *
> * @chip: TPM chip to use
> @@ -857,6 +894,13 @@ static int tpm2_do_selftest(struct tpm_chip *chip)
> rc = TPM2_RC_SUCCESS;
> if (rc == TPM2_RC_INITIALIZE || rc == TPM2_RC_SUCCESS)
> return rc;
> +
> + rc = tpm2_get_selftest_result(chip);
> + dev_dbg(&chip->dev, "self test result is %04x\n", rc);
Please remove this dev_dbg() (also this one).
> +
> + if (rc == TPM2_RC_TESTING || rc == TPM2_RC_SUCCESS)
> + return TPM2_RC_SUCCESS;
> +
> }
>
> return rc;
> --
> 2.13.6
>
/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-05-18 7:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-15 7:17 [PATCH v3] tpm: check selftest status before retrying full selftest Nayna Jain
2018-05-15 7:17 ` Nayna Jain
2018-05-18 7:04 ` Jarkko Sakkinen [this message]
2018-05-18 7:04 ` Jarkko Sakkinen
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=20180518070408.GA9461@linux.intel.com \
--to=jarkko.sakkinen@linux.intel.com \
--cc=jgunthorpe@obsidianresearch.com \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=nayna@linux.vnet.ibm.com \
--cc=peterhuewe@gmx.de \
--cc=tpmdd@selhorst.net \
--cc=zohar@linux.vnet.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.