public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Alexander Steffen <Alexander.Steffen@infineon.com>
Cc: linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org,
	peterhuewe@gmx.de, jgg@ziepe.ca,
	krzysztof.kozlowski+dt@linaro.org,
	Johannes Holland <johannes.holland@infineon.com>,
	Amir Mizinski <amirmizi6@gmail.com>
Subject: Re: [PATCH v5 2/3] tpm: Add tpm_tis_verify_crc to the tpm_tis_phy_ops protocol layer
Date: Tue, 7 Jun 2022 12:56:03 +0300	[thread overview]
Message-ID: <Yp8gsy2vv4Y0luYQ@iki.fi> (raw)
In-Reply-To: <20220603143532.8202-3-Alexander.Steffen@infineon.com>

On Fri, Jun 03, 2022 at 04:35:31PM +0200, Alexander Steffen wrote:
> Some TPMs, e.g. those implementing the I2C variant of TIS, can verify
> data transfers to/from the FIFO with a CRC. The CRC is calculated over
> the entirety of the FIFO register. Since the phy_ops layer is not aware
> when the core layer is done reading/writing the FIFO, CRC verification
> must be triggered from the core layer. To this end, add an optional
> phy_ops API call.
> 
> Co-developed-by: Johannes Holland <johannes.holland@infineon.com>
> Signed-off-by: Johannes Holland <johannes.holland@infineon.com>
> Signed-off-by: Alexander Steffen <Alexander.Steffen@infineon.com>
> Change-Id: I43716c8d45f62c0fcdaabfc3366f8deb89fd1f32

Strip off Change-Id.

> ---
>  drivers/char/tpm/tpm_tis_core.c | 14 ++++++++++++++
>  drivers/char/tpm/tpm_tis_core.h | 10 ++++++++++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
> index dc56b976d816..757623bacfd5 100644
> --- a/drivers/char/tpm/tpm_tis_core.c
> +++ b/drivers/char/tpm/tpm_tis_core.c
> @@ -289,6 +289,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
>  	int size = 0;
>  	int status;
>  	u32 expected;
> +	int rc;
>  
>  	if (count < TPM_HEADER_SIZE) {
>  		size = -EIO;
> @@ -328,6 +329,13 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
>  		goto out;
>  	}
>  
> +	rc = tpm_tis_verify_crc(priv, (size_t)size, buf);
> +	if (rc < 0) {
> +		dev_err(&chip->dev, "CRC mismatch for response.\n");
> +		size = rc;
> +		goto out;
> +	}
> +
>  out:
>  	tpm_tis_ready(chip);
>  	return size;
> @@ -443,6 +451,12 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len)
>  	if (rc < 0)
>  		return rc;
>  
> +	rc = tpm_tis_verify_crc(priv, len, buf);
> +	if (rc < 0) {
> +		dev_err(&chip->dev, "CRC mismatch for command.\n");
> +		return rc;
> +	}
> +
>  	/* go and do it */
>  	rc = tpm_tis_write8(priv, TPM_STS(priv->locality), TPM_STS_GO);
>  	if (rc < 0)
> diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h
> index 6c203f36b8a1..66a5a13cd1df 100644
> --- a/drivers/char/tpm/tpm_tis_core.h
> +++ b/drivers/char/tpm/tpm_tis_core.h
> @@ -121,6 +121,8 @@ struct tpm_tis_phy_ops {
>  			  u8 *result, enum tpm_tis_io_mode mode);
>  	int (*write_bytes)(struct tpm_tis_data *data, u32 addr, u16 len,
>  			   const u8 *value, enum tpm_tis_io_mode mode);
> +	int (*verify_crc)(struct tpm_tis_data *data, size_t len,
> +			  const u8 *value);
>  };
>  
>  static inline int tpm_tis_read_bytes(struct tpm_tis_data *data, u32 addr,
> @@ -188,6 +190,14 @@ static inline int tpm_tis_write32(struct tpm_tis_data *data, u32 addr,
>  	return rc;
>  }
>  
> +static inline int tpm_tis_verify_crc(struct tpm_tis_data *data, size_t len,
> +				     const u8 *value)
> +{
> +	if (!data->phy_ops->verify_crc)
> +		return 0;

I think it would be more readable to have one empty line here.

> +	return data->phy_ops->verify_crc(data, len, value);
> +}
> +
>  static inline bool is_bsw(void)
>  {
>  #ifdef CONFIG_X86
> -- 
> 2.25.1
> 

Other than that LGTM.

BR, Jarkko

  reply	other threads:[~2022-06-07  9:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-03 14:35 [PATCH v5 0/3] tpm_tis_i2c Alexander Steffen
2022-06-03 14:35 ` [PATCH v5 1/3] dt-bindings: trivial-devices: Add two I2C TPM devices Alexander Steffen
2022-06-05 22:56   ` Rob Herring
2022-06-03 14:35 ` [PATCH v5 2/3] tpm: Add tpm_tis_verify_crc to the tpm_tis_phy_ops protocol layer Alexander Steffen
2022-06-07  9:56   ` Jarkko Sakkinen [this message]
2022-06-03 14:35 ` [PATCH v5 3/3] tpm: Add tpm_tis_i2c backend for tpm_tis_core Alexander Steffen
2022-06-07 10:00   ` 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=Yp8gsy2vv4Y0luYQ@iki.fi \
    --to=jarkko@kernel.org \
    --cc=Alexander.Steffen@infineon.com \
    --cc=amirmizi6@gmail.com \
    --cc=jgg@ziepe.ca \
    --cc=johannes.holland@infineon.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    /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