All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Steffen <Alexander.Steffen@infineon.com>
To: <jarkko.sakkinen@linux.intel.com>, <linux-integrity@vger.kernel.org>
Cc: Alexander Steffen <Alexander.Steffen@infineon.com>
Subject: [RFC][PATCH 3/3] tpm-chip: Export TPM device to user space even when startup failed
Date: Thu, 14 Dec 2017 17:06:14 +0100	[thread overview]
Message-ID: <20171214160614.11808-4-Alexander.Steffen@infineon.com> (raw)
In-Reply-To: <20171214160614.11808-1-Alexander.Steffen@infineon.com>

When one of the commands during the auto_startup sequences does not return
TPM_RC_SUCCESS, tpm_chip_register misleadingly returns ENODEV, even though
a TPM device is definitely present.

An error response during those sequences is indeed unexpected, so to
prevent subsequent errors, the kernel should not make use of the TPM
device. But user space applications still might be able to communicate with
the TPM, so they can be used to further diagnose and/or fix the problem. To
allow this, with this patch the device is still exported to user space,
even if a TPM error code has been received, but the kernel itself will not
be allowed to use the device for anything.

This is not a hypothetical scenario, but there are devices in the wild that
show this behavior. With this fix, those devices can be recovered from
their failed state.

Signed-off-by: Alexander Steffen <Alexander.Steffen@infineon.com>
---
 drivers/char/tpm/tpm-chip.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 9cbe1ef..c4636e1 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -384,7 +384,7 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip)
  *
  * Creates a character device for the TPM chip and adds sysfs attributes for
  * the device. As the last step this function adds the chip to the list of TPM
- * chips available for in-kernel use.
+ * chips available for in-kernel use, if the TPM startup was successful.
  *
  * This function should be only called after the chip initialization is
  * complete.
@@ -392,6 +392,7 @@ static int tpm_add_legacy_sysfs(struct tpm_chip *chip)
 int tpm_chip_register(struct tpm_chip *chip)
 {
 	int rc;
+	bool startup_successful = true;
 
 	if (chip->ops->flags & TPM_OPS_AUTO_STARTUP) {
 		if (chip->flags & TPM_CHIP_FLAG_TPM2)
@@ -401,7 +402,7 @@ int tpm_chip_register(struct tpm_chip *chip)
 		if (rc < 0)
 			return rc;
 		else if (rc > 0)
-			return -ENODEV;
+			startup_successful = false;
 	}
 
 	tpm_sysfs_add_device(chip);
@@ -424,10 +425,12 @@ int tpm_chip_register(struct tpm_chip *chip)
 		return rc;
 	}
 
-	/* Make the chip available. */
-	mutex_lock(&idr_lock);
-	idr_replace(&dev_nums_idr, chip, chip->dev_num);
-	mutex_unlock(&idr_lock);
+	if (startup_successful) {
+		/* Make the chip available. */
+		mutex_lock(&idr_lock);
+		idr_replace(&dev_nums_idr, chip, chip->dev_num);
+		mutex_unlock(&idr_lock);
+	}
 
 	return 0;
 }
-- 
2.7.4

  parent reply	other threads:[~2017-12-14 16:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-14 16:06 [RFC][PATCH 0/3] Export broken TPMs to user space Alexander Steffen
2017-12-14 16:06 ` [RFC][PATCH 1/3] tpm-chip: Move idr_replace calls to appropriate places Alexander Steffen
2017-12-14 19:27   ` Jason Gunthorpe
2017-12-15  9:26     ` Alexander.Steffen
2018-01-18 18:38   ` Jarkko Sakkinen
2018-01-18 18:41   ` Jarkko Sakkinen
2017-12-14 16:06 ` [RFC][PATCH 2/3] tpm-chip: Return TPM error codes from auto_startup functions Alexander Steffen
2017-12-14 16:06 ` Alexander Steffen [this message]
2017-12-14 19:28   ` [RFC][PATCH 3/3] tpm-chip: Export TPM device to user space even when startup failed Jason Gunthorpe
2018-01-18 18:45   ` Jarkko Sakkinen
2018-01-18 19:24     ` Jason Gunthorpe
2018-01-23 12:39       ` Jarkko Sakkinen
2017-12-15 14:47 ` [RFC][PATCH 0/3] Export broken TPMs to user space 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=20171214160614.11808-4-Alexander.Steffen@infineon.com \
    --to=alexander.steffen@infineon.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=linux-integrity@vger.kernel.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.