Skip to content

Commit 25ee48a

Browse files
committed
tpm: Address !chip->auth in tpm2_*_auth_session()
Unless tpm_chip_bootstrap() was called by the driver, !chip->auth can cause a null derefence in tpm2_*_auth_session(). Thus, address !chip->auth in tpm2_*_auth_session(). Cc: [email protected] # v6.9+ Reported-by: Stefan Berger <[email protected]> Closes: https://lore.kernel.org/linux-integrity/[email protected]/ Fixes: 699e3ef ("tpm: Add HMAC session start and end functions") Tested-by: Michael Ellerman <[email protected]> # ppc Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent 661e504 commit 25ee48a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/char/tpm/tpm2-sessions.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,13 @@ EXPORT_SYMBOL(tpm_buf_check_hmac_response);
824824
*/
825825
void tpm2_end_auth_session(struct tpm_chip *chip)
826826
{
827-
tpm2_flush_context(chip, chip->auth->handle);
828-
memzero_explicit(chip->auth, sizeof(*chip->auth));
827+
struct tpm2_auth *auth = chip->auth;
828+
829+
if (!auth)
830+
return;
831+
832+
tpm2_flush_context(chip, auth->handle);
833+
memzero_explicit(auth, sizeof(*auth));
829834
}
830835
EXPORT_SYMBOL(tpm2_end_auth_session);
831836

@@ -907,6 +912,11 @@ int tpm2_start_auth_session(struct tpm_chip *chip)
907912
int rc;
908913
u32 null_key;
909914

915+
if (!auth) {
916+
dev_warn_once(&chip->dev, "auth session is not active\n");
917+
return 0;
918+
}
919+
910920
rc = tpm2_load_null(chip, &null_key);
911921
if (rc)
912922
goto out;

0 commit comments

Comments
 (0)