Skip to contentSkip to conversation

tpm: Call tpm_put_ops() when the validation for @digests fails

PATCH In review Jarkko Sakkinen 2 participants 3 messages Sep 10, 2019 – Sep 13, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/char/tpm/tpm-interface.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm-interface.c +9 -5
index 208e5ba40e6e..c7eeb40feac8 100644
@@ -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;
 }
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jarkko Sakkinen

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

Quoted 39 lines

---
drivers/char/tpm/tpm-interface.c | 14 +++++++++-----

1 file changed, 9 insertions(+), 5 deletions(-)
drivers/char/tpm/tpm-interface.c +9 -5
index 208e5ba40e6e..c7eeb40feac8 100644
@@ -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;
 }
Signature · 1 line
2.20.1
#2 lore raw
Quoted 9 lines · Jerry Snitselaar
Quoted 6 lines · Jarkko Sakkinen

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

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