tpm: Return tpm2_sessions_init() when null key creation fails

Do not continue tpm2_sessions_init() further if the null key pair creation
fails.

Cc: stable@vger.kernel.org # v6.10+
Fixes: d2add27cf2 ("tpm: Add NULL primary creation")
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
This commit is contained in:
Jarkko Sakkinen 2024-10-28 07:49:59 +02:00
parent 8198375843
commit d658d59471

View file

@ -1347,14 +1347,21 @@ static int tpm2_create_null_primary(struct tpm_chip *chip)
* *
* Derive and context save the null primary and allocate memory in the * Derive and context save the null primary and allocate memory in the
* struct tpm_chip for the authorizations. * struct tpm_chip for the authorizations.
*
* Return:
* * 0 - OK
* * -errno - A system error
* * TPM_RC - A TPM error
*/ */
int tpm2_sessions_init(struct tpm_chip *chip) int tpm2_sessions_init(struct tpm_chip *chip)
{ {
int rc; int rc;
rc = tpm2_create_null_primary(chip); rc = tpm2_create_null_primary(chip);
if (rc) if (rc) {
dev_err(&chip->dev, "TPM: security failed (NULL seed derivation): %d\n", rc); dev_err(&chip->dev, "null key creation failed with %d\n", rc);
return rc;
}
chip->auth = kmalloc(sizeof(*chip->auth), GFP_KERNEL); chip->auth = kmalloc(sizeof(*chip->auth), GFP_KERNEL);
if (!chip->auth) if (!chip->auth)