crypto: api - Fix zeroing on free
Geert Uytterhoeven pointed out that we're not zeroing all the memory when freeing a transform. This patch fixes it by calling ksize to ensure that we zero everything in sight. Reported-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
20
crypto/api.c
20
crypto/api.c
@@ -557,34 +557,34 @@ err:
|
|||||||
return ERR_PTR(err);
|
return ERR_PTR(err);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
|
EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* crypto_free_tfm - Free crypto transform
|
* crypto_destroy_tfm - Free crypto transform
|
||||||
|
* @mem: Start of tfm slab
|
||||||
* @tfm: Transform to free
|
* @tfm: Transform to free
|
||||||
*
|
*
|
||||||
* crypto_free_tfm() frees up the transform and any associated resources,
|
* This function frees up the transform and any associated resources,
|
||||||
* then drops the refcount on the associated algorithm.
|
* then drops the refcount on the associated algorithm.
|
||||||
*/
|
*/
|
||||||
void crypto_free_tfm(struct crypto_tfm *tfm)
|
void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm)
|
||||||
{
|
{
|
||||||
struct crypto_alg *alg;
|
struct crypto_alg *alg;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
if (unlikely(!tfm))
|
if (unlikely(!mem))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
alg = tfm->__crt_alg;
|
alg = tfm->__crt_alg;
|
||||||
size = sizeof(*tfm) + alg->cra_ctxsize;
|
size = ksize(mem);
|
||||||
|
|
||||||
if (!tfm->exit && alg->cra_exit)
|
if (!tfm->exit && alg->cra_exit)
|
||||||
alg->cra_exit(tfm);
|
alg->cra_exit(tfm);
|
||||||
crypto_exit_ops(tfm);
|
crypto_exit_ops(tfm);
|
||||||
crypto_mod_put(alg);
|
crypto_mod_put(alg);
|
||||||
memset(tfm, 0, size);
|
memset(mem, 0, size);
|
||||||
kfree(tfm);
|
kfree(mem);
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(crypto_destroy_tfm);
|
||||||
EXPORT_SYMBOL_GPL(crypto_free_tfm);
|
|
||||||
|
|
||||||
int crypto_has_alg(const char *name, u32 type, u32 mask)
|
int crypto_has_alg(const char *name, u32 type, u32 mask)
|
||||||
{
|
{
|
||||||
|
@@ -552,7 +552,12 @@ struct crypto_tfm *crypto_alloc_tfm(const char *alg_name,
|
|||||||
const struct crypto_type *frontend,
|
const struct crypto_type *frontend,
|
||||||
u32 type, u32 mask);
|
u32 type, u32 mask);
|
||||||
struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask);
|
struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask);
|
||||||
void crypto_free_tfm(struct crypto_tfm *tfm);
|
void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm);
|
||||||
|
|
||||||
|
static inline void crypto_free_tfm(struct crypto_tfm *tfm)
|
||||||
|
{
|
||||||
|
return crypto_destroy_tfm(tfm, tfm);
|
||||||
|
}
|
||||||
|
|
||||||
int alg_test(const char *driver, const char *alg, u32 type, u32 mask);
|
int alg_test(const char *driver, const char *alg, u32 type, u32 mask);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user