Re: [PATCH v3 3/3] KEYS: trusted: Reserve TPM for seal and unseal operations

From: James Bottomley
Date: Mon Oct 12 2020 - 22:42:03 EST


On Tue, 2020-10-13 at 03:28 +0300, Jarkko Sakkinen wrote:
[...]
> diff --git a/include/linux/tpm.h b/include/linux/tpm.h
> index 8f4ff39f51e7..f0ebce14d2f8 100644
> --- a/include/linux/tpm.h
> +++ b/include/linux/tpm.h
> @@ -397,6 +397,10 @@ static inline u32 tpm2_rc_value(u32 rc)
> #if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
>
> extern int tpm_is_tpm2(struct tpm_chip *chip);
> +extern __must_check int tpm_try_get_ops(struct tpm_chip *chip);
> +extern void tpm_put_ops(struct tpm_chip *chip);
> +extern ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct
> tpm_buf *buf,
> + size_t min_rsp_body_length, const char
> *desc);
> extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
> struct tpm_digest *digest);
> extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
> @@ -410,7 +414,18 @@ static inline int tpm_is_tpm2(struct tpm_chip
> *chip)
> {
> return -ENODEV;
> }
> -
> +static inline int tpm_try_get_ops(struct tpm_chip *chip)
> +{
> + return -ENODEV;
> +}
> +static inline void tpm_put_ops(struct tpm_chip *chip)
> +{
> +}
> +static inline ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct
> tpm_buf *buf,
> + size_t min_rsp_body_length,
> const char *desc)
> +{
> + return -ENODEV;
> +}
> static inline int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx,

I don't think we want this, do we? That's only for API access which
should be available when the TPM isn't selected. Given that get/put
are TPM critical operations, they should only appear when inside code
where the TPM has already been selected. If they appear outside TPM
selected code, I think we want the compile to fail, which is why we
don't want these backup definitions.

James