Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Christian Lamparter <chunkeey@gmail.com>
To: linux-crypto@vger.kernel.org
Cc: Eric Biggers <ebiggers@google.com>,
	Herbert Xu <herbert@gondor.apana.org.au>
Subject: [RFC PATCH] crypto: skcipher - perform len fits into blocksize check at the top
Date: Sat, 18 May 2019 23:30:35 +0200	[thread overview]
Message-ID: <20190518213035.21699-1-chunkeey@gmail.com> (raw)

This patch adds early check to test the given data length
is aligned with the supported ciphers blocksize, or abort
with -EINVAL in case the supplied chunk size does not fit
without padding into the blocksize for block ciphers.

Signed-off-by: Christian Lamparter <chunkeey@gmail.com>

---

This will also work instead of the
"crypto: crypto4xx - blockciphers should only accept complete blocks"
It will fix all potential driver issues in other drivers as well as
break the drivers that don't have the correct blocksize set. it will
also make the extra checks scattered around in the drivers make
redundand as well as the extra tests that do send incomplete blocks
to the hardware drivers.
---
 include/crypto/skcipher.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h
index e555294ed77f..971294602a41 100644
--- a/include/crypto/skcipher.h
+++ b/include/crypto/skcipher.h
@@ -494,6 +494,8 @@ static inline int crypto_skcipher_encrypt(struct skcipher_request *req)
 	crypto_stats_get(alg);
 	if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
 		ret = -ENOKEY;
+	else if (!IS_ALIGNED(cryptlen, crypto_skcipher_blocksize(tfm)))
+		ret = -EINVAL;
 	else
 		ret = tfm->encrypt(req);
 	crypto_stats_skcipher_encrypt(cryptlen, ret, alg);
@@ -521,6 +523,8 @@ static inline int crypto_skcipher_decrypt(struct skcipher_request *req)
 	crypto_stats_get(alg);
 	if (crypto_skcipher_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
 		ret = -ENOKEY;
+	else if (!IS_ALIGNED(cryptlen, crypto_skcipher_blocksize(tfm)))
+		ret = -EINVAL;
 	else
 		ret = tfm->decrypt(req);
 	crypto_stats_skcipher_decrypt(cryptlen, ret, alg);
-- 
2.20.1


             reply	other threads:[~2019-05-18 21:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-18 21:30 Christian Lamparter [this message]
2019-05-18 22:20 ` [RFC PATCH] crypto: skcipher - perform len fits into blocksize check at the top Eric Biggers

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=20190518213035.21699-1-chunkeey@gmail.com \
    --to=chunkeey@gmail.com \
    --cc=ebiggers@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@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