Skip to content

Commit dcf903d

Browse files
committed
Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto fixes from Herbert Xu: - fix new compiler warnings in cavium - set post-op IV properly in caam (this fixes chaining) - fix potential use-after-free in atmel in case of EBUSY - fix sleeping in softirq path in chcr - disable buggy sha1-avx2 driver (may overread and page fault) - fix use-after-free on signals in caam * 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: crypto: cavium - make several functions static crypto: chcr - Avoid algo allocation in softirq. crypto: caam - properly set IV after {en,de}crypt crypto: atmel - only treat EBUSY as transient if backlog crypto: af_alg - Avoid sock_graft call warning crypto: caam - fix signals handling crypto: sha1-ssse3 - Disable avx2
2 parents 96d0d83 + b8fc339 commit dcf903d

File tree

9 files changed

+45
-19
lines changed

9 files changed

+45
-19
lines changed

arch/x86/crypto/sha1_ssse3_glue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ asmlinkage void sha1_transform_avx2(u32 *digest, const char *data,
201201

202202
static bool avx2_usable(void)
203203
{
204-
if (avx_usable() && boot_cpu_has(X86_FEATURE_AVX2)
204+
if (false && avx_usable() && boot_cpu_has(X86_FEATURE_AVX2)
205205
&& boot_cpu_has(X86_FEATURE_BMI1)
206206
&& boot_cpu_has(X86_FEATURE_BMI2))
207207
return true;

crypto/af_alg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock, bool kern)
287287
goto unlock;
288288

289289
sock_init_data(newsock, sk2);
290-
sock_graft(sk2, newsock);
290+
security_sock_graft(sk2, newsock);
291291
security_sk_clone(sk, sk2);
292292

293293
err = type->accept(ask->private, sk2);

drivers/crypto/atmel-sha.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,9 @@ static int atmel_sha_finup(struct ahash_request *req)
12041204
ctx->flags |= SHA_FLAGS_FINUP;
12051205

12061206
err1 = atmel_sha_update(req);
1207-
if (err1 == -EINPROGRESS || err1 == -EBUSY)
1207+
if (err1 == -EINPROGRESS ||
1208+
(err1 == -EBUSY && (ahash_request_flags(req) &
1209+
CRYPTO_TFM_REQ_MAY_BACKLOG)))
12081210
return err1;
12091211

12101212
/*

drivers/crypto/caam/caamalg.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,10 +882,10 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
882882
{
883883
struct ablkcipher_request *req = context;
884884
struct ablkcipher_edesc *edesc;
885-
#ifdef DEBUG
886885
struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
887886
int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
888887

888+
#ifdef DEBUG
889889
dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
890890
#endif
891891

@@ -904,6 +904,14 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
904904
#endif
905905

906906
ablkcipher_unmap(jrdev, edesc, req);
907+
908+
/*
909+
* The crypto API expects us to set the IV (req->info) to the last
910+
* ciphertext block. This is used e.g. by the CTS mode.
911+
*/
912+
scatterwalk_map_and_copy(req->info, req->dst, req->nbytes - ivsize,
913+
ivsize, 0);
914+
907915
kfree(edesc);
908916

909917
ablkcipher_request_complete(req, err);
@@ -914,10 +922,10 @@ static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
914922
{
915923
struct ablkcipher_request *req = context;
916924
struct ablkcipher_edesc *edesc;
917-
#ifdef DEBUG
918925
struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
919926
int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
920927

928+
#ifdef DEBUG
921929
dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
922930
#endif
923931

@@ -935,6 +943,14 @@ static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
935943
#endif
936944

937945
ablkcipher_unmap(jrdev, edesc, req);
946+
947+
/*
948+
* The crypto API expects us to set the IV (req->info) to the last
949+
* ciphertext block.
950+
*/
951+
scatterwalk_map_and_copy(req->info, req->src, req->nbytes - ivsize,
952+
ivsize, 0);
953+
938954
kfree(edesc);
939955

940956
ablkcipher_request_complete(req, err);

drivers/crypto/caam/caamhash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, const u8 *key_in,
396396
ret = caam_jr_enqueue(jrdev, desc, split_key_done, &result);
397397
if (!ret) {
398398
/* in progress */
399-
wait_for_completion_interruptible(&result.completion);
399+
wait_for_completion(&result.completion);
400400
ret = result.err;
401401
#ifdef DEBUG
402402
print_hex_dump(KERN_ERR,

drivers/crypto/caam/key_gen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int gen_split_key(struct device *jrdev, u8 *key_out,
149149
ret = caam_jr_enqueue(jrdev, desc, split_key_done, &result);
150150
if (!ret) {
151151
/* in progress */
152-
wait_for_completion_interruptible(&result.completion);
152+
wait_for_completion(&result.completion);
153153
ret = result.err;
154154
#ifdef DEBUG
155155
print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ",

drivers/crypto/cavium/cpt/cptvf_algs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,17 @@ static inline int cvm_enc_dec(struct ablkcipher_request *req, u32 enc)
222222
return -EINPROGRESS;
223223
}
224224

225-
int cvm_encrypt(struct ablkcipher_request *req)
225+
static int cvm_encrypt(struct ablkcipher_request *req)
226226
{
227227
return cvm_enc_dec(req, true);
228228
}
229229

230-
int cvm_decrypt(struct ablkcipher_request *req)
230+
static int cvm_decrypt(struct ablkcipher_request *req)
231231
{
232232
return cvm_enc_dec(req, false);
233233
}
234234

235-
int cvm_xts_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
235+
static int cvm_xts_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
236236
u32 keylen)
237237
{
238238
struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
@@ -336,7 +336,7 @@ static int cvm_ecb_des3_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
336336
return cvm_setkey(cipher, key, keylen, DES3_ECB);
337337
}
338338

339-
int cvm_enc_dec_init(struct crypto_tfm *tfm)
339+
static int cvm_enc_dec_init(struct crypto_tfm *tfm)
340340
{
341341
struct cvm_enc_ctx *ctx = crypto_tfm_ctx(tfm);
342342

drivers/crypto/chelsio/chcr_algo.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -898,26 +898,20 @@ static int chcr_update_tweak(struct ablkcipher_request *req, u8 *iv)
898898
u8 *key;
899899
unsigned int keylen;
900900

901-
cipher = crypto_alloc_cipher("aes-generic", 0, 0);
901+
cipher = ablkctx->aes_generic;
902902
memcpy(iv, req->info, AES_BLOCK_SIZE);
903903

904-
if (IS_ERR(cipher)) {
905-
ret = -ENOMEM;
906-
goto out;
907-
}
908904
keylen = ablkctx->enckey_len / 2;
909905
key = ablkctx->key + keylen;
910906
ret = crypto_cipher_setkey(cipher, key, keylen);
911907
if (ret)
912-
goto out1;
908+
goto out;
913909

914910
crypto_cipher_encrypt_one(cipher, iv, iv);
915911
for (i = 0; i < (reqctx->processed / AES_BLOCK_SIZE); i++)
916912
gf128mul_x_ble((le128 *)iv, (le128 *)iv);
917913

918914
crypto_cipher_decrypt_one(cipher, iv, iv);
919-
out1:
920-
crypto_free_cipher(cipher);
921915
out:
922916
return ret;
923917
}
@@ -1261,6 +1255,17 @@ static int chcr_cra_init(struct crypto_tfm *tfm)
12611255
pr_err("failed to allocate fallback for %s\n", alg->cra_name);
12621256
return PTR_ERR(ablkctx->sw_cipher);
12631257
}
1258+
1259+
if (get_cryptoalg_subtype(tfm) == CRYPTO_ALG_SUB_TYPE_XTS) {
1260+
/* To update tweak*/
1261+
ablkctx->aes_generic = crypto_alloc_cipher("aes-generic", 0, 0);
1262+
if (IS_ERR(ablkctx->aes_generic)) {
1263+
pr_err("failed to allocate aes cipher for tweak\n");
1264+
return PTR_ERR(ablkctx->aes_generic);
1265+
}
1266+
} else
1267+
ablkctx->aes_generic = NULL;
1268+
12641269
tfm->crt_ablkcipher.reqsize = sizeof(struct chcr_blkcipher_req_ctx);
12651270
return chcr_device_init(crypto_tfm_ctx(tfm));
12661271
}
@@ -1291,6 +1296,8 @@ static void chcr_cra_exit(struct crypto_tfm *tfm)
12911296
struct ablk_ctx *ablkctx = ABLK_CTX(ctx);
12921297

12931298
crypto_free_skcipher(ablkctx->sw_cipher);
1299+
if (ablkctx->aes_generic)
1300+
crypto_free_cipher(ablkctx->aes_generic);
12941301
}
12951302

12961303
static int get_alg_config(struct algo_param *params,

drivers/crypto/chelsio/chcr_crypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155

156156
struct ablk_ctx {
157157
struct crypto_skcipher *sw_cipher;
158+
struct crypto_cipher *aes_generic;
158159
__be32 key_ctx_hdr;
159160
unsigned int enckey_len;
160161
unsigned char ciph_mode;

0 commit comments

Comments
 (0)