All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe Ricard <christophe.ricard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org
Cc: jean-luc.blanc-qxv4g6HH51o@public.gmane.org,
	ashley-fm2HMyfA2y6tG0bUXCXiUA@public.gmane.org,
	tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	christophe-h.ricard-qxv4g6HH51o@public.gmane.org,
	benoit.houyere-qxv4g6HH51o@public.gmane.org
Subject: [PATCH 11/12] tpm: Add check_data handle to tpm_class_ops in order to check data integrity
Date: Sun, 20 Mar 2016 20:34:42 +0100	[thread overview]
Message-ID: <1458502483-16887-12-git-send-email-christophe-h.ricard@st.com> (raw)
In-Reply-To: <1458502483-16887-1-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>

For example, in order to compute crc over the data sent in lower layer
(i2c for instance), provide a specific handle.

The current principles:
- When sending command:
1) Host writes TPM_STS.commandReady
2) Host writes command
3) Host checks TPM received data correctly
4) if not go to step 1

- When receiving data:
1) Host check TPM_STS.dataAvail is set
2) Host get data
3) Host check received data are correct.
4) if not Host write TPM_STS.responseRetry and go to step 1.

Signed-off-by: Christophe Ricard <christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
---
 drivers/char/tpm/tpm_tis_core.c | 81 ++++++++++++++++++++++++++---------------
 include/linux/tpm.h             |  1 +
 2 files changed, 52 insertions(+), 30 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index baa9ab1..9efb3ac 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -126,6 +126,14 @@ again:
 	return -1;
 }
 
+static bool tpm_tis_check_data(struct tpm_chip *chip, u8 *buf, size_t len)
+{
+	if (chip->ops->check_data)
+		return chip->ops->check_data(chip, buf, len);
+
+	return true;
+}
+
 u8 tpm_tis_status(struct tpm_chip *chip)
 {
 	return tpm_read_byte(chip, TPM_STS(chip->vendor.locality));
@@ -197,7 +205,8 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
 int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 {
 	int size = 0;
-	int expected, status;
+	int expected, status, i;
+	bool check_data = false;
 
 	if (count < TPM_HEADER_SIZE) {
 		size = -EIO;
@@ -206,34 +215,41 @@ int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 
 	tpm_tis_clear_int(chip);
 
-	/* read first 10 bytes, including tag, paramsize, and result */
-	size = recv_data(chip, buf, TPM_HEADER_SIZE);
-	if (size < TPM_HEADER_SIZE) {
-		dev_err(&chip->dev, "Unable to read header\n");
-		goto out;
-	}
+	for (i = 0; i < TPM_RETRY && !check_data; i++) {
+		/* read first 10 bytes, including tag, paramsize, and result */
+		size = recv_data(chip, buf, TPM_HEADER_SIZE);
+		if (size < TPM_HEADER_SIZE) {
+			dev_err(&chip->dev, "Unable to read header\n");
+			goto out;
+		}
 
-	expected = be32_to_cpu(*(__be32 *) (buf + 2));
-	if (expected > count) {
-		size = -EIO;
-		goto out;
-	}
+		expected = be32_to_cpu(*(__be32 *) (buf + 2));
+		if (expected > count) {
+			size = -EIO;
+			goto out;
+		}
 
-	size += recv_data(chip, &buf[TPM_HEADER_SIZE],
-			  expected - TPM_HEADER_SIZE);
-	if (size < expected) {
-		dev_err(&chip->dev, "Unable to read remainder of result\n");
-		size = -ETIME;
-		goto out;
-	}
+		size += recv_data(chip, &buf[TPM_HEADER_SIZE],
+				  expected - TPM_HEADER_SIZE);
+		if (size < expected) {
+			dev_err(&chip->dev, "Unable to read remainder of result\n");
+			size = -ETIME;
+			goto out;
+		}
 
-	wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
-			  &chip->vendor.int_queue, false);
-	status = tpm_tis_status(chip);
-	if (status & TPM_STS_DATA_AVAIL) {	/* retry? */
-		dev_err(&chip->dev, "Error left over data\n");
-		size = -EIO;
-		goto out;
+		wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
+				  &chip->vendor.int_queue, false);
+		status = tpm_tis_status(chip);
+		if (status & TPM_STS_DATA_AVAIL) {	/* retry? */
+			dev_err(&chip->dev, "Error left over data\n");
+			size = -EIO;
+			goto out;
+		}
+
+		check_data = tpm_tis_check_data(chip, buf, size);
+		if (!check_data)
+			tpm_write_byte(chip, TPM_STS(chip->vendor.locality),
+				       TPM_STS_RESPONSE_RETRY);
 	}
 
 out:
@@ -323,15 +339,20 @@ static void disable_interrupts(struct tpm_chip *chip)
  */
 static int tpm_tis_send_main(struct tpm_chip *chip, u8 *buf, size_t len)
 {
-	int rc;
+	int rc, i;
 	u32 ordinal;
 	unsigned long dur;
+	bool data_valid = false;
 
 	tpm_tis_clear_int(chip);
 
-	rc = tpm_tis_send_data(chip, buf, len);
-	if (rc < 0)
-		return rc;
+	for (i = 0; i < TPM_RETRY && !data_valid; i++) {
+		rc = tpm_tis_send_data(chip, buf, len);
+		if (rc < 0)
+			return rc;
+
+		data_valid = tpm_tis_check_data(chip, buf, len);
+	}
 
 	/* go and do it */
 	tpm_write_byte(chip, TPM_STS(chip->vendor.locality), TPM_STS_GO);
diff --git a/include/linux/tpm.h b/include/linux/tpm.h
index f78e4fc..8e871dc 100644
--- a/include/linux/tpm.h
+++ b/include/linux/tpm.h
@@ -43,6 +43,7 @@ struct tpm_class_ops {
 	u8 (*status) (struct tpm_chip *chip);
 	bool (*update_timeouts)(struct tpm_chip *chip,
 				unsigned long *timeout_cap);
+	bool (*check_data)(struct tpm_chip *chip, u8 *buf, size_t len);
 
 	int (*read_bytes)(struct tpm_chip *chip, u32 addr, size_t len,
 			  u8 size, u8 *dst);
-- 
2.5.0


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140

  parent reply	other threads:[~2016-03-20 19:34 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-20 19:34 [PATCH 00/12] Few minnor fixes, rework of tpm_tis to support tcg spi and i2c Christophe Ricard
     [not found] ` <1458502483-16887-1-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2016-03-20 19:34   ` [PATCH 01/12] tpm/st33zp24/i2c: Drop two useless checks in ACPI probe path Christophe Ricard
2016-03-20 19:34   ` [PATCH 02/12] tpm/st33zp24/spi: " Christophe Ricard
     [not found]     ` <1458502483-16887-3-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2016-03-22  5:10       ` Jarkko Sakkinen
2016-03-20 19:34   ` [PATCH 03/12] tpm: Add include guards in tpm.h Christophe Ricard
     [not found]     ` <1458502483-16887-4-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2016-03-22  5:13       ` Jarkko Sakkinen
2016-03-20 19:34   ` [PATCH 04/12] tpm/st33zp24: Remove unneeded tpm_reg in get_burstcount Christophe Ricard
     [not found]     ` <1458502483-16887-5-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2016-03-22  6:16       ` Jarkko Sakkinen
     [not found]         ` <20160322061650.GA4058-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-22  6:21           ` Christophe Ricard
2016-03-20 19:34   ` [PATCH 05/12] tpm: Add tpm_set_vendordata and tpm_get_vendordata Christophe Ricard
     [not found]     ` <1458502483-16887-6-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2016-03-22  6:20       ` Jarkko Sakkinen
     [not found]         ` <20160322062001.GB4058-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-22 15:58           ` Jason Gunthorpe
     [not found]             ` <20160322155824.GA25600-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-03-22 16:00               ` Christophe Ricard
2016-03-23 13:11           ` Christophe Ricard
     [not found]             ` <CALD+uuxj2NHd0-LpDZpnfkfMHwY6ke0FPPqmR0FKzrC4BJmFNQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-03-23 16:48               ` Jason Gunthorpe
2016-03-24 13:27               ` Jarkko Sakkinen
     [not found]                 ` <20160324132732.GF8452-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-24 13:30                   ` Christophe Ricard
     [not found]                     ` <CALD+uuwVG_84dY4rCOjecZXxS4LZoE+Kh=CyhmVwyT2U0bAMrg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-03-24 16:18                       ` Jason Gunthorpe
     [not found]                         ` <20160324161819.GA5263-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-03-24 16:31                           ` Christophe Ricard
     [not found]                             ` <CALD+uux0-nbwJfsHFHqPrZwWt=vEy73oi_djNrrY5QeiWwCq9A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-03-24 17:10                               ` Jason Gunthorpe
     [not found]                                 ` <20160324171032.GA27978-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-03-24 23:04                                   ` Christophe Ricard
2016-03-20 19:34   ` [PATCH 06/12] devicetree: Add infineon to vendor-prefix.txt Christophe Ricard
2016-03-20 19:34   ` [PATCH 07/12] devicetree: Add Trusted Computing Group " Christophe Ricard
2016-03-20 19:34   ` [PATCH 08/12] tpm/tpm_tis: Split tpm_tis driver into a core and TCG TIS compliant phy Christophe Ricard
     [not found]     ` <1458502483-16887-9-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2016-03-21  1:32       ` Jason Gunthorpe
     [not found]         ` <20160321013243.GA9417-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-03-21 22:35           ` Christophe Ricard
     [not found]             ` <56F0774F.7040707-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-03-21 23:26               ` Jason Gunthorpe
2016-03-22  6:23       ` Jarkko Sakkinen
2016-03-20 19:34   ` [PATCH 09/12] tpm/tpm_tis: Rework interrupt management for phy compatibility Christophe Ricard
     [not found]     ` <1458502483-16887-10-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2016-03-21  1:37       ` Jason Gunthorpe
     [not found]         ` <20160321013722.GB9417-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-03-21 17:45           ` Christophe Ricard
2016-03-20 19:34   ` [PATCH 10/12] tpm/tpm_tis_spi: Add support for spi phy Christophe Ricard
2016-03-20 19:34   ` Christophe Ricard [this message]
     [not found]     ` <1458502483-16887-12-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2016-03-21  1:39       ` [PATCH 11/12] tpm: Add check_data handle to tpm_class_ops in order to check data integrity Jason Gunthorpe
     [not found]         ` <20160321013933.GC9417-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-03-21 17:44           ` Christophe Ricard
2016-03-20 19:34   ` [PATCH 12/12] tpm/tpm_tis_i2c: Add support for i2c phy Christophe Ricard
2016-03-20 21:59   ` [PATCH 00/12] Few minnor fixes, rework of tpm_tis to support tcg spi and i2c Peter Huewe
2016-03-21 11:13   ` Jarkko Sakkinen
2016-03-22  5:17   ` 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=1458502483-16887-12-git-send-email-christophe-h.ricard@st.com \
    --to=christophe.ricard-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=ashley-fm2HMyfA2y6tG0bUXCXiUA@public.gmane.org \
    --cc=benoit.houyere-qxv4g6HH51o@public.gmane.org \
    --cc=christophe-h.ricard-qxv4g6HH51o@public.gmane.org \
    --cc=jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=jean-luc.blanc-qxv4g6HH51o@public.gmane.org \
    --cc=tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /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.