[v4,02/11] tpm: Export and rename tpm2_find_and_validate_cc()

Message ID 20221103105558.v4.2.I7bbedcf5efd3f1c72c32d6002faed086c5ed31c7@changeid
State New
Headers
Series Encrypted Hibernation |

Commit Message

Evan Green Nov. 3, 2022, 6:01 p.m. UTC
  Export tpm_find_and_validate_cc() since it will be needed by an upcoming
change allowing access to certain PCRs to be restricted to the kernel.
In order to export it consistently, and because it's a tpm2-only
function, rename it to tpm2_find_and_validate_cc().

Signed-off-by: Evan Green <evgreen@chromium.org>

---

(no changes since v3)

Changes in v3:
 - Split find_and_validate_cc() export to its own patch (Jarkko)
 - Rename tpm_find_and_validate_cc() to tpm2_find_and_validate_cc().

 drivers/char/tpm/tpm.h        | 3 +++
 drivers/char/tpm/tpm2-space.c | 8 ++++----
 2 files changed, 7 insertions(+), 4 deletions(-)
  

Comments

Kees Cook Nov. 4, 2022, 6:25 p.m. UTC | #1
On Thu, Nov 03, 2022 at 11:01:10AM -0700, Evan Green wrote:
> Export tpm_find_and_validate_cc() since it will be needed by an upcoming
> change allowing access to certain PCRs to be restricted to the kernel.
> In order to export it consistently, and because it's a tpm2-only
> function, rename it to tpm2_find_and_validate_cc().
> 
> Signed-off-by: Evan Green <evgreen@chromium.org>

Reviewed-by: Kees Cook <keescook@chromium.org>
  
Jarkko Sakkinen Nov. 7, 2022, 11:37 a.m. UTC | #2
On Thu, Nov 03, 2022 at 11:01:10AM -0700, Evan Green wrote:
> Export tpm_find_and_validate_cc() since it will be needed by an upcoming
> change allowing access to certain PCRs to be restricted to the kernel.
> In order to export it consistently, and because it's a tpm2-only
> function, rename it to tpm2_find_and_validate_cc().
> 
> Signed-off-by: Evan Green <evgreen@chromium.org>
> 
> ---
> 
> (no changes since v3)
> 
> Changes in v3:
>  - Split find_and_validate_cc() export to its own patch (Jarkko)
>  - Rename tpm_find_and_validate_cc() to tpm2_find_and_validate_cc().
> 
>  drivers/char/tpm/tpm.h        | 3 +++
>  drivers/char/tpm/tpm2-space.c | 8 ++++----
>  2 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
> index 24ee4e1cc452a0..f1e0f490176f01 100644
> --- a/drivers/char/tpm/tpm.h
> +++ b/drivers/char/tpm/tpm.h
> @@ -231,6 +231,9 @@ int tpm2_find_cc(struct tpm_chip *chip, u32 cc);
>  int tpm2_init_space(struct tpm_space *space, unsigned int buf_size);
>  void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space);
>  void tpm2_flush_space(struct tpm_chip *chip);
> +int tpm2_find_and_validate_cc(struct tpm_chip *chip,
> +			      struct tpm_space *space,
> +			      const void *cmd, size_t len);
>  int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u8 *cmd,
>  		       size_t cmdsiz);
>  int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, void *buf,
> diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
> index ffb35f0154c16c..ca34cc006e7f8d 100644
> --- a/drivers/char/tpm/tpm2-space.c
> +++ b/drivers/char/tpm/tpm2-space.c
> @@ -262,9 +262,9 @@ static int tpm2_map_command(struct tpm_chip *chip, u32 cc, u8 *cmd)
>  	return 0;
>  }
>  
> -static int tpm_find_and_validate_cc(struct tpm_chip *chip,
> -				    struct tpm_space *space,
> -				    const void *cmd, size_t len)
> +int tpm2_find_and_validate_cc(struct tpm_chip *chip,
> +			      struct tpm_space *space,
> +			      const void *cmd, size_t len)
>  {
>  	const struct tpm_header *header = (const void *)cmd;
>  	int i;
> @@ -306,7 +306,7 @@ int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u8 *cmd,
>  	if (!space)
>  		return 0;
>  
> -	cc = tpm_find_and_validate_cc(chip, space, cmd, cmdsiz);
> +	cc = tpm2_find_and_validate_cc(chip, space, cmd, cmdsiz);
>  	if (cc < 0)
>  		return cc;
>  
> -- 
> 2.38.1.431.g37b22c650d-goog
> 

Acked-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko
  

Patch

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 24ee4e1cc452a0..f1e0f490176f01 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -231,6 +231,9 @@  int tpm2_find_cc(struct tpm_chip *chip, u32 cc);
 int tpm2_init_space(struct tpm_space *space, unsigned int buf_size);
 void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space);
 void tpm2_flush_space(struct tpm_chip *chip);
+int tpm2_find_and_validate_cc(struct tpm_chip *chip,
+			      struct tpm_space *space,
+			      const void *cmd, size_t len);
 int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u8 *cmd,
 		       size_t cmdsiz);
 int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, void *buf,
diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
index ffb35f0154c16c..ca34cc006e7f8d 100644
--- a/drivers/char/tpm/tpm2-space.c
+++ b/drivers/char/tpm/tpm2-space.c
@@ -262,9 +262,9 @@  static int tpm2_map_command(struct tpm_chip *chip, u32 cc, u8 *cmd)
 	return 0;
 }
 
-static int tpm_find_and_validate_cc(struct tpm_chip *chip,
-				    struct tpm_space *space,
-				    const void *cmd, size_t len)
+int tpm2_find_and_validate_cc(struct tpm_chip *chip,
+			      struct tpm_space *space,
+			      const void *cmd, size_t len)
 {
 	const struct tpm_header *header = (const void *)cmd;
 	int i;
@@ -306,7 +306,7 @@  int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u8 *cmd,
 	if (!space)
 		return 0;
 
-	cc = tpm_find_and_validate_cc(chip, space, cmd, cmdsiz);
+	cc = tpm2_find_and_validate_cc(chip, space, cmd, cmdsiz);
 	if (cc < 0)
 		return cc;