All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: tpmdd-devel@lists.sourceforge.net
Cc: linux-security-module@vger.kernel.org,
	James.Bottomley@HansenPartnership.com, dhowells@redhat.com,
	Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
	Peter Huewe <peterhuewe@gmx.de>,
	Marcel Selhorst <tpmdd@selhorst.net>,
	Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v3 1/7] tpm: move length validation to tpm_transmit()
Date: Fri,  3 Mar 2017 17:19:02 +0200	[thread overview]
Message-ID: <20170303151912.14752-2-jarkko.sakkinen@linux.intel.com> (raw)
In-Reply-To: <20170303151912.14752-1-jarkko.sakkinen@linux.intel.com>

Check that the length matches the length reported by the response
header already in tpm_transmit() to improve validation.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Reviewed-by: James Bottomley <James.Bottomley@HansenPartnership.com>
---
 drivers/char/tpm/tpm-interface.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index bd2128e..708d356 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -343,6 +343,7 @@ EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
 ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
 		     unsigned int flags)
 {
+	const struct tpm_output_header *header = (void *)buf;
 	ssize_t rc;
 	u32 count, ordinal;
 	unsigned long stop;
@@ -406,9 +407,18 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
 
 out_recv:
 	rc = chip->ops->recv(chip, (u8 *) buf, bufsiz);
-	if (rc < 0)
+	if (rc < 0) {
 		dev_err(&chip->dev,
 			"tpm_transmit: tpm_recv: error %zd\n", rc);
+		goto out;
+	} else if (rc < TPM_HEADER_SIZE) {
+		rc = -EFAULT;
+		goto out;
+	}
+
+	if (rc != be32_to_cpu(header->length))
+		goto out;
+
 out:
 	if (chip->dev.parent)
 		pm_runtime_put_sync(chip->dev.parent);
@@ -438,19 +448,13 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *buf,
 			 size_t bufsiz, size_t min_rsp_body_length,
 			 unsigned int flags, const char *desc)
 {
-	const struct tpm_output_header *header;
+	const struct tpm_output_header *header = buf;
 	int err;
 	ssize_t len;
 
 	len = tpm_transmit(chip, (const u8 *)buf, bufsiz, flags);
 	if (len <  0)
 		return len;
-	else if (len < TPM_HEADER_SIZE)
-		return -EFAULT;
-
-	header = buf;
-	if (len != be32_to_cpu(header->length))
-		return -EFAULT;
 
 	err = be32_to_cpu(header->return_code);
 	if (err != 0 && desc)
-- 
2.9.3

WARNING: multiple messages have this Message-ID (diff)
From: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
To: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	open list <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	James.Bottomley-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org,
	linux-security-module-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v3 1/7] tpm: move length validation to tpm_transmit()
Date: Fri,  3 Mar 2017 17:19:02 +0200	[thread overview]
Message-ID: <20170303151912.14752-2-jarkko.sakkinen@linux.intel.com> (raw)
In-Reply-To: <20170303151912.14752-1-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>

Check that the length matches the length reported by the response
header already in tpm_transmit() to improve validation.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Tested-by: James Bottomley <James.Bottomley-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
Reviewed-by: James Bottomley <James.Bottomley-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
---
 drivers/char/tpm/tpm-interface.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index bd2128e..708d356 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -343,6 +343,7 @@ EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
 ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
 		     unsigned int flags)
 {
+	const struct tpm_output_header *header = (void *)buf;
 	ssize_t rc;
 	u32 count, ordinal;
 	unsigned long stop;
@@ -406,9 +407,18 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const u8 *buf, size_t bufsiz,
 
 out_recv:
 	rc = chip->ops->recv(chip, (u8 *) buf, bufsiz);
-	if (rc < 0)
+	if (rc < 0) {
 		dev_err(&chip->dev,
 			"tpm_transmit: tpm_recv: error %zd\n", rc);
+		goto out;
+	} else if (rc < TPM_HEADER_SIZE) {
+		rc = -EFAULT;
+		goto out;
+	}
+
+	if (rc != be32_to_cpu(header->length))
+		goto out;
+
 out:
 	if (chip->dev.parent)
 		pm_runtime_put_sync(chip->dev.parent);
@@ -438,19 +448,13 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *buf,
 			 size_t bufsiz, size_t min_rsp_body_length,
 			 unsigned int flags, const char *desc)
 {
-	const struct tpm_output_header *header;
+	const struct tpm_output_header *header = buf;
 	int err;
 	ssize_t len;
 
 	len = tpm_transmit(chip, (const u8 *)buf, bufsiz, flags);
 	if (len <  0)
 		return len;
-	else if (len < TPM_HEADER_SIZE)
-		return -EFAULT;
-
-	header = buf;
-	if (len != be32_to_cpu(header->length))
-		return -EFAULT;
 
 	err = be32_to_cpu(header->return_code);
 	if (err != 0 && desc)
-- 
2.9.3


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot

  reply	other threads:[~2017-03-03 15:19 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-03 15:19 [PATCH v3 0/7] in-kernel resource manager Jarkko Sakkinen
2017-03-03 15:19 ` Jarkko Sakkinen
2017-03-03 15:19 ` Jarkko Sakkinen [this message]
2017-03-03 15:19   ` [PATCH v3 1/7] tpm: move length validation to tpm_transmit() Jarkko Sakkinen
2017-03-03 15:19 ` [PATCH v3 2/7] tpm: validate TPM 2.0 commands Jarkko Sakkinen
2017-03-03 15:19   ` Jarkko Sakkinen
2017-03-17 15:40   ` [tpmdd-devel] " Alexander.Steffen
2017-03-17 15:40     ` Alexander.Steffen-d0qZbvYSIPpWk0Htik3J/w
2017-03-17 15:40     ` [tpmdd-devel] " Alexander.Steffen at infineon.com
2017-03-17 16:16     ` Jason Gunthorpe
2017-03-17 16:16       ` Jason Gunthorpe
2017-03-17 16:35       ` Peter.Huewe
2017-03-17 16:35         ` Peter.Huewe-d0qZbvYSIPpWk0Htik3J/w
2017-03-17 16:35         ` [tpmdd-devel] " Peter.Huewe at infineon.com
2017-03-20  9:54         ` Alexander.Steffen
2017-03-20  9:54           ` Alexander.Steffen
2017-03-20  9:54           ` Alexander.Steffen at infineon.com
2017-03-20 17:23           ` Jason Gunthorpe
2017-03-20 17:23             ` Jason Gunthorpe
2017-03-20 17:23             ` [tpmdd-devel] " Jason Gunthorpe
2017-03-20 19:42           ` Ken Goldman
2017-03-20 19:42             ` Ken Goldman
2017-03-20 19:42             ` [tpmdd-devel] " Ken Goldman
2017-03-21 15:44             ` Alexander.Steffen
2017-03-21 15:44               ` Alexander.Steffen-d0qZbvYSIPpWk0Htik3J/w
2017-03-21 15:44               ` [tpmdd-devel] " Alexander.Steffen at infineon.com
2017-03-17 20:42     ` Jarkko Sakkinen
2017-03-17 20:42       ` Jarkko Sakkinen
2017-03-17 20:42       ` [tpmdd-devel] " Jarkko Sakkinen
2017-03-20  9:56       ` Alexander.Steffen
2017-03-20  9:56         ` Alexander.Steffen-d0qZbvYSIPpWk0Htik3J/w
2017-03-20  9:56         ` [tpmdd-devel] " Alexander.Steffen at infineon.com
2017-03-27  5:25         ` Jarkko Sakkinen
2017-03-27  5:25           ` Jarkko Sakkinen
2017-03-27  5:25           ` [tpmdd-devel] " Jarkko Sakkinen
2017-03-03 15:19 ` [PATCH v3 3/7] tpm: export tpm2_flush_context_cmd Jarkko Sakkinen
2017-03-03 15:19   ` Jarkko Sakkinen
2017-03-03 15:19 ` [PATCH v3 4/7] tpm: infrastructure for TPM spaces Jarkko Sakkinen
2017-03-03 15:19   ` Jarkko Sakkinen
2017-03-17 15:41   ` [tpmdd-devel] " Alexander.Steffen
2017-03-17 15:41     ` Alexander.Steffen-d0qZbvYSIPpWk0Htik3J/w
2017-03-17 15:41     ` [tpmdd-devel] " Alexander.Steffen at infineon.com
2017-03-17 20:44     ` Jarkko Sakkinen
2017-03-17 20:44       ` Jarkko Sakkinen
2017-03-17 20:44       ` [tpmdd-devel] " Jarkko Sakkinen
2017-03-03 15:19 ` [PATCH v3 5/7] tpm: split out tpm-dev.c into tpm-dev.c and tpm-common-dev.c Jarkko Sakkinen
2017-03-03 15:19   ` Jarkko Sakkinen
2017-03-03 15:19 ` [PATCH v3 6/7] tpm: expose spaces via a device link /dev/tpmrm<n> Jarkko Sakkinen
2017-03-03 15:19   ` Jarkko Sakkinen
2017-03-03 15:19 ` [PATCH v3 7/7] tpm2: add session handle context saving and restoring to the space code Jarkko Sakkinen
2017-03-03 15:19   ` Jarkko Sakkinen
2017-03-06 21:07 ` [PATCH v3 0/7] in-kernel resource manager Jarkko Sakkinen
2017-03-06 21:07   ` Jarkko Sakkinen
2017-03-11  8:55 ` Jarkko Sakkinen
2017-03-11  8:55   ` 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=20170303151912.14752-2-jarkko.sakkinen@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=dhowells@redhat.com \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --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 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.