]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
crypto: caam - add xts check for block length equal to zero
authorAndrei Botila <andrei.botila@nxp.com>
Tue, 22 Sep 2020 16:03:25 +0000 (19:03 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 09:10:59 +0000 (10:10 +0100)
commit 297b931c2a3cada230d8b84432ee982fc68cf76a upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/crypto/caam/caamalg.c
drivers/crypto/caam/caamalg_qi.c
drivers/crypto/caam/caamalg_qi2.c

index 91feda5b63f65c164adbb427707d5aa7b7700cdd..baaf0e3c4b9d7c8405225efebdaa32e1715be0c0 100644 (file)
@@ -1765,7 +1765,12 @@ static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt)
        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;
 
        /* allocate extended descriptor */
index bb1c0106a95c3e9276cb964b6092a4afc5434687..c0a9a116442cf4b713a41e617c3fe77d620e03a7 100644 (file)
@@ -1380,7 +1380,12 @@ static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt)
        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 (unlikely(caam_congested))
index 66ae1d58116890c29714def791dcebd0d8a9e7de..a3a68cf8784f31a1d71e373d5133d8b0d8c4fd60 100644 (file)
@@ -1451,7 +1451,12 @@ static int skcipher_encrypt(struct skcipher_request *req)
        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;
 
        /* allocate extended descriptor */
@@ -1482,7 +1487,12 @@ static int skcipher_decrypt(struct skcipher_request *req)
        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;
        /* allocate extended descriptor */
        edesc = skcipher_edesc_alloc(req);