aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/ccp
diff options
context:
space:
mode:
authorTom Lendacky <thomas.lendacky@amd.com>2016-05-20 18:33:03 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2016-05-25 06:33:47 -0400
commitab6a11a7c8ef47f996974dd3c648c2c0b1a36ab1 (patch)
tree84aa3f31e7291587899264a30cbce7169a0af18c /drivers/crypto/ccp
parentbad6a185b4d6f81d0ed2b6e4c16307969f160b95 (diff)
crypto: ccp - Fix AES XTS error for request sizes above 4096
The ccp-crypto module for AES XTS support has a bug that can allow requests greater than 4096 bytes in size to be passed to the CCP hardware. The CCP hardware does not support request sizes larger than 4096, resulting in incorrect output. The request should actually be handled by the fallback mechanism instantiated by the ccp-crypto module. Add a check to insure the request size is less than or equal to the maximum supported size and use the fallback mechanism if it is not. Cc: <stable@vger.kernel.org> # 3.14.x- Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/ccp')
-rw-r--r--drivers/crypto/ccp/ccp-crypto-aes-xts.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/drivers/crypto/ccp/ccp-crypto-aes-xts.c b/drivers/crypto/ccp/ccp-crypto-aes-xts.c
index 52c7395cb8d8..0d0d4529ee36 100644
--- a/drivers/crypto/ccp/ccp-crypto-aes-xts.c
+++ b/drivers/crypto/ccp/ccp-crypto-aes-xts.c
@@ -122,6 +122,7 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req,
122 struct ccp_ctx *ctx = crypto_tfm_ctx(req->base.tfm); 122 struct ccp_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
123 struct ccp_aes_req_ctx *rctx = ablkcipher_request_ctx(req); 123 struct ccp_aes_req_ctx *rctx = ablkcipher_request_ctx(req);
124 unsigned int unit; 124 unsigned int unit;
125 u32 unit_size;
125 int ret; 126 int ret;
126 127
127 if (!ctx->u.aes.key_len) 128 if (!ctx->u.aes.key_len)
@@ -133,11 +134,17 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req,
133 if (!req->info) 134 if (!req->info)
134 return -EINVAL; 135 return -EINVAL;
135 136
136 for (unit = 0; unit < ARRAY_SIZE(unit_size_map); unit++) 137 unit_size = CCP_XTS_AES_UNIT_SIZE__LAST;
137 if (!(req->nbytes & (unit_size_map[unit].size - 1))) 138 if (req->nbytes <= unit_size_map[0].size) {
138 break; 139 for (unit = 0; unit < ARRAY_SIZE(unit_size_map); unit++) {
140 if (!(req->nbytes & (unit_size_map[unit].size - 1))) {
141 unit_size = unit_size_map[unit].value;
142 break;
143 }
144 }
145 }
139 146
140 if ((unit_size_map[unit].value == CCP_XTS_AES_UNIT_SIZE__LAST) || 147 if ((unit_size == CCP_XTS_AES_UNIT_SIZE__LAST) ||
141 (ctx->u.aes.key_len != AES_KEYSIZE_128)) { 148 (ctx->u.aes.key_len != AES_KEYSIZE_128)) {
142 /* Use the fallback to process the request for any 149 /* Use the fallback to process the request for any
143 * unsupported unit sizes or key sizes 150 * unsupported unit sizes or key sizes
@@ -158,7 +165,7 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req,
158 rctx->cmd.engine = CCP_ENGINE_XTS_AES_128; 165 rctx->cmd.engine = CCP_ENGINE_XTS_AES_128;
159 rctx->cmd.u.xts.action = (encrypt) ? CCP_AES_ACTION_ENCRYPT 166 rctx->cmd.u.xts.action = (encrypt) ? CCP_AES_ACTION_ENCRYPT
160 : CCP_AES_ACTION_DECRYPT; 167 : CCP_AES_ACTION_DECRYPT;
161 rctx->cmd.u.xts.unit_size = unit_size_map[unit].value; 168 rctx->cmd.u.xts.unit_size = unit_size;
162 rctx->cmd.u.xts.key = &ctx->u.aes.key_sg; 169 rctx->cmd.u.xts.key = &ctx->u.aes.key_sg;
163 rctx->cmd.u.xts.key_len = ctx->u.aes.key_len; 170 rctx->cmd.u.xts.key_len = ctx->u.aes.key_len;
164 rctx->cmd.u.xts.iv = &rctx->iv_sg; 171 rctx->cmd.u.xts.iv = &rctx->iv_sg;