linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Smith" <dpsmith@apertussolutions.com>
To: Jason Gunthorpe <jgg@ziepe.ca>,
	linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Daniel P. Smith" <dpsmith@apertussolutions.com>,
	Ross Philipson <ross.philipson@oracle.com>,
	Peter Huewe <peterhuewe@gmx.de>,
	Jarkko Sakkinen <jarkko@kernel.org>
Subject: [PATCH 3/3] tpm: make locality request return value consistent
Date: Wed, 31 Jan 2024 12:08:23 -0500	[thread overview]
Message-ID: <20240131170824.6183-4-dpsmith@apertussolutions.com> (raw)
In-Reply-To: <20240131170824.6183-1-dpsmith@apertussolutions.com>

The function tpm_tis_request_locality() is expected to return the locality
value that was requested, or a negative error code upon failure. If it is called
while locality_count of struct tis_data is non-zero, no actual locality request
will be sent. Because the ret variable is initially set to 0, the
locality_count will still get increased, and the function will return 0. For a
caller, this would indicate that locality 0 was successfully requested and not
the state changes just mentioned.

Additionally, the function __tpm_tis_request_locality() provides inconsistent
error codes. It will provide either a failed IO write or a -1 should it have
timed out waiting for locality request to succeed.

This commit changes __tpm_tis_request_locality() to return valid negative error
codes to reflect the reason it fails. It then adjusts the return value check in
tpm_tis_request_locality() to check for a non-negative return value before
incrementing locality_cout. In addition, the initial value of the ret value is
set to a negative error to ensure the check does not pass if
__tpm_tis_request_locality() is not called.

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
Signed-off-by: Ross Philipson <ross.philipson@oracle.com>
---
 drivers/char/tpm/tpm_tis_core.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 5709f87991d9..352fefc07823 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -208,7 +208,7 @@ static int __tpm_tis_request_locality(struct tpm_chip *chip, int l)
 again:
 		timeout = stop - jiffies;
 		if ((long)timeout <= 0)
-			return -1;
+			return -EBUSY;
 		rc = wait_event_interruptible_timeout(priv->int_queue,
 						      (check_locality
 						       (chip, l)),
@@ -227,18 +227,21 @@ static int __tpm_tis_request_locality(struct tpm_chip *chip, int l)
 			tpm_msleep(TPM_TIMEOUT);
 		} while (time_before(jiffies, stop));
 	}
-	return -1;
+	return -EBUSY;
 }
 
 static int tpm_tis_request_locality(struct tpm_chip *chip, int l)
 {
 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
-	int ret = 0;
+	int ret = -EBUSY;
+
+	if (l < 0 || l > TPM_MAX_LOCALITY)
+		return -EINVAL;
 
 	mutex_lock(&priv->locality_count_mutex);
 	if (priv->locality_count == 0)
 		ret = __tpm_tis_request_locality(chip, l);
-	if (!ret)
+	if (ret >= 0)
 		priv->locality_count++;
 	mutex_unlock(&priv->locality_count_mutex);
 	return ret;
-- 
2.30.2


  parent reply	other threads:[~2024-01-31 17:09 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240131170824.6183-1-dpsmith@apertussolutions.com>
2024-01-31 17:08 ` [PATCH 1/3] tpm: protect against locality counter underflow Daniel P. Smith
2024-02-01 22:21   ` Jarkko Sakkinen
2024-02-02  3:08     ` Lino Sanfilippo
2024-02-12 20:05       ` Jarkko Sakkinen
2024-02-19 17:54         ` Daniel P. Smith
2024-02-20 18:42       ` Alexander Steffen
2024-02-20 19:04         ` Jarkko Sakkinen
2024-02-20 20:54         ` Lino Sanfilippo
2024-02-20 22:23           ` Jarkko Sakkinen
2024-02-20 23:19             ` Lino Sanfilippo
2024-02-21  0:40               ` Jarkko Sakkinen
2024-02-23  1:58             ` Daniel P. Smith
2024-02-23 12:58               ` Jarkko Sakkinen
2024-02-25 11:23                 ` Daniel P. Smith
2024-02-26  9:39                   ` Jarkko Sakkinen
2024-02-20 22:26           ` Jarkko Sakkinen
2024-02-20 22:31             ` Jarkko Sakkinen
2024-02-20 23:26               ` Lino Sanfilippo
2024-02-21  0:42                 ` Jarkko Sakkinen
2024-02-21 12:37               ` James Bottomley
2024-02-21 19:43                 ` Jarkko Sakkinen
2024-02-21 19:45                   ` Jarkko Sakkinen
2024-02-22  9:06                   ` James Bottomley
2024-02-22 23:49                     ` Jarkko Sakkinen
2024-02-23  1:57                   ` Daniel P. Smith
2024-02-23 20:40                     ` Jarkko Sakkinen
2024-02-23 20:42                       ` Jarkko Sakkinen
2024-02-23  1:57               ` Daniel P. Smith
2024-02-23 20:50                 ` Jarkko Sakkinen
2024-02-20 22:57             ` ross.philipson
2024-02-20 23:10               ` Jarkko Sakkinen
2024-02-20 23:13                 ` Jarkko Sakkinen
2024-02-23  1:56           ` Daniel P. Smith
2024-02-23 20:44             ` Jarkko Sakkinen
2024-02-24  2:34             ` Lino Sanfilippo
2024-02-26  9:38               ` Jarkko Sakkinen
2024-02-23  1:55         ` Daniel P. Smith
2024-02-26 12:43           ` Alexander Steffen
2024-02-24  2:06         ` Lino Sanfilippo
2024-02-23  0:01   ` Jarkko Sakkinen
2024-01-31 17:08 ` [PATCH 2/3] tpm: ensure tpm is in known state at startup Daniel P. Smith
2024-02-01 22:33   ` Jarkko Sakkinen
2024-02-19 19:17     ` Daniel P. Smith
2024-02-19 20:17       ` Jarkko Sakkinen
2024-01-31 17:08 ` Daniel P. Smith [this message]
2024-02-01 22:49   ` [PATCH 3/3] tpm: make locality request return value consistent Jarkko Sakkinen
2024-02-19 20:29     ` Daniel P. Smith
2024-02-19 20:45       ` Jarkko Sakkinen
2024-02-20 18:57       ` Alexander Steffen

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=20240131170824.6183-4-dpsmith@apertussolutions.com \
    --to=dpsmith@apertussolutions.com \
    --cc=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    --cc=ross.philipson@oracle.com \
    /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;
as well as URLs for NNTP newsgroup(s).