Commit c391714c authored by Jason Wang's avatar Jason Wang Committed by Herbert Xu

crypto: sun8i-ce - use kfree_sensitive to clear and free sensitive data

The kfree_sensitive is a kernel API to clear sensitive information
that should not be leaked to other future users of the same memory
objects and free the memory. Its function is the same as the
combination  of memzero_explicit and kfree. Thus, we can replace the
combination APIs with the single kfree_sensitive API.
Signed-off-by: default avatarJason Wang <wangborong@cdjrlc.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 0888d04b
...@@ -26,8 +26,7 @@ void sun8i_ce_prng_exit(struct crypto_tfm *tfm) ...@@ -26,8 +26,7 @@ void sun8i_ce_prng_exit(struct crypto_tfm *tfm)
{ {
struct sun8i_ce_rng_tfm_ctx *ctx = crypto_tfm_ctx(tfm); struct sun8i_ce_rng_tfm_ctx *ctx = crypto_tfm_ctx(tfm);
memzero_explicit(ctx->seed, ctx->slen); kfree_sensitive(ctx->seed);
kfree(ctx->seed);
ctx->seed = NULL; ctx->seed = NULL;
ctx->slen = 0; ctx->slen = 0;
} }
...@@ -38,8 +37,7 @@ int sun8i_ce_prng_seed(struct crypto_rng *tfm, const u8 *seed, ...@@ -38,8 +37,7 @@ int sun8i_ce_prng_seed(struct crypto_rng *tfm, const u8 *seed,
struct sun8i_ce_rng_tfm_ctx *ctx = crypto_rng_ctx(tfm); struct sun8i_ce_rng_tfm_ctx *ctx = crypto_rng_ctx(tfm);
if (ctx->seed && ctx->slen != slen) { if (ctx->seed && ctx->slen != slen) {
memzero_explicit(ctx->seed, ctx->slen); kfree_sensitive(ctx->seed);
kfree(ctx->seed);
ctx->slen = 0; ctx->slen = 0;
ctx->seed = NULL; ctx->seed = NULL;
} }
...@@ -157,9 +155,8 @@ int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src, ...@@ -157,9 +155,8 @@ int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src,
memcpy(dst, d, dlen); memcpy(dst, d, dlen);
memcpy(ctx->seed, d + dlen, ctx->slen); memcpy(ctx->seed, d + dlen, ctx->slen);
} }
memzero_explicit(d, todo);
err_iv: err_iv:
kfree(d); kfree_sensitive(d);
err_mem: err_mem:
return err; return err;
} }
...@@ -95,9 +95,8 @@ static int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wa ...@@ -95,9 +95,8 @@ static int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wa
memcpy(data, d, max); memcpy(data, d, max);
err = max; err = max;
} }
memzero_explicit(d, todo);
err_dst: err_dst:
kfree(d); kfree_sensitive(d);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment