Skip to contentSkip to conversation

crypto: octeontx2 - use crypto_memneq() to check HMAC for cipher_null authenc

PATCH In review David C.C.M. Gall 2 participants 2 messages Aug 15 – Sep 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: octeontx2 - use crypto_memneq() to check HMAC for cipher_null authenc

validate_hmac_cipher_null() compares the computed and received HMAC with memcmp(), which short-circuits on the first differing byte and leaks tag-match length via timing. Use crypto_memneq() instead.

Because for cipher_null the validated payload is un-encrypted, this valid prefix leak allows for authenticated message forgery.

Assisted-by gregkh_clanker_t1000
---
 drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c +4 -3
index 8d9f394d6b50..3ccf17d031c6 100644
@@ -11,6 +11,7 @@
 #include <crypto/xts.h>
 #include <crypto/gcm.h>
 #include <crypto/scatterwalk.h>
+#include <crypto/utils.h>
 #include <linux/sort.h>
 #include <linux/module.h>
 #include "otx2_cptvf.h"
@@ -90,9 +91,9 @@ static inline int validate_hmac_cipher_null(struct otx2_cpt_req_info *cpt_req)
 	req = container_of(cpt_req->areq, struct aead_request, base);
 	tfm = crypto_aead_reqtfm(req);
 	rctx = aead_request_ctx_dma(req);
-	if (memcmp(rctx->fctx.hmac.s.hmac_calc,
-		   rctx->fctx.hmac.s.hmac_recv,
-		   crypto_aead_authsize(tfm)) != 0)
+	if (crypto_memneq(rctx->fctx.hmac.s.hmac_calc,
+			  rctx->fctx.hmac.s.hmac_recv,
+			  crypto_aead_authsize(tfm)))
 		return -EBADMSG;
 
 	return 0;
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 4 lines · David C.C.M. Gall

validate_hmac_cipher_null() compares the computed and received HMAC with memcmp(), which short-circuits on the first differing byte and leaks tag-match length via timing. Use crypto_memneq() instead.

Quoted 8 lines

Because for cipher_null the validated payload is un-encrypted, this valid prefix leak allows for authenticated message forgery.

Assisted-by gregkh_clanker_t1000
---
 drivers/crypto/marvell/octeontx2/otx2_cptvf_algs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt