diff mbox series

[4/9] security: keys: trusted: Store the handle of a loaded key

Message ID 20210220013255.1083202-5-matthewgarrett@google.com (mailing list archive)
State New, archived
Headers show
Series Enable hibernation when Lockdown is enabled | expand

Commit Message

Matthew Garrett Feb. 20, 2021, 1:32 a.m. UTC
Certain in-kernel operations using a trusted key (such as creation
certification) require knowledge of the handle it's loaded at. Keep
a copy of that in the payload.

Signed-off-by: Matthew Garrett <mjg59@google.com>
---
 include/keys/trusted-type.h               | 1 +
 security/keys/trusted-keys/trusted_tpm2.c | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Jarkko Sakkinen Feb. 20, 2021, 3:06 a.m. UTC | #1
On Sat, Feb 20, 2021 at 01:32:50AM +0000, Matthew Garrett wrote:
> Certain in-kernel operations using a trusted key (such as creation
> certification) require knowledge of the handle it's loaded at. Keep
> a copy of that in the payload.
> 
> Signed-off-by: Matthew Garrett <mjg59@google.com>

This looks good to me as well *as a code change*.

/Jarkko

> ---
>  include/keys/trusted-type.h               | 1 +
>  security/keys/trusted-keys/trusted_tpm2.c | 6 ++++--
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/include/keys/trusted-type.h b/include/keys/trusted-type.h
> index 020e01a99ea4..154d8a1769c3 100644
> --- a/include/keys/trusted-type.h
> +++ b/include/keys/trusted-type.h
> @@ -21,6 +21,7 @@
>  
>  struct trusted_key_payload {
>  	struct rcu_head rcu;
> +	unsigned int blob_handle;
>  	unsigned int key_len;
>  	unsigned int blob_len;
>  	unsigned int creation_len;
> diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c
> index 6357a51a24e9..a3673fffd834 100644
> --- a/security/keys/trusted-keys/trusted_tpm2.c
> +++ b/security/keys/trusted-keys/trusted_tpm2.c
> @@ -272,11 +272,13 @@ static int tpm2_load_cmd(struct tpm_chip *chip,
>  	}
>  
>  	rc = tpm_send(chip, buf.data, tpm_buf_length(&buf));
> -	if (!rc)
> +	if (!rc) {
>  		*blob_handle = be32_to_cpup(
>  			(__be32 *) &buf.data[TPM_HEADER_SIZE]);
> -	else
> +		payload->blob_handle = *blob_handle;
> +	} else {
>  		goto out;
> +	}
>  
>  	rc = tpm2_unpack_blob(payload);
>  out:
> -- 
> 2.30.0.617.g56c4b15f3c-goog
> 
>
diff mbox series

Patch

diff --git a/include/keys/trusted-type.h b/include/keys/trusted-type.h
index 020e01a99ea4..154d8a1769c3 100644
--- a/include/keys/trusted-type.h
+++ b/include/keys/trusted-type.h
@@ -21,6 +21,7 @@ 
 
 struct trusted_key_payload {
 	struct rcu_head rcu;
+	unsigned int blob_handle;
 	unsigned int key_len;
 	unsigned int blob_len;
 	unsigned int creation_len;
diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c
index 6357a51a24e9..a3673fffd834 100644
--- a/security/keys/trusted-keys/trusted_tpm2.c
+++ b/security/keys/trusted-keys/trusted_tpm2.c
@@ -272,11 +272,13 @@  static int tpm2_load_cmd(struct tpm_chip *chip,
 	}
 
 	rc = tpm_send(chip, buf.data, tpm_buf_length(&buf));
-	if (!rc)
+	if (!rc) {
 		*blob_handle = be32_to_cpup(
 			(__be32 *) &buf.data[TPM_HEADER_SIZE]);
-	else
+		payload->blob_handle = *blob_handle;
+	} else {
 		goto out;
+	}
 
 	rc = tpm2_unpack_blob(payload);
 out: