Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tpm: Use auth only after NULL check in tpm_buf_check_hmac_response()

Dereference auth after NULL check in tpm_buf_check_hmac_response().
Otherwise, unless tpm2_sessions_init() was called, a call can cause NULL
dereference, when TCG_TPM2_HMAC is enabled.

[jarkko: adjusted the commit message.]
Cc: stable@vger.kernel.org # v6.10+
Fixes: 7ca110f2679b ("tpm: Address !chip->auth in tpm_buf_append_hmac_session*()")
Signed-off-by: Hao Ge <gehao@kylinos.cn>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>

authored by

Hao Ge and committed by
Jarkko Sakkinen
7dc357d3 d6797831

+3 -2
+3 -2
drivers/char/tpm/tpm2-sessions.c
··· 746 746 struct tpm2_auth *auth = chip->auth; 747 747 off_t offset_s, offset_p; 748 748 u8 rphash[SHA256_DIGEST_SIZE]; 749 - u32 attrs; 749 + u32 attrs, cc; 750 750 struct sha256_state sctx; 751 751 u16 tag = be16_to_cpu(head->tag); 752 - u32 cc = be32_to_cpu(auth->ordinal); 753 752 int parm_len, len, i, handles; 754 753 755 754 if (!auth) 756 755 return rc; 756 + 757 + cc = be32_to_cpu(auth->ordinal); 757 758 758 759 if (auth->session >= TPM_HEADER_SIZE) { 759 760 WARN(1, "tpm session not filled correctly\n");