From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Nayna Jain <nayna@linux.vnet.ibm.com>
Cc: tpmdd-devel@lists.sourceforge.net,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, peterhuewe@gmx.de,
tpmdd@selhorst.net, jgunthorpe@obsidianresearch.com
Subject: Re: [PATCH v2 1/2] tpm: implement TPM 2.0 capability to get active PCR banks
Date: Tue, 3 Jan 2017 20:52:36 +0200 [thread overview]
Message-ID: <20170103185236.g4a4wu66ivmtoqad@intel.com> (raw)
In-Reply-To: <1483124550-9529-2-git-send-email-nayna@linux.vnet.ibm.com>
On Fri, Dec 30, 2016 at 02:02:29PM -0500, Nayna Jain wrote:
> This patch implements the TPM 2.0 capability TPM_CAP_PCRS to
> retrieve the active PCR banks from the TPM. This is needed
> to enable extending all active banks as recommended by TPM 2.0
> TCG Specification.
>
> Signed-off-by: Nayna Jain <nayna@linux.vnet.ibm.com>
> ---
> drivers/char/tpm/tpm.h | 5 +++
> drivers/char/tpm/tpm2-cmd.c | 79 +++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 84 insertions(+)
>
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 1ae9768..3d8121e 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -43,6 +43,7 @@ enum tpm_const {
> TPM_NUM_DEVICES = 65536,
> TPM_RETRY = 50, /* 5 seconds */
> TPM_NUM_EVENT_LOG_FILES = 3,
> + TPM2_MAX_PCR_BANKS = 7,
Remove and use ARRAY_SIZE().
> };
>
> enum tpm_timeout {
> @@ -127,6 +128,7 @@ enum tpm2_permanent_handles {
> };
>
> enum tpm2_capabilities {
> + TPM2_CAP_PCRS = 5,
> TPM2_CAP_TPM_PROPERTIES = 6,
> };
>
> @@ -187,6 +189,8 @@ struct tpm_chip {
>
> const struct attribute_group *groups[3];
> unsigned int groups_cnt;
> +
> + enum tpm2_algorithms active_banks[TPM2_MAX_PCR_BANKS];
u16
> #ifdef CONFIG_ACPI
> acpi_handle acpi_dev_handle;
> char ppi_version[TPM_PPI_VERSION_LEN + 1];
> @@ -545,4 +549,5 @@ int tpm2_auto_startup(struct tpm_chip *chip);
> void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type);
> unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
> int tpm2_probe(struct tpm_chip *chip);
> +ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
> #endif
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 6eda239..dd03fd8 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -83,6 +83,25 @@ struct tpm2_get_tpm_pt_out {
> __be32 value;
> } __packed;
>
> +struct tpm2_tpms_pcr_selection {
> + __be16 hash_alg;
> + u8 size_of_select;
> + u8 pcr_select[3];
> +} __packed;
> +
> +struct tpm2_getcap_in {
> + __be32 cap_id;
> + __be32 property_id;
> + __be32 property_cnt;
> +} __packed;
> +
> +struct tpm2_getcap_out {
> + u8 more_data;
> + __be32 subcap_id;
> + __be32 count;
> + char cap_data[0];
> +} __packed;
> +
Use tpm_buf and remove tpm2_getcap_in.
Remove tpm2_getcap_out.
Remove alignment.
> struct tpm2_get_random_in {
> __be16 size;
> } __packed;
> @@ -100,6 +119,8 @@ union tpm2_cmd_params {
> struct tpm2_pcr_extend_in pcrextend_in;
> struct tpm2_get_tpm_pt_in get_tpm_pt_in;
> struct tpm2_get_tpm_pt_out get_tpm_pt_out;
> + struct tpm2_getcap_in getcap_in;
> + struct tpm2_getcap_out getcap_out;
Do not put anything into this union. It is deprecated.
> struct tpm2_get_random_in getrandom_in;
> struct tpm2_get_random_out getrandom_out;
> };
> @@ -993,8 +1014,66 @@ int tpm2_auto_startup(struct tpm_chip *chip)
> }
> }
>
> + rc = tpm2_get_pcr_allocation(chip);
> +
> out:
> if (rc > 0)
> rc = -ENODEV;
> return rc;
> }
> +
> +#define TPM2_GETCAP_IN_SIZE \
> + (sizeof(struct tpm_input_header) + sizeof(struct tpm2_getcap_in))
> +
> +static const struct tpm_input_header tpm2_getcap_header = {
> + .tag = cpu_to_be16(TPM2_ST_NO_SESSIONS),
> + .length = cpu_to_be32(TPM2_GETCAP_IN_SIZE),
> + .ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY)
> +};
> +
> +/**
> + * tpm2_get_pcr_allocation() - get TPM active PCR banks.
> + *
> + * @chip: TPM chip to use.
> + *
> + * Return: Same as with tpm_transmit_cmd.
> + */
> +ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
> +{
> + struct tpm2_cmd cmd;
> + struct tpm2_tpms_pcr_selection pcr_selection;
> + void *marker;
> + unsigned int count = 0;
> + int rc;
> + int i;
> +
> + cmd.header.in = tpm2_getcap_header;
> + cmd.params.getcap_in.cap_id = cpu_to_be32(TPM2_CAP_PCRS);
> + cmd.params.getcap_in.property_id = cpu_to_be32(0);
> + cmd.params.getcap_in.property_cnt = cpu_to_be32(1);
> +
> + rc = tpm_transmit_cmd(chip, &cmd, sizeof(cmd), 0,
> + "get tpm pcr allocation");
> + if (rc < 0)
> + goto out;
> +
> + count = be32_to_cpu(cmd.params.getcap_out.count);
> + if (count > TPM2_MAX_PCR_BANKS) {
> + dev_err(&chip->dev,
> + "%s: Error: Invalid active PCR banks count\n",
"Error:" is redundant.
> + __func__);
> + return -ENODEV;
> + }
> +
> + marker = &cmd.params.getcap_out.cap_data;
> + for (i = 0; i < count; i++) {
> + memcpy(&pcr_selection, marker, sizeof(pcr_selection));
> + chip->active_banks[i] = be16_to_cpu(pcr_selection.hash_alg);
> + marker = marker + sizeof(struct tpm2_tpms_pcr_selection);
> + }
> +
> +out:
> + if (count < TPM2_MAX_PCR_BANKS)
> + chip->active_banks[count] = 0;
> + return rc;
> +}
> --
> 2.5.0
/Jarkko
next prev parent reply other threads:[~2017-01-03 18:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-30 19:02 [PATCH v2 0/2] tpm: enhance TPM 2.0 extend function to support multiple PCR banks Nayna Jain
2016-12-30 19:02 ` [PATCH v2 1/2] tpm: implement TPM 2.0 capability to get active " Nayna Jain
2017-01-03 18:52 ` Jarkko Sakkinen [this message]
2016-12-30 19:02 ` [PATCH v2 2/2] tpm: enhance TPM 2.0 PCR extend to support multiple banks Nayna Jain
2016-12-30 20:53 ` kbuild test robot
2016-12-30 21:17 ` kbuild test robot
2017-01-03 18:54 ` Jarkko Sakkinen
2017-01-02 22:15 ` [PATCH v2 0/2] tpm: enhance TPM 2.0 extend function to support multiple PCR banks Jarkko Sakkinen
2017-01-03 12:27 ` [tpmdd-devel] " Mimi Zohar
2017-01-03 13:55 ` Jarkko Sakkinen
2017-01-03 13:29 ` 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=20170103185236.g4a4wu66ivmtoqad@intel.com \
--to=jarkko.sakkinen@linux.intel.com \
--cc=jgunthorpe@obsidianresearch.com \
--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-devel@lists.sourceforge.net \
--cc=tpmdd@selhorst.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