Skip to contentSkip to conversation

crypto: add check for xts input length equal to zero

PATCH In review Andrei Botila 8 participants 33 messages Aug 7, 2020 – Aug 12, 2020

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

cover crypto: add check for xts input length equal to zero

From: Andrei Botila <[email protected]>

This patch set is a follow-up on the previous RFC discussion which can be found
here: https://lore.kernel.org/r/[email protected]

This series converts all XTS implementations to return 0 when the input length is equal to 0. This change is necessary in order to standardize the way skcipher algorithms handle this corner case. This check is made for other algorithms such as CBC, ARC4, CFB, OFB, SALSA20, CTR, ECB and PCBC, XTS being the outlier here.

Although some drivers do not explicitly check for requests with zero input length, their implementations might be able to deal with this case. Since we don't have the HW to test which ones are able and which ones are not we rely on the maintainers of these drivers to verify and comment if the changes are necessary in their driver or not.

One important thing to keep in mind is that in some implementations we make this check only for XTS algorithms although probably all skcipher algorithms should return 0 in case of zero input length.

This fix has been tested only on ARMv8 CE, the rest of the patches have been build tested *only*, and should be tested on actual hardware before being merged.

Andrei Botila (22):
crypto: arm/aes-ce - add check for xts input length equal to zero
crypto: arm/aes-neonbs - add check for xts input length equal to zero
crypto: arm64/aes - add check for xts input length equal to zero
crypto: arm64/aes-neonbs - add check for xts input length equal to
zero
crypto: powerpc/aes-spe - add check for xts input length equal to zero
crypto: s390/aes - add check for xts input length equal to zero
crypto: s390/paes - add check for xts input length equal to zero
crypto: x86/glue_helper - add check for xts input length equal to zero
crypto: xts - add check for block length equal to zero
crypto: atmel-aes - add check for xts input length equal to zero
crypto: artpec6 - add check for xts input length equal to zero
crypto: bcm - add check for xts input length equal to zero
crypto: cavium/cpt - add check for xts input length equal to zero
crypto: cavium/nitrox - add check for xts input length equal to zero
crypto: ccp - add check for xts input length equal to zero
crypto: ccree - add check for xts input length equal to zero
crypto: chelsio - add check for xts input length equal to zero
crypto: hisilicon/sec - add check for xts input length equal to zero
crypto: inside-secure - add check for xts input length equal to zero
crypto: octeontx - add check for xts input length equal to zero
crypto: qce - add check for xts input length equal to zero
crypto: vmx - add check for xts input length equal to zero

 arch/arm/crypto/aes-ce-glue.c                    |  6 ++++++
 arch/arm/crypto/aes-neonbs-glue.c                |  3 +++
 arch/arm64/crypto/aes-glue.c                     |  6 ++++++
 arch/arm64/crypto/aes-neonbs-glue.c              |  3 +++
 arch/powerpc/crypto/aes-spe-glue.c               |  6 ++++++
 arch/s390/crypto/aes_s390.c                      |  3 +++
 arch/s390/crypto/paes_s390.c                     |  3 +++
 arch/x86/crypto/glue_helper.c                    |  3 +++
 crypto/xts.c                                     |  6 ++++++
 drivers/crypto/atmel-aes.c                       |  4 ++++
 drivers/crypto/axis/artpec6_crypto.c             |  6 ++++++
 drivers/crypto/bcm/cipher.c                      |  3 +++
 drivers/crypto/cavium/cpt/cptvf_algs.c           |  4 ++++
 drivers/crypto/cavium/nitrox/nitrox_skcipher.c   |  6 ++++++
 drivers/crypto/ccp/ccp-crypto-aes-xts.c          |  3 +++
 drivers/crypto/ccree/cc_cipher.c                 | 11 ++++++-----
 drivers/crypto/chelsio/chcr_algo.c               |  4 ++++
 drivers/crypto/hisilicon/sec/sec_algs.c          |  4 ++++
 drivers/crypto/inside-secure/safexcel_cipher.c   |  6 ++++++
 drivers/crypto/marvell/octeontx/otx_cptvf_algs.c |  5 +++++
 drivers/crypto/qce/skcipher.c                    |  3 +++
 drivers/crypto/vmx/aes_xts.c                     |  3 +++
 22 files changed, 96 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/22 crypto: arm/aes-ce - add check for xts input length equal to zero

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

---
 arch/arm/crypto/aes-ce-glue.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/crypto/aes-ce-glue.c +6 -0
index b668c97663ec..57a9cf7fe98a 100644
@@ -452,6 +452,9 @@ static int xts_encrypt(struct skcipher_request *req)
 	struct scatterlist *src, *dst;
 	struct skcipher_walk walk;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < AES_BLOCK_SIZE)
 		return -EINVAL;
 
@@ -524,6 +527,9 @@ static int xts_decrypt(struct skcipher_request *req)
 	struct scatterlist *src, *dst;
 	struct skcipher_walk walk;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < AES_BLOCK_SIZE)
 		return -EINVAL;
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/22 crypto: arm/aes-neonbs - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

---
 arch/arm/crypto/aes-neonbs-glue.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/crypto/aes-neonbs-glue.c +3 -0
index e6fd32919c81..98ca6e6cca90 100644
@@ -339,6 +339,9 @@ static int __xts_crypt(struct skcipher_request *req, bool encrypt,
 	struct skcipher_walk walk;
 	int err;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < AES_BLOCK_SIZE)
 		return -EINVAL;
 
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/22 crypto: arm64/aes - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/crypto/aes-glue.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm64/crypto/aes-glue.c +6 -0
index 395bbf64b2ab..44c9644c74b1 100644
@@ -515,6 +515,9 @@ static int __maybe_unused xts_encrypt(struct skcipher_request *req)
 	struct scatterlist *src, *dst;
 	struct skcipher_walk walk;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < AES_BLOCK_SIZE)
 		return -EINVAL;
 
@@ -587,6 +590,9 @@ static int __maybe_unused xts_decrypt(struct skcipher_request *req)
 	struct scatterlist *src, *dst;
 	struct skcipher_walk walk;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < AES_BLOCK_SIZE)
 		return -EINVAL;
 
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/22 crypto: arm64/aes-neonbs - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/crypto/aes-neonbs-glue.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm64/crypto/aes-neonbs-glue.c +3 -0
index fb507d569922..197bf24e7dae 100644
@@ -330,6 +330,9 @@ static int __xts_crypt(struct skcipher_request *req, bool encrypt,
 	int first = 1;
 	u8 *out, *in;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < AES_BLOCK_SIZE)
 		return -EINVAL;
 
Signature · 1 line
2.17.1
#5 lore raw

PATCH 5/22 crypto: powerpc/aes-spe - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
---
 arch/powerpc/crypto/aes-spe-glue.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/powerpc/crypto/aes-spe-glue.c +6 -0
index c2b23b69d7b1..f37d8bef322b 100644
@@ -327,6 +327,9 @@ static int ppc_xts_encrypt(struct skcipher_request *req)
 	u8 b[2][AES_BLOCK_SIZE];
 	int err;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < AES_BLOCK_SIZE)
 		return -EINVAL;
 
@@ -366,6 +369,9 @@ static int ppc_xts_decrypt(struct skcipher_request *req)
 	le128 twk;
 	int err;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < AES_BLOCK_SIZE)
 		return -EINVAL;
 
Signature · 1 line
2.17.1
#6 lore raw

PATCH 6/22 crypto: s390/aes - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Heiko Carstens <[email protected]>
Cc Vasily Gorbik <[email protected]>
Cc Christian Borntraeger <[email protected]>
---
 arch/s390/crypto/aes_s390.c | 3 +++
 1 file changed, 3 insertions(+)
arch/s390/crypto/aes_s390.c +3 -0
index 73044634d342..bc8855f4b7d1 100644
@@ -437,6 +437,9 @@ static int xts_aes_crypt(struct skcipher_request *req, unsigned long modifier)
 		u8 init[16];
 	} xts_param;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < AES_BLOCK_SIZE)
 		return -EINVAL;
 
Signature · 1 line
2.17.1
#7 lore raw

PATCH 7/22 crypto: s390/paes - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Heiko Carstens <[email protected]>
Cc Vasily Gorbik <[email protected]>
Cc Christian Borntraeger <[email protected]>
---
 arch/s390/crypto/paes_s390.c | 3 +++
 1 file changed, 3 insertions(+)
arch/s390/crypto/paes_s390.c +3 -0
index f3caeb17c85b..7f0861c6f019 100644
@@ -494,6 +494,9 @@ static int xts_paes_crypt(struct skcipher_request *req, unsigned long modifier)
 		u8 init[16];
 	} xts_param;
 
+	if (!req->cryptlen)
+		return 0;
+
 	ret = skcipher_walk_virt(&walk, req, false);
 	if (ret)
 		return ret;
Signature · 1 line
2.17.1
#8 lore raw

PATCH 8/22 crypto: x86/glue_helper - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/crypto/glue_helper.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/crypto/glue_helper.c +3 -0
index d3d91a0abf88..cc5042c72910 100644
@@ -275,6 +275,9 @@ int glue_xts_req_128bit(const struct common_glue_ctx *gctx,
 	unsigned int nbytes, tail;
 	int err;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < XTS_BLOCK_SIZE)
 		return -EINVAL;
 
Signature · 1 line
2.17.1
#9 lore raw

PATCH 9/22 crypto: xts - add check for block length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

---
 crypto/xts.c | 6 ++++++
 1 file changed, 6 insertions(+)
crypto/xts.c +6 -0
index 3c3ed02c7663..7df68f52fddc 100644
@@ -263,6 +263,9 @@ static int xts_encrypt(struct skcipher_request *req)
 	struct skcipher_request *subreq = &rctx->subreq;
 	int err;
 
+	if (!req->cryptlen)
+		return 0;
+
 	err = xts_init_crypt(req, xts_encrypt_done) ?:
 	      xts_xor_tweak_pre(req, true) ?:
 	      crypto_skcipher_encrypt(subreq) ?:
@@ -280,6 +283,9 @@ static int xts_decrypt(struct skcipher_request *req)
 	struct skcipher_request *subreq = &rctx->subreq;
 	int err;
 
+	if (!req->cryptlen)
+		return 0;
+
 	err = xts_init_crypt(req, xts_decrypt_done) ?:
 	      xts_xor_tweak_pre(req, false) ?:
 	      crypto_skcipher_decrypt(subreq) ?:
Signature · 1 line
2.17.1
#10 lore raw

PATCH 10/22 crypto: atmel-aes - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Nicolas Ferre <[email protected]>
Cc Alexandre Belloni <[email protected]>
Cc Ludovic Desroches <[email protected]>
---
 drivers/crypto/atmel-aes.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/crypto/atmel-aes.c +4 -0
index a6e14491e080..af789ac73478 100644
@@ -1107,6 +1107,10 @@ static int atmel_aes_crypt(struct skcipher_request *req, unsigned long mode)
 		ctx->block_size = CFB64_BLOCK_SIZE;
 		break;
 
+	case AES_FLAGS_XTS:
+		if (!req->cryptlen)
+			return 0;
+
 	default:
 		ctx->block_size = AES_BLOCK_SIZE;
 		break;
Signature · 1 line
2.17.1
#11 lore raw

Re: [PATCH 10/22] crypto: atmel-aes - add check for xts input length equal to zero

Thank you for the patch! Perhaps something to improve:

Hi Andrei,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on cryptodev/master]
[also build test WARNING on crypto/master next-20200807] [cannot apply to powerpc/next sparc-next/master v5.8]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Andrei-Botila/crypto-add-check-for-xts-input-length-equal-to-zero/20200808-002648
base:   https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master
config: arm-defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

drivers/crypto/atmel-aes.c: In function 'atmel_aes_crypt':

>> drivers/crypto/atmel-aes.c:1111:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
    1111 |   if (!req->cryptlen)
         |      ^
   drivers/crypto/atmel-aes.c:1114:2: note: here
    1114 |  default:
         |  ^~~~~~~

vim +1111 drivers/crypto/atmel-aes.c

1085
1086 static int atmel_aes_crypt(struct skcipher_request *req, unsigned long mode)
1087 {
1088 struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
1089 struct atmel_aes_base_ctx *ctx = crypto_skcipher_ctx(skcipher);
1090 struct atmel_aes_reqctx *rctx;
1091 struct atmel_aes_dev *dd;
1092
1093 switch (mode & AES_FLAGS_OPMODE_MASK) {
1094 case AES_FLAGS_CFB8:
1095 ctx->block_size = CFB8_BLOCK_SIZE;
1096 break;
1097
1098 case AES_FLAGS_CFB16:
1099 ctx->block_size = CFB16_BLOCK_SIZE;
1100 break;
1101
1102 case AES_FLAGS_CFB32:
1103 ctx->block_size = CFB32_BLOCK_SIZE;
1104 break;
1105
1106 case AES_FLAGS_CFB64:
1107 ctx->block_size = CFB64_BLOCK_SIZE;
1108 break;
1109
1110 case AES_FLAGS_XTS:

> 1111			if (!req->cryptlen)

1112 return 0;
1113
1114 default:
1115 ctx->block_size = AES_BLOCK_SIZE;
1116 break;
1117 }
1118 ctx->is_aead = false;
1119
1120 dd = atmel_aes_find_dev(ctx);
1121 if (!dd)
1122 return -ENODEV;
1123
1124 rctx = skcipher_request_ctx(req);
1125 rctx->mode = mode;
1126
1127 if ((mode & AES_FLAGS_OPMODE_MASK) != AES_FLAGS_ECB &&
1128 !(mode & AES_FLAGS_ENCRYPT) && req->src == req->dst) {
1129 unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
1130
1131 if (req->cryptlen >= ivsize)
1132 scatterwalk_map_and_copy(rctx->lastc, req->src,
1133 req->cryptlen - ivsize,
1134 ivsize, 0);
1135 }
1136
1137 return atmel_aes_handle_queue(dd, &req->base);
1138 }
1139

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#12 lore raw

PATCH 11/22 crypto: artpec6 - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Jesper Nilsson <[email protected]>
Cc Lars Persson <[email protected]>
---
 drivers/crypto/axis/artpec6_crypto.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/crypto/axis/artpec6_crypto.c +6 -0
index 1a46eeddf082..243880c97629 100644
@@ -1090,6 +1090,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) {
@@ -1135,6 +1138,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) {
Signature · 1 line
2.17.1
#13 lore raw

PATCH 12/22 crypto: bcm - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Zhang Shengju <[email protected]>
Cc Tang Bin <[email protected]>
---
 drivers/crypto/bcm/cipher.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/crypto/bcm/cipher.c +3 -0
index 8a7fa1ae1ade..8a6f225f4db7 100644
@@ -1754,6 +1754,9 @@ static int skcipher_enqueue(struct skcipher_request *req, bool encrypt)
 	    crypto_skcipher_ctx(crypto_skcipher_reqtfm(req));
 	int err;
 
+	if (!req->cryptlen && ctx->cipher.mode == CIPHER_MODE_XTS)
+		return 0;
+
 	flow_log("%s() enc:%u\n", __func__, encrypt);
 
 	rctx->gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
Signature · 1 line
2.17.1
#14 lore raw

PATCH 13/22 crypto: cavium/cpt - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

---
 drivers/crypto/cavium/cpt/cptvf_algs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/crypto/cavium/cpt/cptvf_algs.c +4 -0
index 5af0dc2a8909..edc18c8dd571 100644
@@ -193,6 +193,7 @@ static inline void create_output_list(struct skcipher_request *req,
 static inline int cvm_enc_dec(struct skcipher_request *req, u32 enc)
 {
 	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
+	struct cvm_enc_ctx *ctx = crypto_skcipher_ctx(tfm);
 	struct cvm_req_ctx *rctx = skcipher_request_ctx(req);
 	u32 enc_iv_len = crypto_skcipher_ivsize(tfm);
 	struct fc_context *fctx = &rctx->fctx;
@@ -200,6 +201,9 @@ static inline int cvm_enc_dec(struct skcipher_request *req, u32 enc)
 	void *cdev = NULL;
 	int status;
 
+	if (!req->cryptlen && ctx->cipher_type == AES_XTS)
+		return 0;
+
 	memset(req_info, 0, sizeof(struct cpt_request_info));
 	req_info->may_sleep = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) != 0;
 	memset(fctx, 0, sizeof(struct fc_context));
Signature · 1 line
2.17.1
#15 lore raw

PATCH 14/22 crypto: cavium/nitrox - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Srikanth Jampala <[email protected]>
Cc Nagadheeraj Rottela <[email protected]>
---
 drivers/crypto/cavium/nitrox/nitrox_skcipher.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/crypto/cavium/nitrox/nitrox_skcipher.c +6 -0
index a553ac65f324..d76589ebe354 100644
@@ -249,10 +249,16 @@ static int nitrox_skcipher_crypt(struct skcipher_request *skreq, bool enc)
 	struct crypto_skcipher *cipher = crypto_skcipher_reqtfm(skreq);
 	struct nitrox_crypto_ctx *nctx = crypto_skcipher_ctx(cipher);
 	struct nitrox_kcrypt_request *nkreq = skcipher_request_ctx(skreq);
+	struct crypto_tfm *tfm = crypto_skcipher_tfm(cipher);
 	int ivsize = crypto_skcipher_ivsize(cipher);
 	struct se_crypto_request *creq;
+	const char *name;
 	int ret;
 
+	name = crypto_tfm_alg_name(tfm);
+	if (!skreq->cryptlen && flexi_cipher_type(name) == CIPHER_AES_XTS)
+		return 0;
+
 	creq = &nkreq->creq;
 	creq->flags = skreq->base.flags;
 	creq->gfp = (skreq->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
Signature · 1 line
2.17.1
#16 lore raw

PATCH 15/22 crypto: ccp - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Tom Lendacky <[email protected]>
Cc John Allen <[email protected]>
---
 drivers/crypto/ccp/ccp-crypto-aes-xts.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/crypto/ccp/ccp-crypto-aes-xts.c +3 -0
index 6849261ca47d..6a93b54d388a 100644
@@ -113,6 +113,9 @@ static int ccp_aes_xts_crypt(struct skcipher_request *req,
 	u32 unit_size;
 	int ret;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (!ctx->u.aes.key_len)
 		return -EINVAL;
 
Signature · 1 line
2.17.1
#17 lore raw

PATCH 16/22 crypto: ccree - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero. This change has implications not only for xts(aes) but also for cts(cbc(aes)) and cts(cbc(paes)).

Cc Gilad Ben-Yossef <[email protected]>
---
 drivers/crypto/ccree/cc_cipher.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/crypto/ccree/cc_cipher.c +6 -5
index 076669dc1035..112bb8b4dce6 100644
@@ -912,17 +912,18 @@ static int cc_cipher_process(struct skcipher_request *req,
 
 	/* STAT_PHASE_0: Init and sanity checks */
 
-	if (validate_data_size(ctx_p, nbytes)) {
-		dev_dbg(dev, "Unsupported data size %d.\n", nbytes);
-		rc = -EINVAL;
-		goto exit_process;
-	}
 	if (nbytes == 0) {
 		/* No data to process is valid */
 		rc = 0;
 		goto exit_process;
 	}
 
+	if (validate_data_size(ctx_p, nbytes)) {
+		dev_dbg(dev, "Unsupported data size %d.\n", nbytes);
+		rc = -EINVAL;
+		goto exit_process;
+	}
+
 	if (ctx_p->fallback_on) {
 		struct skcipher_request *subreq = skcipher_request_ctx(req);
 
Signature · 1 line
2.17.1
maintainer Acked-by on v1 16/22
#18 lore raw

Re: [PATCH 16/22] crypto: ccree - add check for xts input length equal to zero

Quoted 43 lines · Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero. This change has implications not only for xts(aes) but also for cts(cbc(aes)) and cts(cbc(paes)).

Cc Gilad Ben-Yossef <[email protected]>
---
 drivers/crypto/ccree/cc_cipher.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/crypto/ccree/cc_cipher.c +6 -6
index 076669dc1035..112bb8b4dce6 100644
@@ -912,17 +912,18 @@ static int cc_cipher_process(struct skcipher_request *req,
 
        /* STAT_PHASE_0: Init and sanity checks */
 
-       if (validate_data_size(ctx_p, nbytes)) {
-               dev_dbg(dev, "Unsupported data size %d.\n", nbytes);
-               rc = -EINVAL;
-               goto exit_process;
-       }
        if (nbytes == 0) {
                /* No data to process is valid */
                rc = 0;
                goto exit_process;
        }
 
+       if (validate_data_size(ctx_p, nbytes)) {
+               dev_dbg(dev, "Unsupported data size %d.\n", nbytes);
+               rc = -EINVAL;
+               goto exit_process;
+       }
+
        if (ctx_p->fallback_on) {
                struct skcipher_request *subreq = skcipher_request_ctx(req);
 
--
Quoted 2 lines

2.17.1

Thanks,
Gilad

Signature · 4 lines
Gilad Ben-Yossef
Chief Coffee Drinker

values of β will give rise to dom!
#19 lore raw

PATCH 17/22 crypto: chelsio - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Ayush Sawal <[email protected]>
Cc Vinay Kumar Yadav <[email protected]>
Cc Rohit Maheshwari <[email protected]>
---
 drivers/crypto/chelsio/chcr_algo.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/crypto/chelsio/chcr_algo.c +4 -0
index 13b908ea4873..e9746580870a 100644
@@ -1372,8 +1372,12 @@ static int chcr_aes_encrypt(struct skcipher_request *req)
 	int err;
 	struct uld_ctx *u_ctx = ULD_CTX(c_ctx(tfm));
 	struct chcr_context *ctx = c_ctx(tfm);
+	int subtype = get_cryptoalg_subtype(tfm);
 	unsigned int cpu;
 
+	if (!req->cryptlen && subtype == CRYPTO_ALG_SUB_TYPE_XTS)
+		return 0;
+
 	cpu = get_cpu();
 	reqctx->txqidx = cpu % ctx->ntxq;
 	reqctx->rxqidx = cpu % ctx->nrxq;
Signature · 1 line
2.17.1
#20 lore raw

PATCH 18/22 crypto: hisilicon/sec - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

---
 drivers/crypto/hisilicon/sec/sec_algs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/crypto/hisilicon/sec/sec_algs.c +4 -0
index 8ca945ac297e..419ec4f23164 100644
@@ -723,6 +723,10 @@ static int sec_alg_skcipher_crypto(struct skcipher_request *skreq,
 	bool split = skreq->src != skreq->dst;
 	gfp_t gfp = skreq->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC;
 
+	if (!skreq->cryptlen && (ctx->cipher_alg == SEC_C_AES_XTS_128 ||
+				 ctx->cipher_alg == SEC_C_AES_XTS_256))
+		return 0;
+
 	mutex_init(&sec_req->lock);
 	sec_req->req_base = &skreq->base;
 	sec_req->err = 0;
Signature · 1 line
2.17.1
#21 lore raw

PATCH 19/22 crypto: inside-secure - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

---
 drivers/crypto/inside-secure/safexcel_cipher.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/crypto/inside-secure/safexcel_cipher.c +6 -0
index 1ac3253b7903..03d06556ea98 100644
@@ -2533,6 +2533,9 @@ static int safexcel_skcipher_aes_xts_cra_init(struct crypto_tfm *tfm)
 
 static int safexcel_encrypt_xts(struct skcipher_request *req)
 {
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < XTS_BLOCK_SIZE)
 		return -EINVAL;
 	return safexcel_queue_req(&req->base, skcipher_request_ctx(req),
@@ -2541,6 +2544,9 @@ static int safexcel_encrypt_xts(struct skcipher_request *req)
 
 static int safexcel_decrypt_xts(struct skcipher_request *req)
 {
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < XTS_BLOCK_SIZE)
 		return -EINVAL;
 	return safexcel_queue_req(&req->base, skcipher_request_ctx(req),
Signature · 1 line
2.17.1
#22 lore raw

RE: [PATCH 19/22] crypto: inside-secure - add check for xts input length equal to zero

Quoted 46 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Andrei Botila
Sent: Friday, August 7, 2020 6:20 PM
To: Herbert Xu <[email protected]>; David S. Miller <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Andrei Botila <[email protected]>; Antoine Tenart <[email protected]>
Subject: [PATCH 19/22] crypto: inside-secure - add check for xts input length equal to zero

<<< External Email >>>
From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

---
 drivers/crypto/inside-secure/safexcel_cipher.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/crypto/inside-secure/safexcel_cipher.c +6 -1
index 1ac3253b7903..03d06556ea98 100644
@@ -2533,6 +2533,9 @@ static int safexcel_skcipher_aes_xts_cra_init(struct crypto_tfm *tfm)
 
 static int safexcel_encrypt_xts(struct skcipher_request *req)
 {
+if (!req->cryptlen)
+return 0;
+
 if (req->cryptlen < XTS_BLOCK_SIZE)
 return -EINVAL;
 return safexcel_queue_req(&req->base, skcipher_request_ctx(req),
@@ -2541,6 +2544,9 @@ static int safexcel_encrypt_xts(struct skcipher_request *req)
 
 static int safexcel_decrypt_xts(struct skcipher_request *req)
 {
+if (!req->cryptlen)
+return 0;
+
 if (req->cryptlen < XTS_BLOCK_SIZE)
 return -EINVAL;
 return safexcel_queue_req(&req->base, skcipher_request_ctx(req),
--
Quoted 1 line

2.17.1

With all due respect, but this makes no sense.

For XTS, any length below 16 is illegal, as applying CTS in order to handle non-cipher block multiples (16 bytes in case of AES) requires _more_ data than 1 cipher block.

There is no benefit to explicitly check for zero length if there is already a check for less-than-16. That's just wasting CPU cycles and a branch predictor entry, for no benefit whatsoever. (except for academic "alignment with other ciphers").

XTS has very specific use cases. No one in their right mind would call it for a situation where it can't be applied in the first place, e.g. anything < 16 bytes.

Regards,
Pascal van Leeuwen
Silicon IP Architect Multi-Protocol Engines, Rambus Security Rambus ROTW Holding BV
+31-73 6581953

Note: The Inside Secure/Verimatrix Silicon IP team was recently acquired by Rambus. Please be so kind to update your e-mail address book with my new e-mail address.

** This message and any attachments are for the sole use of the intended recipient(s). It may contain information that is confidential and privileged. If you are not the intended recipient of this message, you are prohibited from printing, copying, forwarding or saving it. Please delete the message and attachments and notify the sender immediately. **

Rambus Inc.<http://www.rambus.com>

maintainer
#23 lore raw

Re: [PATCH 19/22] crypto: inside-secure - add check for xts input length equal to zero

Quoted 2 lines · Pascal

With all due respect, but this makes no sense.

I agree. This is a lot of churn for no gain.

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
#24 lore raw

Re: [PATCH 19/22] crypto: inside-secure - add check for xts input length equal to zero

Quoted 6 lines · Herbert Xu
Quoted 2 lines · Pascal

With all due respect, but this makes no sense.

I agree. This is a lot of churn for no gain.

I would say the gain is that all skcipher algorithms would behave the same when input length equals zero - i.e. treat the request as a no-op.

We can't say "no input" has any meaning to the other skcipher algorithms, but the convention is to accept this case and just return 0. I don't see why XTS has to be handled differently.

Thanks,
Horia

#25 lore raw

Re: [PATCH 19/22] crypto: inside-secure - add check for xts input length equal to zero

Quoted 5 lines · Horia Geantă
Quoted 4 lines · Herbert Xu
Quoted 2 lines · Pascal

With all due respect, but this makes no sense.

Quoted 9 lines
Quoted 2 lines

I agree. This is a lot of churn for no gain.

I would say the gain is that all skcipher algorithms would behave the same when input length equals zero - i.e. treat the request as a no-op.

We can't say "no input" has any meaning to the other skcipher algorithms, but the convention is to accept this case and just return 0. I don't see why XTS has to be handled differently.

CTS also rejects empty inputs.

The rule it follows is just that all input lengths >= blocksize are allowed. Input lengths < blocksize aren't allowed.

- Eric

#26 lore raw

Re: [PATCH 19/22] crypto: inside-secure - add check for xts input length equal to zero

Quoted 16 lines · Eric Biggers
Quoted 5 lines · Horia Geantă
Quoted 4 lines · Herbert Xu
Quoted 2 lines · Pascal

With all due respect, but this makes no sense.

Quoted 9 lines
Quoted 2 lines

I agree. This is a lot of churn for no gain.

I would say the gain is that all skcipher algorithms would behave the same when input length equals zero - i.e. treat the request as a no-op.

We can't say "no input" has any meaning to the other skcipher algorithms, but the convention is to accept this case and just return 0. I don't see why XTS has to be handled differently.

Quoted 5 lines

CTS also rejects empty inputs.

The rule it follows is just that all input lengths >= blocksize are allowed. Input lengths < blocksize aren't allowed.

Indeed, thanks.

What about, for example, CBC?
AFAICT cbc(aes) with input length = 0 is valid.

Same for CTR (with the note that blocksize = 1) and several other algorithms mentioned in the cover letter.

What's the rule in these cases?

Thanks,
Horia

maintainer
#27 lore raw

Re: [PATCH 19/22] crypto: inside-secure - add check for xts input length equal to zero

Quoted 3 lines · Horia Geantă

What about, for example, CBC?
AFAICT cbc(aes) with input length = 0 is valid.

That's just because CBC accepts any input which is a multiple of blocksize.

Quoted 2 lines

Same for CTR (with the note that blocksize = 1) and several other algorithms mentioned in the cover letter.

CTR accepts any input size.

Quoted 1 line

What's the rule in these cases?

What input size is accepted depends on the algorithm.

Cheers,

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
#28 lore raw

RE: [PATCH 19/22] crypto: inside-secure - add check for xts input length equal to zero

In reply to Horia Geantă
Quoted 11 lines

-----Original Message-----
From: Horia Geantă <[email protected]>
Sent: Monday, August 10, 2020 4:34 PM
To: Herbert Xu <[email protected]>; Van Leeuwen, Pascal <[email protected]>
Cc: Andrei Botila (OSS) <[email protected]>; David S. Miller <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Andrei Botila <[email protected]>; Antoine Tenart <[email protected]>
Subject: Re: [PATCH 19/22] crypto: inside-secure - add check for xts input length equal to zero

<<< External Email >>>
On 8/10/2020 4:45 PM, Herbert Xu wrote:

Quoted 9 lines
Quoted 6 lines · Pascal
Quoted 2 lines

With all due respect, but this makes no sense.

I agree. This is a lot of churn for no gain.

I would say the gain is that all skcipher algorithms would behave the same when input length equals zero - i.e. treat the request as a no-op.

XTS already behaves differently because it can accept any byte amount as long as it is not in the range 0 -16. So far, you got an EINVAL error for lengths < 16. The special exception on top of that for length 0 does not improve anything.

Treating a request of length 0 as a no-op is not a useful feature here, as there is no use case where that would make sense. XTS encrypts blocks (usually disk sectors), and cannot be chained. So an attempt to encrypt a zero length block is most certainly some kind of error (e.g. trying to use XTS for something it was not designed to do - big security mistake!).

Quoted 4 lines

We can't say "no input" has any meaning to the other skcipher algorithms, but the convention is to accept this case and just return 0. I don't see why XTS has to be handled differently.

I don't see why you would blindly follow some historical convention ... unless maybe there was some existing real use case that would benefit?

BTW: for generic ciphers I could think of some use cases where the zero length request being a no-op makes sense if the application does not bother to check how much data it has gathered to process (which may be nothing), but I can't see how this could apply to XTS, being block-based.

Quoted 2 lines

Thanks,
Horia

Regards,
Pascal van Leeuwen
Silicon IP Architect Multi-Protocol Engines, Rambus Security Rambus ROTW Holding BV
+31-73 6581953

Note: The Inside Secure/Verimatrix Silicon IP team was recently acquired by Rambus. Please be so kind to update your e-mail address book with my new e-mail address.

** This message and any attachments are for the sole use of the intended recipient(s). It may contain information that is confidential and privileged. If you are not the intended recipient of this message, you are prohibited from printing, copying, forwarding or saving it. Please delete the message and attachments and notify the sender immediately. **

Rambus Inc.<http://www.rambus.com>

#29 lore raw

PATCH 20/22 crypto: octeontx - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc Boris Brezillon <[email protected]>
Cc Arnaud Ebalard <[email protected]>
Cc Srujana Challa <[email protected]>
---
 drivers/crypto/marvell/octeontx/otx_cptvf_algs.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/crypto/marvell/octeontx/otx_cptvf_algs.c +5 -0
index 90bb31329d4b..ec13bc3f1766 100644
@@ -340,11 +340,16 @@ static inline int cpt_enc_dec(struct skcipher_request *req, u32 enc)
 {
 	struct crypto_skcipher *stfm = crypto_skcipher_reqtfm(req);
 	struct otx_cpt_req_ctx *rctx = skcipher_request_ctx(req);
+	struct crypto_tfm *tfm = crypto_skcipher_tfm(stfm);
+	struct otx_cpt_enc_ctx *ctx = crypto_tfm_ctx(tfm);
 	struct otx_cpt_req_info *req_info = &rctx->cpt_req;
 	u32 enc_iv_len = crypto_skcipher_ivsize(stfm);
 	struct pci_dev *pdev;
 	int status, cpu_num;
 
+	if (!req->cryptlen && ctx->cipher_type == OTX_CPT_AES_XTS)
+		return 0;
+
 	/* Validate that request doesn't exceed maximum CPT supported size */
 	if (req->cryptlen > OTX_CPT_MAX_REQ_SIZE)
 		return -E2BIG;
Signature · 1 line
2.17.1
#30 lore raw

PATCH 21/22 crypto: qce - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

---
 drivers/crypto/qce/skcipher.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/crypto/qce/skcipher.c +3 -0
index 5630c5addd28..887fd4dc9b43 100644
@@ -223,6 +223,9 @@ static int qce_skcipher_crypt(struct skcipher_request *req, int encrypt)
 	int keylen;
 	int ret;
 
+	if (!req->cryptlen && IS_XTS(rctx->flags))
+		return 0;
+
 	rctx->flags = tmpl->alg_flags;
 	rctx->flags |= encrypt ? QCE_ENCRYPT : QCE_DECRYPT;
 	keylen = IS_XTS(rctx->flags) ? ctx->enc_keylen >> 1 : ctx->enc_keylen;
Signature · 1 line
2.17.1
Reviewed-by on v1 21/22
#31 lore raw

Re: [PATCH 21/22] crypto: qce - add check for xts input length equal to zero

Hi,

Thanks for the patch!

Quoted 9 lines · Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

---
 drivers/crypto/qce/skcipher.c | 3 +++
 1 file changed, 3 insertions(+)
Quoted 16 lines
drivers/crypto/qce/skcipher.c +3 -0
index 5630c5addd28..887fd4dc9b43 100644
@@ -223,6 +223,9 @@ static int qce_skcipher_crypt(struct skcipher_request *req, int encrypt)
 	int keylen;
 	int ret;
 
+	if (!req->cryptlen && IS_XTS(rctx->flags))
+		return 0;
+
 	rctx->flags = tmpl->alg_flags;
 	rctx->flags |= encrypt ? QCE_ENCRYPT : QCE_DECRYPT;
 	keylen = IS_XTS(rctx->flags) ? ctx->enc_keylen >> 1 : ctx->enc_keylen;
Signature · 2 lines
regards,
Stan
#32 lore raw

PATCH 22/22 crypto: vmx - add check for xts input length equal to zero

In reply to Andrei Botila

From: Andrei Botila <[email protected]>

Standardize the way input lengths equal to 0 are handled in all skcipher algorithms. All the algorithms return 0 for input lengths equal to zero.

Cc "Breno Leitão" <[email protected]>
Cc Nayna Jain <[email protected]>
Cc Paulo Flabiano Smorigo <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
---
 drivers/crypto/vmx/aes_xts.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/crypto/vmx/aes_xts.c +3 -0
index 9fee1b1532a4..33107c9e2656 100644
@@ -84,6 +84,9 @@ static int p8_aes_xts_crypt(struct skcipher_request *req, int enc)
 	u8 tweak[AES_BLOCK_SIZE];
 	int ret;
 
+	if (!req->cryptlen)
+		return 0;
+
 	if (req->cryptlen < AES_BLOCK_SIZE)
 		return -EINVAL;
 
Signature · 1 line
2.17.1