tpm: cmd_ready command can be issued only after granting locality
Subsystems (3)
PATCH v7 1/1 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.
Two wrapper functions are added (request_locality relinquish_locality) to simplify the error handling.
The issue is only visible on devices that support multiple localities.
---
V2: 1. 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 return value.
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.
V6: 1. Add locality wrappers.
V7: 1. Add tpm_ prefix to locality wrappers.
drivers/char/tpm/tpm-interface.c | 54 +++++++++++++++----- drivers/char/tpm/tpm_crb.c | 108 +++++++++++++++++++++++++++------------ drivers/char/tpm/tpm_tis_core.c | 4 +- include/linux/tpm.h | 2 +- 4 files changed, 120 insertions(+), 48 deletions(-)
drivers/char/tpm/tpm-interface.c +41 -13
@@ -369,6 +369,36 @@ static int tpm_validate_command(struct tpm_chip *chip,return -EINVAL ; } +static int tpm_request_locality (struct tpm_chip *chip) +{ +int rc; + +if (!chip->ops->request_locality) +return 0 ; + + rc = chip->ops->request_locality (chip,0 ); +if (rc <0 ) +return rc; + + chip->locality = rc; + +return 0 ; +} + +static void tpm_relinquish_locality (struct tpm_chip *chip) +{ +int rc; + +if (!chip->ops->relinquish_locality) +return ; + + rc = chip->ops->relinquish_locality (chip, chip->locality); +if (rc) +dev_err (&chip->dev,"%s: : error %d\n" , __func__, rc); + + chip->locality =-1 ; +} +/** * tmp_transmit - Internal kernel interface to transmit TPM commands. *
@@ -422,8 +452,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);
@@ -431,14 +459,15 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space,/* Store the decision as chip->locality will be changed. */ need_locality = chip->locality ==-1 ; -if (!(flags &TPM_TRANSMIT_RAW ) && - need_locality && chip->ops->request_locality) { - rc = chip->ops->request_locality (chip,0 ); +if (!(flags &TPM_TRANSMIT_RAW ) && need_locality) { + rc =tpm_request_locality (chip);if (rc <0 ) goto out_no_locality; - 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 +528,16 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space, rc =tpm2_commit_space (chip, space, ordinal, buf, &len); out: -if (need_locality && chip->ops->relinquish_locality) { - chip->ops->relinquish_locality (chip, chip->locality); - chip->locality =-1 ; - } +if (chip->dev.parent) +pm_runtime_put_sync (chip->dev.parent); + +if (need_locality) +tpm_relinquish_locality (chip); + 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
Quoted 9 lines · Tomas Winkler
The correct sequence is to first request locality and only after that perform
cmd_readyhandshake, otherwise the hardware will drop the subsequent message as from the device point of view thecmd_readyhandshake wasn't performed. Symmetrically locality has to be relinquished only after going idle handshake has completed, this requires thatgo_idlehas 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.
Quoted 7 lines
Two wrapper functions are added (
request_localityrelinquish_locality) to simplify the error handling.The issue is only visible on devices that support multiple localities.
Fixes 877c57d0d0ca ("tpm_crb: request and relinquish locality 0")Signed-off-by Tomas Winkler <[email protected]>
/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 13 lines · Jarkko Sakkinen
Quoted 12 lines · Tomas Winkler
The correct sequence is to first request locality and only after that perform
cmd_readyhandshake, otherwise the hardware will drop the subsequent message as from the device point of view thecmd_readyhandshake wasn't performed. Symmetrically locality has to be relinquished only after going idle handshake has completed, this requires thatgo_idlehas 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.Two wrapper functions are added (
request_localityrelinquish_locality) to simplify the error handling.
Quoted 7 lines
Quoted 4 lines
The issue is only visible on devices that support multiple localities.
Fixes 877c57d0d0ca ("tpm_crb: request and relinquish locality 0")Signed-off-by Tomas Winkler <[email protected]>Tested-by Jarkko Sakkinen <[email protected]>Reviewed-by Jarkko Sakkinen <[email protected]>
This commit has been applied.
/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 18 lines · Jarkko Sakkinen
Quoted 15 lines · Tomas Winkler
Quoted 14 lines
The correct sequence is to first request locality and only after that perform
cmd_readyhandshake, otherwise the hardware will drop the subsequent message as from the device point of view thecmd_readyhandshake wasn't performed. Symmetrically locality has to be relinquished only after going idle handshake has completed, this requires thatgo_idlehas 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.Two wrapper functions are added (
request_localityrelinquish_locality) to simplify the error handling.The issue is only visible on devices that support multiple localities.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Fixes 877c57d0d0ca ("tpm_crb: request and relinquish locality 0")Signed-off-by Tomas Winkler <[email protected]>Tested-by Jarkko Sakkinen <[email protected]>Reviewed-by Jarkko Sakkinen <[email protected]>This commit has been applied.
Appreciated.
Tomas
--
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