tpm: cmd_ready command can be issued only after granting locality
Subsystems (3)
PATCH v5 1/2 tpm: cmd_ready command can be issued only after granting locality
The correct sequence is to first request locality and only after that perform cmd_ready handshake, otherwise the hardware will drop the subsequent message as from the device point of view the cmd_ready handshake wasn't performed. Symmetrically locality has to be relinquished only after going idle handshake has completed, this requires that go_idle has to poll for the completion and as well locality relinquish has to poll for completion so it is not overridden in back to back commands flow.
The issue is only visible on devices that support multiple localities.
---
V2: poll for locality relinquish completion
V3: 1. Print error message upon locality relinquish failure
2. Don't override rc code on error path with locality relinquish
V4: 1. Don't capture locality relinquish error code in rc, just print
the error message.
V5: 1. Fix a coding style issue
2. Add fixes reference
Note: This should got to the stable but doesn't apply cleanly, a rebased patch will be send after merging.
drivers/char/tpm/tpm-interface.c | 20 +++++--- drivers/char/tpm/tpm_crb.c | 108 +++++++++++++++++++++++++++------------ drivers/char/tpm/tpm_tis_core.c | 4 +- include/linux/tpm.h | 2 +- 4 files changed, 93 insertions(+), 41 deletions(-)
drivers/char/tpm/tpm-interface.c +14 -6
@@ -422,8 +422,6 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,if (!(flags &TPM_TRANSMIT_UNLOCKED ))mutex_lock (&chip->tpm_mutex); -if (chip->dev.parent) -pm_runtime_get_sync (chip->dev.parent);if (chip->ops->clk_enable !=NULL ) chip->ops->clk_enable (chip, true);
@@ -439,6 +437,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space, chip->locality = rc; } +if (chip->dev.parent) +pm_runtime_get_sync (chip->dev.parent); + rc =tpm2_prepare_space (chip, space, ordinal, buf);if (rc) goto out;
@@ -499,17 +500,24 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space, rc =tpm2_commit_space (chip, space, ordinal, buf, &len); out: +if (chip->dev.parent) +pm_runtime_put_sync (chip->dev.parent); +if (need_locality && chip->ops->relinquish_locality) { - chip->ops->relinquish_locality (chip, chip->locality); +/* this coud be on error path, don't override error code */ +int l_rc = chip->ops->relinquish_locality (chip, chip->locality); + +if (l_rc) +dev_err (&chip->dev,"%s: relinquish_locality: error %d\n" , + __func__, l_rc); + chip->locality =-1 ; } + out_no_locality:if (chip->ops->clk_enable !=NULL ) chip->ops->clk_enable (chip, false); -if (chip->dev.parent) -pm_runtime_put_sync (chip->dev.parent); -if (!(flags &TPM_TRANSMIT_UNLOCKED ))mutex_unlock (&chip->tpm_mutex);return rc ? rc : len;
drivers/char/tpm/tpm_crb.c +75 -33
192 lines not on this page · raw message
drivers/char/tpm/tpm_tis_core.c +3 -1
@@ -143,11 +143,13 @@ static bool check_locality(struct tpm_chip *chip, int l)return false; } -static void release_locality (struct tpm_chip *chip,int l) +static int release_locality (struct tpm_chip *chip,int l) {struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev);tpm_tis_write8 (priv,TPM_ACCESS (l),TPM_ACCESS_ACTIVE_LOCALITY ); + +return 0 ; }static int request_locality (struct tpm_chip *chip,int l)
include/linux/tpm.h +1 -1
@@ -44,7 +44,7 @@ struct tpm_class_ops {bool (*update_timeouts)(struct tpm_chip *chip,unsigned long *timeout_cap);int (*request_locality)(struct tpm_chip *chip,int loc); -void (*relinquish_locality)(struct tpm_chip *chip,int loc); +int (*relinquish_locality)(struct tpm_chip *chip,int loc);void (*clk_enable)(struct tpm_chip *chip,bool value); };
Signature · 6 lines
2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
drivers/char/tpm/tpm-interface.c ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space, · line 515
Quoted 13 lines · Tomas Winkler
drivers/char/tpm/tpm-interface.c +2
-1if (need_locality && chip->ops->relinquish_locality) { - chip->ops->relinquish_locality (chip, chip->locality); +/* this coud be on error path, don't override error code */ + int l_rc = chip->ops->relinquish_locality(chip, chip-Quoted 1 line
locality);
drivers/char/tpm/tpm-interface.c +3
-0+ +if (l_rc) + dev_err(&chip->dev, "%s: relinquish_locality: error%d\n",
drivers/char/tpm/tpm-interface.c +2
-0+ __func__, l_rc); + chip->locality =-1 ; }
The 'l_rc' declaration causes NAK as I've stated before.
Why don't you just make a helper function:
static void tpm_relinquish_locality(struct tpm_chip *chip)
{
int rc;
if (!chip->ops->relinquish_locality)
return 0;
rc = chip->ops->relinquish_locality(chip);
if (rc)
dev_err(&chip->dev, "%s: error %d\n", __func__, rc);
chip->locality = -1;
}Then the original code would be simply:
if (need_locality)
tpm_relinquish_locality(chip);
/Jarkko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Tomas Winkler
Quoted 5 lines
drivers/char/tpm/tpm-interface.c +2
-1if (need_locality && chip->ops->relinquish_locality) { - chip->ops->relinquish_locality (chip, chip->locality); +/* this coud be on error path, don't override error code */ + int l_rc = chip->ops->relinquish_locality(chip, chip-Quoted 1 line
locality);
Quoted 10 lines
drivers/char/tpm/tpm-interface.c ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space, · line 515
Quoted 8 lines
drivers/char/tpm/tpm-interface.c +3
-0+ +if (l_rc) + dev_err(&chip->dev, "%s: relinquish_locality: error%d\n",
drivers/char/tpm/tpm-interface.c +2
-0+ __func__, l_rc); + chip->locality =-1 ; }The '
l_rc' declaration causes NAK as I've stated before.
I will provide a sixth version that let us both down the tree
Quoted 16 lines
Why don't you just make a helper function:
static void tpm_relinquish_locality(struct tpm_chip *chip) { int rc; if (!chip->ops->relinquish_locality) return 0; rc = chip->ops->relinquish_locality(chip); if (rc) dev_err(&chip->dev, "%s: error %d\n", __func__, rc); chip->locality = -1; }
Quoted 6 lines
Then the original code would be simply:
if (
need_locality)tpm_relinquish_locality(chip);/Jarkko
????{.n?+???????+%?????????w??{.n?+????{??????????v?^?)????w*jg??????????j????G?????????j:+v???w?j?m????????w?????f???h?????????