]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
tpm: remove TPM_TRANSMIT_UNLOCKED flag
authorJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Sun, 4 Nov 2018 18:01:42 +0000 (20:01 +0200)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Wed, 13 Feb 2019 07:48:28 +0000 (09:48 +0200)
Added locking as part of tpm_try_get_ops() and tpm_put_ops() as they are
anyway used in most of the call sites except in tpmrm_release() where we
take the locks manually.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Tested-by: Alexander Steffen <Alexander.Steffen@infineon.com>
drivers/char/tpm/tpm-chip.c
drivers/char/tpm/tpm-dev-common.c
drivers/char/tpm/tpm-interface.c
drivers/char/tpm/tpm.h
drivers/char/tpm/tpm2-cmd.c
drivers/char/tpm/tpm2-space.c

index 32db84683c40160c48c0962ecc63703f62899fd4..157505b0f7559619b49ee5709ef7db6302490a35 100644 (file)
@@ -58,6 +58,7 @@ int tpm_try_get_ops(struct tpm_chip *chip)
        if (!chip->ops)
                goto out_lock;
 
+       mutex_lock(&chip->tpm_mutex);
        return 0;
 out_lock:
        up_read(&chip->ops_sem);
@@ -75,6 +76,7 @@ EXPORT_SYMBOL_GPL(tpm_try_get_ops);
  */
 void tpm_put_ops(struct tpm_chip *chip)
 {
+       mutex_unlock(&chip->tpm_mutex);
        up_read(&chip->ops_sem);
        put_device(&chip->dev);
 }
index 95fe652b34ff5eabaa9188f6cb838940941ada63..435c09ec9056e127e7508f9e27218cfc427c7ab7 100644 (file)
@@ -33,7 +33,6 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
        struct tpm_header *header = (void *)buf;
        ssize_t ret, len;
 
-       mutex_lock(&chip->tpm_mutex);
        ret = tpm2_prepare_space(chip, space, buf, bufsiz);
        /* If the command is not implemented by the TPM, synthesize a
         * response with a TPM2_RC_COMMAND_CODE return for user-space.
@@ -46,18 +45,16 @@ static ssize_t tpm_dev_transmit(struct tpm_chip *chip, struct tpm_space *space,
                ret = sizeof(*header);
        }
        if (ret)
-               goto out_lock;
+               goto out_rc;
 
-       len = tpm_transmit(chip, buf, bufsiz, TPM_TRANSMIT_UNLOCKED);
+       len = tpm_transmit(chip, buf, bufsiz, 0);
        if (len < 0)
                ret = len;
 
        if (!ret)
                ret = tpm2_commit_space(chip, space, buf, &len);
 
-out_lock:
-       mutex_unlock(&chip->tpm_mutex);
-
+out_rc:
        return ret ? ret : len;
 }
 
index 5acbef8cf2ce1b2ca67d35ab24d8c95f94ecaa09..54a15f59e1756b86fbc734f2f154ab789b0bc9db 100644 (file)
@@ -236,10 +236,6 @@ ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
        memcpy(save, buf, save_size);
 
        for (;;) {
-               if (!(flags & TPM_TRANSMIT_UNLOCKED) &&
-                   !(flags & TPM_TRANSMIT_NESTED))
-                       mutex_lock(&chip->tpm_mutex);
-
                if (chip->ops->clk_enable != NULL)
                        chip->ops->clk_enable(chip, true);
 
@@ -266,10 +262,6 @@ out_locality:
                if (chip->ops->clk_enable != NULL)
                        chip->ops->clk_enable(chip, false);
 
-               if (!(flags & TPM_TRANSMIT_UNLOCKED) &&
-                   !(flags & TPM_TRANSMIT_NESTED))
-                       mutex_unlock(&chip->tpm_mutex);
-
                if (ret < 0)
                        break;
                rc = be32_to_cpu(header->return_code);
index 644f1a5c4fdd37cbc217121879d2914645cb77fa..18ef432a3fdee6e3d749ec8f6c1a840e20a089c4 100644 (file)
@@ -488,14 +488,10 @@ extern struct idr dev_nums_idr;
 /**
  * enum tpm_transmit_flags - flags for tpm_transmit()
  *
- * @TPM_TRANSMIT_UNLOCKED:     do not lock the chip
- * @TPM_TRANSMIT_NESTED:       discard setup steps (power management,
- *                             locality) including locking (i.e. implicit
- *                             UNLOCKED)
+ * %TPM_TRANSMIT_NESTED:       discard setup steps (power management, locality)
  */
 enum tpm_transmit_flags {
-       TPM_TRANSMIT_UNLOCKED   = BIT(0),
-       TPM_TRANSMIT_NESTED      = BIT(1),
+       TPM_TRANSMIT_NESTED      = BIT(0),
 };
 
 ssize_t tpm_transmit(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
index f2b0e5c52a577e4de119ba4a6b4c335cc4d10038..d6abc964ef66164f0341ae54f634e86b6526b6f3 100644 (file)
@@ -652,17 +652,12 @@ int tpm2_unseal_trusted(struct tpm_chip *chip,
        u32 blob_handle;
        int rc;
 
-       mutex_lock(&chip->tpm_mutex);
-       rc = tpm2_load_cmd(chip, payload, options, &blob_handle,
-                          TPM_TRANSMIT_UNLOCKED);
+       rc = tpm2_load_cmd(chip, payload, options, &blob_handle, 0);
        if (rc)
-               goto out;
+               return rc;
 
-       rc = tpm2_unseal_cmd(chip, payload, options, blob_handle,
-                            TPM_TRANSMIT_UNLOCKED);
-       tpm2_flush_context_cmd(chip, blob_handle, TPM_TRANSMIT_UNLOCKED);
-out:
-       mutex_unlock(&chip->tpm_mutex);
+       rc = tpm2_unseal_cmd(chip, payload, options, blob_handle, 0);
+       tpm2_flush_context_cmd(chip, blob_handle, 0);
        return rc;
 }
 
index 08bbd558dbc122b2f454f377e87cac736e8cd14d..8a8754a0f9642035f9d807ce25cc23fb41b6042c 100644 (file)
@@ -38,8 +38,7 @@ static void tpm2_flush_sessions(struct tpm_chip *chip, struct tpm_space *space)
 
        for (i = 0; i < ARRAY_SIZE(space->session_tbl); i++) {
                if (space->session_tbl[i])
-                       tpm2_flush_context_cmd(chip, space->session_tbl[i],
-                                              TPM_TRANSMIT_UNLOCKED);
+                       tpm2_flush_context_cmd(chip, space->session_tbl[i], 0);
        }
 }
 
@@ -83,7 +82,7 @@ static int tpm2_load_context(struct tpm_chip *chip, u8 *buf,
        body_size = sizeof(*ctx) + be16_to_cpu(ctx->blob_size);
        tpm_buf_append(&tbuf, &buf[*offset], body_size);
 
-       rc = tpm_transmit_cmd(chip, &tbuf, 4, TPM_TRANSMIT_UNLOCKED, NULL);
+       rc = tpm_transmit_cmd(chip, &tbuf, 4, 0, NULL);
        if (rc < 0) {
                dev_warn(&chip->dev, "%s: failed with a system error %d\n",
                         __func__, rc);
@@ -131,7 +130,7 @@ static int tpm2_save_context(struct tpm_chip *chip, u32 handle, u8 *buf,
 
        tpm_buf_append_u32(&tbuf, handle);
 
-       rc = tpm_transmit_cmd(chip, &tbuf, 0, TPM_TRANSMIT_UNLOCKED, NULL);
+       rc = tpm_transmit_cmd(chip, &tbuf, 0, 0, NULL);
        if (rc < 0) {
                dev_warn(&chip->dev, "%s: failed with a system error %d\n",
                         __func__, rc);
@@ -167,8 +166,7 @@ void tpm2_flush_space(struct tpm_chip *chip)
 
        for (i = 0; i < ARRAY_SIZE(space->context_tbl); i++)
                if (space->context_tbl[i] && ~space->context_tbl[i])
-                       tpm2_flush_context_cmd(chip, space->context_tbl[i],
-                                              TPM_TRANSMIT_UNLOCKED);
+                       tpm2_flush_context_cmd(chip, space->context_tbl[i], 0);
 
        tpm2_flush_sessions(chip, space);
 }
@@ -416,7 +414,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, u32 cc, u8 *rsp,
 
        return 0;
 out_no_slots:
-       tpm2_flush_context_cmd(chip, phandle, TPM_TRANSMIT_UNLOCKED);
+       tpm2_flush_context_cmd(chip, phandle, 0);
        dev_warn(&chip->dev, "%s: out of slots for 0x%08X\n", __func__,
                 phandle);
        return -ENOMEM;
@@ -503,8 +501,7 @@ static int tpm2_save_space(struct tpm_chip *chip)
                } else if (rc)
                        return rc;
 
-               tpm2_flush_context_cmd(chip, space->context_tbl[i],
-                                      TPM_TRANSMIT_UNLOCKED);
+               tpm2_flush_context_cmd(chip, space->context_tbl[i], 0);
                space->context_tbl[i] = ~0;
        }