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

crypto: algapi - enforce that all instances have a ->free() method

All instances need to have a ->free() method, but people could forget to
set it and then not notice if the instance is never unregistered. To
help detect this bug earlier, don't allow an instance without a ->free()
method to be registered, and complain loudly if someone tries to do it.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
d4fdc2df a24a1fd7

+14
+3
crypto/aead.c
··· 288 288 { 289 289 int err; 290 290 291 + if (WARN_ON(!inst->free)) 292 + return -EINVAL; 293 + 291 294 err = aead_prepare_alg(&inst->alg); 292 295 if (err) 293 296 return err;
+3
crypto/ahash.c
··· 656 656 { 657 657 int err; 658 658 659 + if (WARN_ON(!inst->free)) 660 + return -EINVAL; 661 + 659 662 err = ahash_prepare_alg(&inst->alg); 660 663 if (err) 661 664 return err;
+2
crypto/akcipher.c
··· 147 147 int akcipher_register_instance(struct crypto_template *tmpl, 148 148 struct akcipher_instance *inst) 149 149 { 150 + if (WARN_ON(!inst->free)) 151 + return -EINVAL; 150 152 akcipher_prepare_alg(&inst->alg); 151 153 return crypto_register_instance(tmpl, akcipher_crypto_instance(inst)); 152 154 }
+3
crypto/shash.c
··· 577 577 { 578 578 int err; 579 579 580 + if (WARN_ON(!inst->free)) 581 + return -EINVAL; 582 + 580 583 err = shash_prepare_alg(&inst->alg); 581 584 if (err) 582 585 return err;
+3
crypto/skcipher.c
··· 865 865 { 866 866 int err; 867 867 868 + if (WARN_ON(!inst->free)) 869 + return -EINVAL; 870 + 868 871 err = skcipher_prepare_alg(&inst->alg); 869 872 if (err) 870 873 return err;