Skip to content

Commit cb8affb

Browse files
iokillherbertx
authored andcommitted
crypto: nx - Fix timing leak in GCM and CCM decryption
Using non-constant time memcmp() makes the verification of the authentication tag in the decrypt path vulnerable to timing attacks. Fix this by using crypto_memneq() instead. Cc: stable@vger.kernel.org Signed-off-by: David Gstir <david@sigma-star.at> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 8005c49 commit cb8affb

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

drivers/crypto/nx/nx-aes-ccm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ static int ccm_nx_decrypt(struct aead_request *req,
409409
processed += to_process;
410410
} while (processed < nbytes);
411411

412-
rc = memcmp(csbcpb->cpb.aes_ccm.out_pat_or_mac, priv->oauth_tag,
412+
rc = crypto_memneq(csbcpb->cpb.aes_ccm.out_pat_or_mac, priv->oauth_tag,
413413
authsize) ? -EBADMSG : 0;
414414
out:
415415
spin_unlock_irqrestore(&nx_ctx->lock, irq_flags);

drivers/crypto/nx/nx-aes-gcm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <crypto/internal/aead.h>
2323
#include <crypto/aes.h>
24+
#include <crypto/algapi.h>
2425
#include <crypto/scatterwalk.h>
2526
#include <linux/module.h>
2627
#include <linux/types.h>
@@ -418,7 +419,7 @@ static int gcm_aes_nx_crypt(struct aead_request *req, int enc,
418419
itag, req->src, req->assoclen + nbytes,
419420
crypto_aead_authsize(crypto_aead_reqtfm(req)),
420421
SCATTERWALK_FROM_SG);
421-
rc = memcmp(itag, otag,
422+
rc = crypto_memneq(itag, otag,
422423
crypto_aead_authsize(crypto_aead_reqtfm(req))) ?
423424
-EBADMSG : 0;
424425
}

0 commit comments

Comments
 (0)