From: Andrei Botila <andrei.botila@nxp.com>
Date: Tue, 22 Sep 2020 19:03:25 +0300
Subject: crypto: caam - add xts check for block length equal to zero
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Git-commit: 297b931c2a3cada230d8b84432ee982fc68cf76a
Patch-mainline: v5.10-rc1
References: jsc#SLE-16106
XTS should not return succes when dealing with block length equal to zero.
This is different than the rest of the skcipher algorithms.
Fixes: 31bb2f0da1b50 ("crypto: caam - check zero-length input")
Cc: <stable@vger.kernel.org> # v5.4+
Signed-off-by: Andrei Botila <andrei.botila@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
drivers/crypto/caam/caamalg.c | 7 ++++++-
drivers/crypto/caam/caamalg_qi.c | 7 ++++++-
drivers/crypto/caam/caamalg_qi2.c | 14 ++++++++++++--
3 files changed, 24 insertions(+), 4 deletions(-)
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -1806,7 +1806,12 @@ static inline int skcipher_crypt(struct
u32 *desc;
int ret = 0;
- if (!req->cryptlen)
+ /*
+ * XTS is expected to return an error even for input length = 0
+ * Note that the case input length < block size will be caught during
+ * HW offloading and return an error.
+ */
+ if (!req->cryptlen && !ctx->fallback)
return 0;
if (ctx->fallback && (xts_skcipher_ivsize(req) ||
--- a/drivers/crypto/caam/caamalg_qi.c
+++ b/drivers/crypto/caam/caamalg_qi.c
@@ -1427,7 +1427,12 @@ static inline int skcipher_crypt(struct
struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
int ret;
- if (!req->cryptlen)
+ /*
+ * XTS is expected to return an error even for input length = 0
+ * Note that the case input length < block size will be caught during
+ * HW offloading and return an error.
+ */
+ if (!req->cryptlen && !ctx->fallback)
return 0;
if (ctx->fallback && (xts_skcipher_ivsize(req) ||
--- a/drivers/crypto/caam/caamalg_qi2.c
+++ b/drivers/crypto/caam/caamalg_qi2.c
@@ -1498,7 +1498,12 @@ static int skcipher_encrypt(struct skcip
struct caam_request *caam_req = skcipher_request_ctx(req);
int ret;
- if (!req->cryptlen)
+ /*
+ * XTS is expected to return an error even for input length = 0
+ * Note that the case input length < block size will be caught during
+ * HW offloading and return an error.
+ */
+ if (!req->cryptlen && !ctx->fallback)
return 0;
if (ctx->fallback && (xts_skcipher_ivsize(req) ||
@@ -1542,7 +1547,12 @@ static int skcipher_decrypt(struct skcip
struct caam_request *caam_req = skcipher_request_ctx(req);
int ret;
- if (!req->cryptlen)
+ /*
+ * XTS is expected to return an error even for input length = 0
+ * Note that the case input length < block size will be caught during
+ * HW offloading and return an error.
+ */
+ if (!req->cryptlen && !ctx->fallback)
return 0;
if (ctx->fallback && (xts_skcipher_ivsize(req) ||