security: keys: trusted: always clear the hmac_sha1_ctx before returning

Clear the hmac_sha1_ctx structure via __cleanup(hmac_sha1_zeroize_ctx)
to make sure that the function does not leak sensitive data on the stack
when returning without calling hmac_sha1_final().

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Link: https://patch.msgid.link/20260916095022.604354-10-thuth@redhat.com
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
This commit is contained in:
Thomas Huth 2026-09-16 11:50:11 +02:00 committed by Eric Biggers
parent e09cbc96ff
commit 6df7613758

View File

@ -101,7 +101,7 @@ static inline void dump_tpm_buf(unsigned char *buf)
static int TSS_rawhmac(unsigned char *digest, const unsigned char *key,
unsigned int keylen, ...)
{
struct hmac_sha1_ctx hmac_ctx;
struct hmac_sha1_ctx hmac_ctx __cleanup(hmac_sha1_zeroize_ctx);
va_list argp;
unsigned int dlen;
unsigned char *data;