All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Eric Biggers <ebiggers@kernel.org>
Cc: James Bottomley <James.Bottomley@hansenpartnership.com>,
	Mimi Zohar <zohar@linux.ibm.com>,
	keyrings@vger.kernel.org, David Howells <dhowells@redhat.com>,
	linux-integrity@vger.kernel.org, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/3] KEYS: trusted_tpm1: Compare HMAC values in constant time
Date: Tue, 5 Aug 2025 16:44:27 +0300	[thread overview]
Message-ID: <aJIKu7uD-nYQERKW@kernel.org> (raw)
In-Reply-To: <20250731212354.105044-2-ebiggers@kernel.org>

On Thu, Jul 31, 2025 at 02:23:52PM -0700, Eric Biggers wrote:
> To prevent timing attacks, HMAC value comparison needs to be constant
> time.  Replace the memcmp() with the correct function, crypto_memneq().
> 
> Fixes: d00a1c72f7f4 ("keys: add new trusted key-type")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>

Was crypto_memneq() available at the time?

> ---
>  security/keys/trusted-keys/trusted_tpm1.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trusted-keys/trusted_tpm1.c
> index 89c9798d18007..e73f2c6c817a0 100644
> --- a/security/keys/trusted-keys/trusted_tpm1.c
> +++ b/security/keys/trusted-keys/trusted_tpm1.c
> @@ -5,10 +5,11 @@
>   *
>   * See Documentation/security/keys/trusted-encrypted.rst
>   */
>  
>  #include <crypto/hash_info.h>
> +#include <crypto/utils.h>
>  #include <linux/init.h>
>  #include <linux/slab.h>
>  #include <linux/parser.h>
>  #include <linux/string.h>
>  #include <linux/err.h>
> @@ -239,11 +240,11 @@ int TSS_checkhmac1(unsigned char *buffer,
>  			  TPM_NONCE_SIZE, enonce, TPM_NONCE_SIZE, ononce,
>  			  1, continueflag, 0, 0);
>  	if (ret < 0)
>  		goto out;
>  
> -	if (memcmp(testhmac, authdata, SHA1_DIGEST_SIZE))
> +	if (crypto_memneq(testhmac, authdata, SHA1_DIGEST_SIZE))
>  		ret = -EINVAL;
>  out:
>  	kfree_sensitive(sdesc);
>  	return ret;
>  }
> @@ -332,20 +333,20 @@ static int TSS_checkhmac2(unsigned char *buffer,
>  	ret = TSS_rawhmac(testhmac1, key1, keylen1, SHA1_DIGEST_SIZE,
>  			  paramdigest, TPM_NONCE_SIZE, enonce1,
>  			  TPM_NONCE_SIZE, ononce, 1, continueflag1, 0, 0);
>  	if (ret < 0)
>  		goto out;
> -	if (memcmp(testhmac1, authdata1, SHA1_DIGEST_SIZE)) {
> +	if (crypto_memneq(testhmac1, authdata1, SHA1_DIGEST_SIZE)) {
>  		ret = -EINVAL;
>  		goto out;
>  	}
>  	ret = TSS_rawhmac(testhmac2, key2, keylen2, SHA1_DIGEST_SIZE,
>  			  paramdigest, TPM_NONCE_SIZE, enonce2,
>  			  TPM_NONCE_SIZE, ononce, 1, continueflag2, 0, 0);
>  	if (ret < 0)
>  		goto out;
> -	if (memcmp(testhmac2, authdata2, SHA1_DIGEST_SIZE))
> +	if (crypto_memneq(testhmac2, authdata2, SHA1_DIGEST_SIZE))
>  		ret = -EINVAL;
>  out:
>  	kfree_sensitive(sdesc);
>  	return ret;
>  }
> 
> base-commit: d6084bb815c453de27af8071a23163a711586a6c
> -- 
> 2.50.1
> 

BR, Jarkko

  reply	other threads:[~2025-08-05 13:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-31 21:23 [PATCH 0/3] KEYS: trusted_tpm1: HMAC fix and cleanup Eric Biggers
2025-07-31 21:23 ` [PATCH 1/3] KEYS: trusted_tpm1: Compare HMAC values in constant time Eric Biggers
2025-08-05 13:44   ` Jarkko Sakkinen [this message]
2025-08-05 17:32     ` Eric Biggers
2025-08-09 10:37       ` Jarkko Sakkinen
2025-08-09 17:21         ` Eric Biggers
2025-07-31 21:23 ` [PATCH 2/3] KEYS: trusted_tpm1: Use SHA-1 library instead of crypto_shash Eric Biggers
2025-08-05 13:45   ` Jarkko Sakkinen
2025-07-31 21:23 ` [PATCH 3/3] KEYS: trusted_tpm1: Move private functionality out of public header Eric Biggers
2025-08-05 13:48   ` Jarkko Sakkinen
2025-08-05 17:33     ` Eric Biggers
2025-08-09 10:38       ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aJIKu7uD-nYQERKW@kernel.org \
    --to=jarkko@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=dhowells@redhat.com \
    --cc=ebiggers@kernel.org \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.