From: Greg KH <greg@kroah.com>
To: James Bottomley <James.Bottomley@hansenpartnership.com>
Cc: linux-integrity@vger.kernel.org, Mimi Zohar <zohar@linux.ibm.com>,
Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
linux-api@vger.kernel.org
Subject: Re: [PATCH v5 1/1] tpm: add sysfs exports for all banks of PCR registers
Date: Wed, 13 Jan 2021 08:50:11 +0100 [thread overview]
Message-ID: <X/6mM/egPLyXASM9@kroah.com> (raw)
In-Reply-To: <20210113015958.6685-2-James.Bottomley@HansenPartnership.com>
On Tue, Jan 12, 2021 at 05:59:58PM -0800, James Bottomley wrote:
> Create sysfs per hash groups with 24 PCR files in them one group,
> named pcr-<hash>, for each agile hash of the TPM. The files are
> plugged in to a PCR read function which is TPM version agnostic, so
> this works also for TPM 1.2 but the hash is only sha1 in that case.
>
> Note: the macros used to create the hashes emit spurious checkpatch
> warnings. Do not try to "fix" them as checkpatch recommends, otherwise
> they'll break.
>
> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
> Tested-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
>
> ---
>
> v2: fix TPM 1.2 legacy links failure
> v3: fix warn on and add note to tpm_algorithms
> v4: reword commit and add tested-by
> v5: algorithm spelling fix WARN->dev_err
> ---
> drivers/char/tpm/tpm-sysfs.c | 179 +++++++++++++++++++++++++++++++++++
> include/linux/tpm.h | 9 +-
> 2 files changed, 187 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
> index e2ff0b273a0f..63f03cfb8e6a 100644
> --- a/drivers/char/tpm/tpm-sysfs.c
> +++ b/drivers/char/tpm/tpm-sysfs.c
> @@ -337,11 +337,190 @@ static const struct attribute_group tpm2_dev_group = {
> .attrs = tpm2_dev_attrs,
> };
>
> +struct tpm_pcr_attr {
> + int alg_id;
> + int pcr;
> + struct device_attribute attr;
> +};
> +
> +#define to_tpm_pcr_attr(a) container_of(a, struct tpm_pcr_attr, attr)
> +
> +static ssize_t pcr_value_show(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + struct tpm_pcr_attr *ha = to_tpm_pcr_attr(attr);
> + struct tpm_chip *chip = to_tpm_chip(dev);
> + struct tpm_digest digest;
> + int i;
> + int digest_size = 0;
> + int rc;
> + char *str = buf;
> +
> + for (i = 0; i < chip->nr_allocated_banks; i++)
> + if (ha->alg_id == chip->allocated_banks[i].alg_id)
> + digest_size = chip->allocated_banks[i].digest_size;
> + /* should never happen */
> + if (!digest_size)
> + return -EINVAL;
> +
> + digest.alg_id = ha->alg_id;
> + rc = tpm_pcr_read(chip, ha->pcr, &digest);
> + if (rc)
> + return rc;
> + for (i = 0; i < digest_size; i++)
> + str += sprintf(str, "%02X", digest.digest[i]);
> + str += sprintf(str, "\n");
sysfs_emit()?
> +
> + return str - buf;
> +}
> +
> +/*
> + * The following set of defines represents all the magic to build
> + * the per hash attribute groups for displaying each bank of PCRs.
> + * The only slight problem with this approach is that every PCR is
> + * hard coded to be present, so you don't know if an PCR is missing
> + * until a cat of the file returns -EINVAL
> + *
> + * Also note you must ignore checkpatch warnings in this macro
> + * code. This is deep macro magic that checkpatch.pl doesn't
> + * understand.
> + */
> +
> +/* Note, this must match TPM2_PLATFORM_PCR which is fixed at 24. */
> +#define _TPM_HELPER(_alg, _hash, F) \
> + F(_alg, _hash, 0) \
> + F(_alg, _hash, 1) \
> + F(_alg, _hash, 2) \
> + F(_alg, _hash, 3) \
> + F(_alg, _hash, 4) \
> + F(_alg, _hash, 5) \
> + F(_alg, _hash, 6) \
> + F(_alg, _hash, 7) \
> + F(_alg, _hash, 8) \
> + F(_alg, _hash, 9) \
> + F(_alg, _hash, 10) \
> + F(_alg, _hash, 11) \
> + F(_alg, _hash, 12) \
> + F(_alg, _hash, 13) \
> + F(_alg, _hash, 14) \
> + F(_alg, _hash, 15) \
> + F(_alg, _hash, 16) \
> + F(_alg, _hash, 17) \
> + F(_alg, _hash, 18) \
> + F(_alg, _hash, 19) \
> + F(_alg, _hash, 20) \
> + F(_alg, _hash, 21) \
> + F(_alg, _hash, 22) \
> + F(_alg, _hash, 23)
> +
> +/* ignore checkpatch warning about trailing ; in macro. */
> +#define PCR_ATTR(_alg, _hash, _pcr) \
> + static struct tpm_pcr_attr dev_attr_pcr_##_hash##_##_pcr = { \
> + .alg_id = _alg, \
> + .pcr = _pcr, \
> + .attr = { \
> + .attr = { \
> + .name = __stringify(_pcr), \
> + .mode = 0444 \
> + }, \
__ATTR_RO()?
> void tpm_sysfs_add_device(struct tpm_chip *chip)
> {
> + int i;
> +
> WARN_ON(chip->groups_cnt != 0);
> +
How can that WARN_ON happen?
thanks,
greg k-h
next prev parent reply other threads:[~2021-01-13 7:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-13 1:59 [PATCH v5 0/1] add sysfs exports for TPM 2 PCR registers James Bottomley
2021-01-13 1:59 ` [PATCH v5 1/1] tpm: add sysfs exports for all banks of " James Bottomley
2021-01-13 7:48 ` Greg KH
2021-01-13 17:31 ` James Bottomley
2021-01-13 22:14 ` Jarkko Sakkinen
2021-01-14 2:55 ` James Bottomley
2021-01-13 7:50 ` Greg KH [this message]
2021-01-15 18:04 ` James Bottomley
2021-01-13 20:48 ` [PATCH v5 0/1] add sysfs exports for TPM 2 " Jarkko Sakkinen
2021-01-13 21:02 ` James Bottomley
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=X/6mM/egPLyXASM9@kroah.com \
--to=greg@kroah.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=jarkko.sakkinen@linux.intel.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=zohar@linux.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 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).