Skip to content

Commit c62f4b8

Browse files
committed
Merge tag 'v6.15-p4' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto fixes from Herbert Xu: - Disable ahash request chaining as it causes problems with the sa2ul driver - Fix a couple of bugs in the new scomp stream freeing code - Fix an old caam refcount underflow that is possibly showing up now because of the new parallel self-tests - Fix regression in the tegra driver * tag 'v6.15-p4' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: crypto: ahash - Disable request chaining crypto: scomp - Fix wild memory accesses in scomp_free_streams crypto: caam/qi - Fix drv_ctx refcount bug crypto: scomp - Fix null-pointer deref when freeing streams crypto: tegra - Fix IV usage for AES ECB
2 parents 1a1d569 + b2e689b commit c62f4b8

File tree

6 files changed

+18
-87
lines changed

6 files changed

+18
-87
lines changed

crypto/ahash.c

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -315,16 +315,7 @@ EXPORT_SYMBOL_GPL(crypto_ahash_setkey);
315315

316316
static bool ahash_request_hasvirt(struct ahash_request *req)
317317
{
318-
struct ahash_request *r2;
319-
320-
if (ahash_request_isvirt(req))
321-
return true;
322-
323-
list_for_each_entry(r2, &req->base.list, base.list)
324-
if (ahash_request_isvirt(r2))
325-
return true;
326-
327-
return false;
318+
return ahash_request_isvirt(req);
328319
}
329320

330321
static int ahash_reqchain_virt(struct ahash_save_req_state *state,
@@ -472,7 +463,6 @@ static int ahash_do_req_chain(struct ahash_request *req,
472463
bool update = op == crypto_ahash_alg(tfm)->update;
473464
struct ahash_save_req_state *state;
474465
struct ahash_save_req_state state0;
475-
struct ahash_request *r2;
476466
u8 *page = NULL;
477467
int err;
478468

@@ -509,7 +499,6 @@ static int ahash_do_req_chain(struct ahash_request *req,
509499
state->offset = 0;
510500
state->nbytes = 0;
511501
INIT_LIST_HEAD(&state->head);
512-
list_splice_init(&req->base.list, &state->head);
513502

514503
if (page)
515504
sg_init_one(&state->sg, page, PAGE_SIZE);
@@ -540,9 +529,6 @@ static int ahash_do_req_chain(struct ahash_request *req,
540529

541530
out_set_chain:
542531
req->base.err = err;
543-
list_for_each_entry(r2, &req->base.list, base.list)
544-
r2->base.err = err;
545-
546532
return err;
547533
}
548534

@@ -551,19 +537,10 @@ int crypto_ahash_init(struct ahash_request *req)
551537
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
552538

553539
if (likely(tfm->using_shash)) {
554-
struct ahash_request *r2;
555540
int err;
556541

557542
err = crypto_shash_init(prepare_shash_desc(req, tfm));
558543
req->base.err = err;
559-
560-
list_for_each_entry(r2, &req->base.list, base.list) {
561-
struct shash_desc *desc;
562-
563-
desc = prepare_shash_desc(r2, tfm);
564-
r2->base.err = crypto_shash_init(desc);
565-
}
566-
567544
return err;
568545
}
569546

@@ -620,19 +597,10 @@ int crypto_ahash_update(struct ahash_request *req)
620597
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
621598

622599
if (likely(tfm->using_shash)) {
623-
struct ahash_request *r2;
624600
int err;
625601

626602
err = shash_ahash_update(req, ahash_request_ctx(req));
627603
req->base.err = err;
628-
629-
list_for_each_entry(r2, &req->base.list, base.list) {
630-
struct shash_desc *desc;
631-
632-
desc = ahash_request_ctx(r2);
633-
r2->base.err = shash_ahash_update(r2, desc);
634-
}
635-
636604
return err;
637605
}
638606

@@ -645,19 +613,10 @@ int crypto_ahash_final(struct ahash_request *req)
645613
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
646614

647615
if (likely(tfm->using_shash)) {
648-
struct ahash_request *r2;
649616
int err;
650617

651618
err = crypto_shash_final(ahash_request_ctx(req), req->result);
652619
req->base.err = err;
653-
654-
list_for_each_entry(r2, &req->base.list, base.list) {
655-
struct shash_desc *desc;
656-
657-
desc = ahash_request_ctx(r2);
658-
r2->base.err = crypto_shash_final(desc, r2->result);
659-
}
660-
661620
return err;
662621
}
663622

@@ -670,19 +629,10 @@ int crypto_ahash_finup(struct ahash_request *req)
670629
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
671630

672631
if (likely(tfm->using_shash)) {
673-
struct ahash_request *r2;
674632
int err;
675633

676634
err = shash_ahash_finup(req, ahash_request_ctx(req));
677635
req->base.err = err;
678-
679-
list_for_each_entry(r2, &req->base.list, base.list) {
680-
struct shash_desc *desc;
681-
682-
desc = ahash_request_ctx(r2);
683-
r2->base.err = shash_ahash_finup(r2, desc);
684-
}
685-
686636
return err;
687637
}
688638

@@ -757,19 +707,10 @@ int crypto_ahash_digest(struct ahash_request *req)
757707
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
758708

759709
if (likely(tfm->using_shash)) {
760-
struct ahash_request *r2;
761710
int err;
762711

763712
err = shash_ahash_digest(req, prepare_shash_desc(req, tfm));
764713
req->base.err = err;
765-
766-
list_for_each_entry(r2, &req->base.list, base.list) {
767-
struct shash_desc *desc;
768-
769-
desc = prepare_shash_desc(r2, tfm);
770-
r2->base.err = shash_ahash_digest(r2, desc);
771-
}
772-
773714
return err;
774715
}
775716

@@ -1133,20 +1074,5 @@ int ahash_register_instance(struct crypto_template *tmpl,
11331074
}
11341075
EXPORT_SYMBOL_GPL(ahash_register_instance);
11351076

1136-
void ahash_request_free(struct ahash_request *req)
1137-
{
1138-
struct ahash_request *tmp;
1139-
struct ahash_request *r2;
1140-
1141-
if (unlikely(!req))
1142-
return;
1143-
1144-
list_for_each_entry_safe(r2, tmp, &req->base.list, base.list)
1145-
kfree_sensitive(r2);
1146-
1147-
kfree_sensitive(req);
1148-
}
1149-
EXPORT_SYMBOL_GPL(ahash_request_free);
1150-
11511077
MODULE_LICENSE("GPL");
11521078
MODULE_DESCRIPTION("Asynchronous cryptographic hash type");

crypto/scompress.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,14 @@ static void scomp_free_streams(struct scomp_alg *alg)
111111
struct crypto_acomp_stream __percpu *stream = alg->stream;
112112
int i;
113113

114+
alg->stream = NULL;
115+
if (!stream)
116+
return;
117+
114118
for_each_possible_cpu(i) {
115119
struct crypto_acomp_stream *ps = per_cpu_ptr(stream, i);
116120

117-
if (!ps->ctx)
121+
if (IS_ERR_OR_NULL(ps->ctx))
118122
break;
119123

120124
alg->free_ctx(ps->ctx);
@@ -132,6 +136,8 @@ static int scomp_alloc_streams(struct scomp_alg *alg)
132136
if (!stream)
133137
return -ENOMEM;
134138

139+
alg->stream = stream;
140+
135141
for_each_possible_cpu(i) {
136142
struct crypto_acomp_stream *ps = per_cpu_ptr(stream, i);
137143

@@ -143,8 +149,6 @@ static int scomp_alloc_streams(struct scomp_alg *alg)
143149

144150
spin_lock_init(&ps->lock);
145151
}
146-
147-
alg->stream = stream;
148152
return 0;
149153
}
150154

drivers/crypto/caam/qi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ int caam_qi_enqueue(struct device *qidev, struct caam_drv_req *req)
122122
qm_fd_addr_set64(&fd, addr);
123123

124124
do {
125+
refcount_inc(&req->drv_ctx->refcnt);
125126
ret = qman_enqueue(req->drv_ctx->req_fq, &fd);
126-
if (likely(!ret)) {
127-
refcount_inc(&req->drv_ctx->refcnt);
127+
if (likely(!ret))
128128
return 0;
129-
}
130129

130+
refcount_dec(&req->drv_ctx->refcnt);
131131
if (ret != -EBUSY)
132132
break;
133133
num_retries++;

drivers/crypto/tegra/tegra-se-aes.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static int tegra_aes_do_one_req(struct crypto_engine *engine, void *areq)
269269
unsigned int cmdlen, key1_id, key2_id;
270270
int ret;
271271

272-
rctx->iv = (u32 *)req->iv;
272+
rctx->iv = (ctx->alg == SE_ALG_ECB) ? NULL : (u32 *)req->iv;
273273
rctx->len = req->cryptlen;
274274
key1_id = ctx->key1_id;
275275
key2_id = ctx->key2_id;
@@ -498,9 +498,6 @@ static int tegra_aes_crypt(struct skcipher_request *req, bool encrypt)
498498
if (!req->cryptlen)
499499
return 0;
500500

501-
if (ctx->alg == SE_ALG_ECB)
502-
req->iv = NULL;
503-
504501
rctx->encrypt = encrypt;
505502

506503
return crypto_transfer_skcipher_request_to_engine(ctx->se->engine, req);

include/crypto/hash.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <linux/atomic.h>
1212
#include <linux/crypto.h>
13+
#include <linux/slab.h>
1314
#include <linux/string.h>
1415

1516
/* Set this bit for virtual address instead of SG list. */
@@ -581,7 +582,10 @@ static inline struct ahash_request *ahash_request_alloc_noprof(
581582
* ahash_request_free() - zeroize and free the request data structure
582583
* @req: request data structure cipher handle to be freed
583584
*/
584-
void ahash_request_free(struct ahash_request *req);
585+
static inline void ahash_request_free(struct ahash_request *req)
586+
{
587+
kfree_sensitive(req);
588+
}
585589

586590
static inline struct ahash_request *ahash_request_cast(
587591
struct crypto_async_request *req)

include/crypto/internal/hash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static inline struct crypto_shash *__crypto_shash_cast(struct crypto_tfm *tfm)
249249

250250
static inline bool ahash_request_chained(struct ahash_request *req)
251251
{
252-
return crypto_request_chained(&req->base);
252+
return false;
253253
}
254254

255255
static inline bool ahash_request_isvirt(struct ahash_request *req)

0 commit comments

Comments
 (0)