LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] crypto: sun8i-ce - use kfree_sensitive to clear and free sensitive data
@ 2021-08-03 12:55 Jason Wang
2021-08-12 11:36 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Jason Wang @ 2021-08-03 12:55 UTC (permalink / raw)
To: herbert
Cc: clabbe.montjoie, davem, mripard, wens, jernej.skrabec,
wangborong, mchehab+huawei, corbet, baijiaju1990, linux-crypto,
linux-arm-kernel, linux-sunxi, linux-kernel
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: Jason Wang <wangborong@cdjrlc.com>
---
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c | 9 +++------
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c | 3 +--
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
index cd1baee424a1..b3a9bbfb8831 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
@@ -26,8 +26,7 @@ void sun8i_ce_prng_exit(struct crypto_tfm *tfm)
{
struct sun8i_ce_rng_tfm_ctx *ctx = crypto_tfm_ctx(tfm);
- memzero_explicit(ctx->seed, ctx->slen);
- kfree(ctx->seed);
+ kfree_sensitive(ctx->seed);
ctx->seed = NULL;
ctx->slen = 0;
}
@@ -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);
if (ctx->seed && ctx->slen != slen) {
- memzero_explicit(ctx->seed, ctx->slen);
- kfree(ctx->seed);
+ kfree_sensitive(ctx->seed);
ctx->slen = 0;
ctx->seed = NULL;
}
@@ -157,9 +155,8 @@ int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src,
memcpy(dst, d, dlen);
memcpy(ctx->seed, d + dlen, ctx->slen);
}
- memzero_explicit(d, todo);
err_iv:
- kfree(d);
+ kfree_sensitive(d);
err_mem:
return err;
}
diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c
index 5b7af4498bd5..19cd2e52f89d 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c
@@ -95,9 +95,8 @@ static int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wa
memcpy(data, d, max);
err = max;
}
- memzero_explicit(d, todo);
err_dst:
- kfree(d);
+ kfree_sensitive(d);
return err;
}
--
2.32.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] crypto: sun8i-ce - use kfree_sensitive to clear and free sensitive data
2021-08-03 12:55 [PATCH] crypto: sun8i-ce - use kfree_sensitive to clear and free sensitive data Jason Wang
@ 2021-08-12 11:36 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2021-08-12 11:36 UTC (permalink / raw)
To: Jason Wang
Cc: clabbe.montjoie, davem, mripard, wens, jernej.skrabec,
mchehab+huawei, corbet, baijiaju1990, linux-crypto,
linux-arm-kernel, linux-sunxi, linux-kernel
On Tue, Aug 03, 2021 at 12:55:25PM +0000, Jason Wang wrote:
> 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: Jason Wang <wangborong@cdjrlc.com>
> ---
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c | 9 +++------
> drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c | 3 +--
> 2 files changed, 4 insertions(+), 8 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-08-12 11:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 12:55 [PATCH] crypto: sun8i-ce - use kfree_sensitive to clear and free sensitive data Jason Wang
2021-08-12 11:36 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).