Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: api - Add crypto_request_clone and fb

Add a helper to clone crypto requests and eliminate code duplication.
Use kmemdup in the helper.

Also add an fb field to crypto_tfm.

This also happens to fix the existing implementations which were
buggy.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202504230118.1CxUaUoX-lkp@intel.com/
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202504230004.c7mrY0C6-lkp@intel.com/
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+58 -64
+3 -26
crypto/acompress.c
··· 11 11 #include <crypto/scatterwalk.h> 12 12 #include <linux/cryptouser.h> 13 13 #include <linux/cpumask.h> 14 - #include <linux/errno.h> 14 + #include <linux/err.h> 15 15 #include <linux/kernel.h> 16 16 #include <linux/module.h> 17 - #include <linux/page-flags.h> 18 17 #include <linux/percpu.h> 19 18 #include <linux/scatterlist.h> 20 19 #include <linux/sched.h> 21 20 #include <linux/seq_file.h> 22 - #include <linux/slab.h> 23 21 #include <linux/smp.h> 24 22 #include <linux/spinlock.h> 25 23 #include <linux/string.h> ··· 77 79 alg->exit(acomp); 78 80 79 81 if (acomp_is_async(acomp)) 80 - crypto_free_acomp(acomp->fb); 82 + crypto_free_acomp(crypto_acomp_fb(acomp)); 81 83 } 82 84 83 85 static int crypto_acomp_init_tfm(struct crypto_tfm *tfm) ··· 86 88 struct acomp_alg *alg = crypto_acomp_alg(acomp); 87 89 struct crypto_acomp *fb = NULL; 88 90 int err; 89 - 90 - acomp->fb = acomp; 91 91 92 92 if (tfm->__crt_alg->cra_type != &crypto_acomp_type) 93 93 return crypto_init_scomp_ops_async(tfm); ··· 100 104 if (crypto_acomp_reqsize(fb) > MAX_SYNC_COMP_REQSIZE) 101 105 goto out_free_fb; 102 106 103 - acomp->fb = fb; 107 + tfm->fb = crypto_acomp_tfm(fb); 104 108 } 105 109 106 110 acomp->compress = alg->compress; ··· 565 569 return 0; 566 570 } 567 571 EXPORT_SYMBOL_GPL(acomp_walk_virt); 568 - 569 - struct acomp_req *acomp_request_clone(struct acomp_req *req, 570 - size_t total, gfp_t gfp) 571 - { 572 - struct crypto_acomp *tfm = crypto_acomp_reqtfm(req); 573 - struct acomp_req *nreq; 574 - 575 - nreq = kmalloc(total, gfp); 576 - if (!nreq) { 577 - acomp_request_set_tfm(req, tfm->fb); 578 - req->base.flags = CRYPTO_TFM_REQ_ON_STACK; 579 - return req; 580 - } 581 - 582 - memcpy(nreq, req, total); 583 - acomp_request_set_tfm(req, tfm); 584 - return req; 585 - } 586 - EXPORT_SYMBOL_GPL(acomp_request_clone); 587 572 588 573 MODULE_LICENSE("GPL"); 589 574 MODULE_DESCRIPTION("Asynchronous compression type");
+5 -27
crypto/ahash.c
··· 12 12 * Copyright (c) 2008 Loc Ho <lho@amcc.com> 13 13 */ 14 14 15 - #include <crypto/scatterwalk.h> 16 15 #include <linux/cryptouser.h> 17 16 #include <linux/err.h> 18 17 #include <linux/kernel.h> 19 18 #include <linux/mm.h> 20 19 #include <linux/module.h> 21 - #include <linux/sched.h> 22 20 #include <linux/slab.h> 23 21 #include <linux/seq_file.h> 24 22 #include <linux/string.h> ··· 299 301 300 302 err = alg->setkey(tfm, key, keylen); 301 303 if (!err && ahash_is_async(tfm)) 302 - err = crypto_ahash_setkey(tfm->fb, key, keylen); 304 + err = crypto_ahash_setkey(crypto_ahash_fb(tfm), 305 + key, keylen); 303 306 if (unlikely(err)) { 304 307 ahash_set_needkey(tfm, alg); 305 308 return err; ··· 731 732 tfm->__crt_alg->cra_exit(tfm); 732 733 733 734 if (ahash_is_async(hash)) 734 - crypto_free_ahash(hash->fb); 735 + crypto_free_ahash(crypto_ahash_fb(hash)); 735 736 } 736 737 737 738 static int crypto_ahash_init_tfm(struct crypto_tfm *tfm) ··· 744 745 crypto_ahash_set_statesize(hash, alg->halg.statesize); 745 746 crypto_ahash_set_reqsize(hash, crypto_tfm_alg_reqsize(tfm)); 746 747 747 - hash->fb = hash; 748 - 749 748 if (tfm->__crt_alg->cra_type == &crypto_shash_type) 750 749 return crypto_init_ahash_using_shash(tfm); 751 750 ··· 753 756 if (IS_ERR(fb)) 754 757 return PTR_ERR(fb); 755 758 756 - hash->fb = fb; 759 + tfm->fb = crypto_ahash_tfm(fb); 757 760 } 758 761 759 762 ahash_set_needkey(hash, alg); ··· 1033 1036 int crypto_hash_digest(struct crypto_ahash *tfm, const u8 *data, 1034 1037 unsigned int len, u8 *out) 1035 1038 { 1036 - HASH_REQUEST_ON_STACK(req, tfm->fb); 1039 + HASH_REQUEST_ON_STACK(req, crypto_ahash_fb(tfm)); 1037 1040 int err; 1038 1041 1039 1042 ahash_request_set_callback(req, 0, NULL, NULL); ··· 1045 1048 return err; 1046 1049 } 1047 1050 EXPORT_SYMBOL_GPL(crypto_hash_digest); 1048 - 1049 - struct ahash_request *ahash_request_clone(struct ahash_request *req, 1050 - size_t total, gfp_t gfp) 1051 - { 1052 - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 1053 - struct ahash_request *nreq; 1054 - 1055 - nreq = kmalloc(total, gfp); 1056 - if (!nreq) { 1057 - ahash_request_set_tfm(req, tfm->fb); 1058 - req->base.flags = CRYPTO_TFM_REQ_ON_STACK; 1059 - return req; 1060 - } 1061 - 1062 - memcpy(nreq, req, total); 1063 - ahash_request_set_tfm(req, tfm); 1064 - return req; 1065 - } 1066 - EXPORT_SYMBOL_GPL(ahash_request_clone); 1067 1051 1068 1052 MODULE_LICENSE("GPL"); 1069 1053 MODULE_DESCRIPTION("Asynchronous cryptographic hash type");
+18
crypto/api.c
··· 528 528 goto out; 529 529 530 530 tfm = (struct crypto_tfm *)(mem + frontend->tfmsize); 531 + tfm->fb = tfm; 531 532 532 533 err = frontend->init_tfm(tfm); 533 534 if (err) ··· 712 711 alg->cra_destroy(alg); 713 712 } 714 713 EXPORT_SYMBOL_GPL(crypto_destroy_alg); 714 + 715 + struct crypto_async_request *crypto_request_clone( 716 + struct crypto_async_request *req, size_t total, gfp_t gfp) 717 + { 718 + struct crypto_tfm *tfm = req->tfm; 719 + struct crypto_async_request *nreq; 720 + 721 + nreq = kmemdup(req, total, gfp); 722 + if (!nreq) { 723 + req->tfm = tfm->fb; 724 + return req; 725 + } 726 + 727 + nreq->flags &= ~CRYPTO_TFM_REQ_ON_STACK; 728 + return nreq; 729 + } 730 + EXPORT_SYMBOL_GPL(crypto_request_clone); 715 731 716 732 MODULE_DESCRIPTION("Cryptographic core API"); 717 733 MODULE_LICENSE("GPL");
+6 -3
include/crypto/acompress.h
··· 114 114 int (*compress)(struct acomp_req *req); 115 115 int (*decompress)(struct acomp_req *req); 116 116 unsigned int reqsize; 117 - struct crypto_acomp *fb; 118 117 struct crypto_tfm base; 119 118 }; 120 119 ··· 552 553 return req; 553 554 } 554 555 555 - struct acomp_req *acomp_request_clone(struct acomp_req *req, 556 - size_t total, gfp_t gfp); 556 + static inline struct acomp_req *acomp_request_clone(struct acomp_req *req, 557 + size_t total, gfp_t gfp) 558 + { 559 + return container_of(crypto_request_clone(&req->base, total, gfp), 560 + struct acomp_req, base); 561 + } 557 562 558 563 #endif
+6 -3
include/crypto/hash.h
··· 246 246 bool using_shash; /* Underlying algorithm is shash, not ahash */ 247 247 unsigned int statesize; 248 248 unsigned int reqsize; 249 - struct crypto_ahash *fb; 250 249 struct crypto_tfm base; 251 250 }; 252 251 ··· 1034 1035 return req; 1035 1036 } 1036 1037 1037 - struct ahash_request *ahash_request_clone(struct ahash_request *req, 1038 - size_t total, gfp_t gfp); 1038 + static inline struct ahash_request *ahash_request_clone( 1039 + struct ahash_request *req, size_t total, gfp_t gfp) 1040 + { 1041 + return container_of(crypto_request_clone(&req->base, total, gfp), 1042 + struct ahash_request, base); 1043 + } 1039 1044 1040 1045 #endif /* _CRYPTO_HASH_H */
+6 -1
include/crypto/internal/acompress.h
··· 220 220 return crypto_request_flags(&req->base) & ~CRYPTO_ACOMP_REQ_PRIVATE; 221 221 } 222 222 223 + static inline struct crypto_acomp *crypto_acomp_fb(struct crypto_acomp *tfm) 224 + { 225 + return __crypto_acomp_tfm(crypto_acomp_tfm(tfm)->fb); 226 + } 227 + 223 228 static inline struct acomp_req *acomp_fbreq_on_stack_init( 224 229 char *buf, struct acomp_req *old) 225 230 { 226 231 struct crypto_acomp *tfm = crypto_acomp_reqtfm(old); 227 232 struct acomp_req *req = (void *)buf; 228 233 229 - acomp_request_set_tfm(req, tfm->fb); 234 + acomp_request_set_tfm(req, crypto_acomp_fb(tfm)); 230 235 req->base.flags = CRYPTO_TFM_REQ_ON_STACK; 231 236 acomp_request_set_callback(req, acomp_request_flags(old), NULL, NULL); 232 237 req->base.flags &= ~CRYPTO_ACOMP_REQ_PRIVATE;
+6 -1
include/crypto/internal/hash.h
··· 272 272 return crypto_tfm_req_chain(&tfm->base); 273 273 } 274 274 275 + static inline struct crypto_ahash *crypto_ahash_fb(struct crypto_ahash *tfm) 276 + { 277 + return __crypto_ahash_cast(crypto_ahash_tfm(tfm)->fb); 278 + } 279 + 275 280 static inline struct ahash_request *ahash_fbreq_on_stack_init( 276 281 char *buf, struct ahash_request *old) 277 282 { 278 283 struct crypto_ahash *tfm = crypto_ahash_reqtfm(old); 279 284 struct ahash_request *req = (void *)buf; 280 285 281 - ahash_request_set_tfm(req, tfm->fb); 286 + ahash_request_set_tfm(req, crypto_ahash_fb(tfm)); 282 287 req->base.flags = CRYPTO_TFM_REQ_ON_STACK; 283 288 ahash_request_set_callback(req, ahash_request_flags(old), NULL, NULL); 284 289 req->base.flags &= ~CRYPTO_AHASH_REQ_PRIVATE;
+8 -3
include/linux/crypto.h
··· 14 14 15 15 #include <linux/completion.h> 16 16 #include <linux/errno.h> 17 - #include <linux/refcount.h> 17 + #include <linux/refcount_types.h> 18 18 #include <linux/slab.h> 19 19 #include <linux/types.h> 20 20 ··· 411 411 u32 crt_flags; 412 412 413 413 int node; 414 - 414 + 415 + struct crypto_tfm *fb; 416 + 415 417 void (*exit)(struct crypto_tfm *tfm); 416 - 418 + 417 419 struct crypto_alg *__crt_alg; 418 420 419 421 void *__crt_ctx[] CRYPTO_MINALIGN_ATTR; ··· 510 508 req->tfm = tfm; 511 509 req->flags &= ~CRYPTO_TFM_REQ_ON_STACK; 512 510 } 511 + 512 + struct crypto_async_request *crypto_request_clone( 513 + struct crypto_async_request *req, size_t total, gfp_t gfp); 513 514 514 515 #endif /* _LINUX_CRYPTO_H */ 515 516