stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 2/7] tpm: Return on tpm2_create_null_primary() failure
       [not found] <20240917154444.702370-1-jarkko@kernel.org>
@ 2024-09-17 15:44 ` Jarkko Sakkinen
  2024-09-17 15:44 ` [PATCH v3 3/7] tpm: Return on tpm2_create_primary() failure in tpm2_load_null() Jarkko Sakkinen
  1 sibling, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2024-09-17 15:44 UTC (permalink / raw)
  To: linux-integrity
  Cc: James.Bottomley, roberto.sassu, mapengyu, Jarkko Sakkinen, stable,
	Mimi Zohar, David Howells, Paul Moore, James Morris,
	Serge E. Hallyn, keyrings, linux-security-module, linux-kernel

tpm2_sessions_init() does not ignores the result of saving the null key.
Address this by printing either TPM or POSIX error code, and returning
-ENODEV back to the caller.

Cc: stable@vger.kernel.org # v6.11+
Fixes: d2add27cf2b8 ("tpm: Add NULL primary creation")
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
v3:
- Handle TPM and POSIX error separately and return -ENODEV always back
  to the caller.
v2:
- Refined the commit message.
---
 drivers/char/tpm/tpm2-sessions.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessions.c
index 6cc1ea81c57c..0993d18ee886 100644
--- a/drivers/char/tpm/tpm2-sessions.c
+++ b/drivers/char/tpm/tpm2-sessions.c
@@ -1273,7 +1273,13 @@ static int tpm2_create_null_primary(struct tpm_chip *chip)
 		tpm2_flush_context(chip, null_key);
 	}
 
-	return rc;
+	if (rc < 0)
+		dev_err(&chip->dev, "saving the null key failed with error %d\n", rc);
+	else if (rc > 0)
+		dev_err(&chip->dev, "saving the null key failed with TPM error 0x%04X\n", rc);
+
+	/* Map all errors to -ENODEV: */
+	return rc ? -ENODEV : rc;
 }
 
 /**
@@ -1289,7 +1295,7 @@ int tpm2_sessions_init(struct tpm_chip *chip)
 
 	rc = tpm2_create_null_primary(chip);
 	if (rc)
-		dev_err(&chip->dev, "TPM: security failed (NULL seed derivation): %d\n", rc);
+		return rc;
 
 	chip->auth = kmalloc(sizeof(*chip->auth), GFP_KERNEL);
 	if (!chip->auth)
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v3 3/7] tpm: Return on tpm2_create_primary() failure in tpm2_load_null()
       [not found] <20240917154444.702370-1-jarkko@kernel.org>
  2024-09-17 15:44 ` [PATCH v3 2/7] tpm: Return on tpm2_create_null_primary() failure Jarkko Sakkinen
@ 2024-09-17 15:44 ` Jarkko Sakkinen
  1 sibling, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2024-09-17 15:44 UTC (permalink / raw)
  To: linux-integrity
  Cc: James.Bottomley, roberto.sassu, mapengyu, Jarkko Sakkinen, stable,
	Mimi Zohar, David Howells, Paul Moore, James Morris,
	Serge E. Hallyn, keyrings, linux-security-module, linux-kernel

tpm2_load_null() ignores the return value of tpm2_create_primary().
Further, it does not heal from the situation when memcmp() returns zero.

Address this by returning on failure and saving the null key if there
was no detected interference in the bus.

Cc: stable@vger.kernel.org # v6.11+
Fixes: eb24c9788cd9 ("tpm: disable the TPM if NULL name changes")
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
v3:
- Update log messages. Previously the log message incorrectly stated
  on load failure that integrity check had been failed, even tho the
  check is done *after* the load operation.
v2:
- Refined the commit message.
- Reverted tpm2_create_primary() changes. They are not required if
  tmp_null_key is used as the parameter.
---
 drivers/char/tpm/tpm2-sessions.c | 38 +++++++++++++++++---------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessions.c
index 0993d18ee886..03c56f0eda49 100644
--- a/drivers/char/tpm/tpm2-sessions.c
+++ b/drivers/char/tpm/tpm2-sessions.c
@@ -850,32 +850,34 @@ static int tpm2_parse_start_auth_session(struct tpm2_auth *auth,
 
 static int tpm2_load_null(struct tpm_chip *chip, u32 *null_key)
 {
-	int rc;
 	unsigned int offset = 0; /* dummy offset for null seed context */
 	u8 name[SHA256_DIGEST_SIZE + 2];
+	u32 tmp_null_key;
+	int rc;
 
 	rc = tpm2_load_context(chip, chip->null_key_context, &offset,
-			       null_key);
-	if (rc != -EINVAL)
+			       &tmp_null_key);
+	if (rc != -EINVAL) {
+		if (!rc)
+			*null_key = tmp_null_key;
 		return rc;
+	}
+	dev_info(&chip->dev, "the null key has been reset\n");
 
-	/* an integrity failure may mean the TPM has been reset */
-	dev_err(&chip->dev, "NULL key integrity failure!\n");
-	/* check the null name against what we know */
-	tpm2_create_primary(chip, TPM2_RH_NULL, NULL, name);
-	if (memcmp(name, chip->null_key_name, sizeof(name)) == 0)
-		/* name unchanged, assume transient integrity failure */
+	rc = tpm2_create_primary(chip, TPM2_RH_NULL, &tmp_null_key, name);
+	if (rc)
 		return rc;
-	/*
-	 * Fatal TPM failure: the NULL seed has actually changed, so
-	 * the TPM must have been illegally reset.  All in-kernel TPM
-	 * operations will fail because the NULL primary can't be
-	 * loaded to salt the sessions, but disable the TPM anyway so
-	 * userspace programmes can't be compromised by it.
-	 */
-	dev_err(&chip->dev, "NULL name has changed, disabling TPM due to interference\n");
-	chip->flags |= TPM_CHIP_FLAG_DISABLE;
 
+	/* Return the null key if the name has not been changed: */
+	if (memcmp(name, chip->null_key_name, sizeof(name)) == 0) {
+		*null_key = tmp_null_key;
+		return 0;
+	}
+
+	/* Deduce from the name change TPM interference: */
+	dev_err(&chip->dev, "the null key integrity check failedh\n");
+	tpm2_flush_context(chip, tmp_null_key);
+	chip->flags |= TPM_CHIP_FLAG_DISABLE;
 	return rc;
 }
 
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-09-17 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20240917154444.702370-1-jarkko@kernel.org>
2024-09-17 15:44 ` [PATCH v3 2/7] tpm: Return on tpm2_create_null_primary() failure Jarkko Sakkinen
2024-09-17 15:44 ` [PATCH v3 3/7] tpm: Return on tpm2_create_primary() failure in tpm2_load_null() Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).