2019-09-10 14:34:41

by Jarkko Sakkinen

[permalink] [raw]
Subject: [PATCH] tpm: Call tpm_put_ops() when the validation for @digests fails

The chip is not released when the validation for @digests fails. Add
tpm_put_ops() to the failure path.

Cc: [email protected]
Reported-by: Roberto Sassu <[email protected]>
Signed-off-by: Jarkko Sakkinen <[email protected]>
---
drivers/char/tpm/tpm-interface.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 208e5ba40e6e..c7eeb40feac8 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -320,18 +320,22 @@ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
if (!chip)
return -ENODEV;

- for (i = 0; i < chip->nr_allocated_banks; i++)
- if (digests[i].alg_id != chip->allocated_banks[i].alg_id)
- return -EINVAL;
+ for (i = 0; i < chip->nr_allocated_banks; i++) {
+ if (digests[i].alg_id != chip->allocated_banks[i].alg_id) {
+ rc = EINVAL;
+ goto out;
+ }
+ }

if (chip->flags & TPM_CHIP_FLAG_TPM2) {
rc = tpm2_pcr_extend(chip, pcr_idx, digests);
- tpm_put_ops(chip);
- return rc;
+ goto out;
}

rc = tpm1_pcr_extend(chip, pcr_idx, digests[0].digest,
"attempting extend a PCR value");
+
+out:
tpm_put_ops(chip);
return rc;
}
--
2.20.1


2019-09-10 15:14:15

by Jerry Snitselaar

[permalink] [raw]
Subject: Re: [PATCH] tpm: Call tpm_put_ops() when the validation for @digests fails

On Tue Sep 10 19, Jarkko Sakkinen wrote:
>The chip is not released when the validation for @digests fails. Add
>tpm_put_ops() to the failure path.
>
>Cc: [email protected]
>Reported-by: Roberto Sassu <[email protected]>
>Signed-off-by: Jarkko Sakkinen <[email protected]>

Reviewed-by: Jerry Snitselaar <[email protected]>

>---
> drivers/char/tpm/tpm-interface.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
>diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
>index 208e5ba40e6e..c7eeb40feac8 100644
>--- a/drivers/char/tpm/tpm-interface.c
>+++ b/drivers/char/tpm/tpm-interface.c
>@@ -320,18 +320,22 @@ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
> if (!chip)
> return -ENODEV;
>
>- for (i = 0; i < chip->nr_allocated_banks; i++)
>- if (digests[i].alg_id != chip->allocated_banks[i].alg_id)
>- return -EINVAL;
>+ for (i = 0; i < chip->nr_allocated_banks; i++) {
>+ if (digests[i].alg_id != chip->allocated_banks[i].alg_id) {
>+ rc = EINVAL;
>+ goto out;
>+ }
>+ }
>
> if (chip->flags & TPM_CHIP_FLAG_TPM2) {
> rc = tpm2_pcr_extend(chip, pcr_idx, digests);
>- tpm_put_ops(chip);
>- return rc;
>+ goto out;
> }
>
> rc = tpm1_pcr_extend(chip, pcr_idx, digests[0].digest,
> "attempting extend a PCR value");
>+
>+out:
> tpm_put_ops(chip);
> return rc;
> }
>--
>2.20.1
>

2019-09-13 13:54:52

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH] tpm: Call tpm_put_ops() when the validation for @digests fails

On Tue, Sep 10, 2019 at 08:11:21AM -0700, Jerry Snitselaar wrote:
> On Tue Sep 10 19, Jarkko Sakkinen wrote:
> > The chip is not released when the validation for @digests fails. Add
> > tpm_put_ops() to the failure path.
> >
> > Cc: [email protected]
> > Reported-by: Roberto Sassu <[email protected]>
> > Signed-off-by: Jarkko Sakkinen <[email protected]>
>
> Reviewed-by: Jerry Snitselaar <[email protected]>

Roberto, can you just squash this fix with yours to a single patch and
send a new patch version? You can add suggested-by tag from me to v4.

/Jarkko