Skip to content

Commit eed0e3d

Browse files
Eric Biggersjarkkojs
authored andcommitted
KEYS: trusted_tpm1: Compare HMAC values in constant time
To prevent timing attacks, HMAC value comparison needs to be constant time. Replace the memcmp() with the correct function, crypto_memneq(). [For the Fixes commit I used the commit that introduced the memcmp(). It predates the introduction of crypto_memneq(), but it was still a bug at the time even though a helper function didn't exist yet.] Fixes: d00a1c7 ("keys: add new trusted key-type") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent fec734e commit eed0e3d

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

security/keys/trusted-keys/trusted_tpm1.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <crypto/hash_info.h>
10+
#include <crypto/utils.h>
1011
#include <linux/init.h>
1112
#include <linux/slab.h>
1213
#include <linux/parser.h>
@@ -241,7 +242,7 @@ int TSS_checkhmac1(unsigned char *buffer,
241242
if (ret < 0)
242243
goto out;
243244

244-
if (memcmp(testhmac, authdata, SHA1_DIGEST_SIZE))
245+
if (crypto_memneq(testhmac, authdata, SHA1_DIGEST_SIZE))
245246
ret = -EINVAL;
246247
out:
247248
kfree_sensitive(sdesc);
@@ -334,7 +335,7 @@ static int TSS_checkhmac2(unsigned char *buffer,
334335
TPM_NONCE_SIZE, ononce, 1, continueflag1, 0, 0);
335336
if (ret < 0)
336337
goto out;
337-
if (memcmp(testhmac1, authdata1, SHA1_DIGEST_SIZE)) {
338+
if (crypto_memneq(testhmac1, authdata1, SHA1_DIGEST_SIZE)) {
338339
ret = -EINVAL;
339340
goto out;
340341
}
@@ -343,7 +344,7 @@ static int TSS_checkhmac2(unsigned char *buffer,
343344
TPM_NONCE_SIZE, ononce, 1, continueflag2, 0, 0);
344345
if (ret < 0)
345346
goto out;
346-
if (memcmp(testhmac2, authdata2, SHA1_DIGEST_SIZE))
347+
if (crypto_memneq(testhmac2, authdata2, SHA1_DIGEST_SIZE))
347348
ret = -EINVAL;
348349
out:
349350
kfree_sensitive(sdesc);

0 commit comments

Comments
 (0)