mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vincent Whitchurch <vincent.whitchurch@axis.com>
To: <herbert@gondor.apana.org.au>, <davem@davemloft.net>,
	<jesper.nilsson@axis.com>, <lars.persson@axis.com>
Cc: <kernel@axis.com>,
	Vincent Whitchurch <vincent.whitchurch@axis.com>,
	<linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH 11/12] crypto: axis - handle zero cryptlen
Date: Tue, 10 Jan 2023 14:50:41 +0100	[thread overview]
Message-ID: <20230110135042.2940847-12-vincent.whitchurch@axis.com> (raw)
In-Reply-To: <20230110135042.2940847-1-vincent.whitchurch@axis.com>

Succeed zero length operations to prevent hangs/failures with various
CRYPTO_MANAGER_EXTRA_TESTS such as:

 artpec6-ecb-aes "random: len=0 klen=32" encryption random:
 inplace_two_sglists may_sleep use_finup src_divs=[100.0%@+2743]
 key_offset=93

For XTS, sizes lesser than the block size need to be explicitly rejected
to prevent errors like this:

 alg: skcipher: artpec6-xts-aes encryption unexpectedly succeeded on test
 vector "random: len=0 klen=64"; expected_error=-22, cfg="rando m:
 use_final nosimd src_divs=[<reimport>100.0%@+3991]
 dst_divs=[73.80%@+4003, 26.20%@+16] iv_offset=68"

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
 drivers/crypto/axis/artpec6_crypto.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/crypto/axis/artpec6_crypto.c b/drivers/crypto/axis/artpec6_crypto.c
index 5eccb5a3a52e..938faf3afa69 100644
--- a/drivers/crypto/axis/artpec6_crypto.c
+++ b/drivers/crypto/axis/artpec6_crypto.c
@@ -1097,6 +1097,9 @@ static int __artpec6_crypto_encrypt(struct skcipher_request *req)
 	void (*complete)(struct crypto_async_request *req);
 	int ret;
 
+	if (!req->cryptlen)
+		return 0;
+
 	req_ctx = skcipher_request_ctx(req);
 
 	switch (ctx->crypto_type) {
@@ -1145,6 +1148,9 @@ static int __artpec6_crypto_decrypt(struct skcipher_request *req)
 	struct artpec6_crypto_request_context *req_ctx = NULL;
 	void (*complete)(struct crypto_async_request *req);
 
+	if (!req->cryptlen)
+		return 0;
+
 	req_ctx = skcipher_request_ctx(req);
 
 	switch (ctx->crypto_type) {
@@ -1311,6 +1317,9 @@ static int artpec6_crypto_ctr_decrypt(struct skcipher_request *req)
 
 static int artpec6_crypto_xts_encrypt(struct skcipher_request *req)
 {
+	if (req->cryptlen < AES_BLOCK_SIZE)
+		return -EINVAL;
+
 	/* Hardware does not implement ciphertext stealing */
 	if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE))
 		return artpec6_crypto_crypt_fallback(req, true);
@@ -1320,6 +1329,9 @@ static int artpec6_crypto_xts_encrypt(struct skcipher_request *req)
 
 static int artpec6_crypto_xts_decrypt(struct skcipher_request *req)
 {
+	if (req->cryptlen < AES_BLOCK_SIZE)
+		return -EINVAL;
+
 	/* Hardware does not implement ciphertext stealing */
 	if (!IS_ALIGNED(req->cryptlen, AES_BLOCK_SIZE))
 		return artpec6_crypto_crypt_fallback(req, false);
-- 
2.34.1


  parent reply	other threads:[~2023-01-10 13:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10 13:50 [PATCH 00/12] crypto: axis - make tests pass Vincent Whitchurch
2023-01-10 13:50 ` [PATCH 01/12] crypto: axis - do not DMA to ahash_request.result Vincent Whitchurch
2023-01-20  9:09   ` Herbert Xu
2023-01-27 15:35     ` Vincent Whitchurch
2023-01-10 13:50 ` [PATCH 02/12] crypto: axis - do not DMA to IV Vincent Whitchurch
2023-01-20  9:11   ` Herbert Xu
2023-01-27 15:39     ` Vincent Whitchurch
2023-01-30  7:29       ` Herbert Xu
2023-01-10 13:50 ` [PATCH 03/12] crypto: axis - fix CTR output IV Vincent Whitchurch
2023-01-10 13:50 ` [PATCH 04/12] crypto: axis - fix in-place CBC " Vincent Whitchurch
2023-01-10 13:50 ` [PATCH 05/12] crypto: axis - validate AEAD authsize Vincent Whitchurch
2023-01-10 13:50 ` [PATCH 06/12] crypto: axis - reject invalid sizes Vincent Whitchurch
2023-01-10 13:50 ` [PATCH 07/12] crypto: axis - fix XTS blocksize Vincent Whitchurch
2023-01-10 13:50 ` [PATCH 08/12] crypto: axis - add skcipher fallback Vincent Whitchurch
2023-01-10 13:50 ` [PATCH 09/12] crypto: axis - add fallback for AEAD Vincent Whitchurch
2023-01-10 13:50 ` [PATCH 10/12] crypto: axis - fix XTS unaligned block size handling Vincent Whitchurch
2023-01-10 13:50 ` Vincent Whitchurch [this message]
2023-01-10 13:50 ` [PATCH 12/12] crypto: axis - allow small size for AEAD Vincent Whitchurch

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=20230110135042.2940847-12-vincent.whitchurch@axis.com \
    --to=vincent.whitchurch@axis.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=jesper.nilsson@axis.com \
    --cc=kernel@axis.com \
    --cc=lars.persson@axis.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®