Skip to content

Commit c391714

Browse files
Jason Wangherbertx
authored andcommitted
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: Jason Wang <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 0888d04 commit c391714

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ void sun8i_ce_prng_exit(struct crypto_tfm *tfm)
2626
{
2727
struct sun8i_ce_rng_tfm_ctx *ctx = crypto_tfm_ctx(tfm);
2828

29-
memzero_explicit(ctx->seed, ctx->slen);
30-
kfree(ctx->seed);
29+
kfree_sensitive(ctx->seed);
3130
ctx->seed = NULL;
3231
ctx->slen = 0;
3332
}
@@ -38,8 +37,7 @@ int sun8i_ce_prng_seed(struct crypto_rng *tfm, const u8 *seed,
3837
struct sun8i_ce_rng_tfm_ctx *ctx = crypto_rng_ctx(tfm);
3938

4039
if (ctx->seed && ctx->slen != slen) {
41-
memzero_explicit(ctx->seed, ctx->slen);
42-
kfree(ctx->seed);
40+
kfree_sensitive(ctx->seed);
4341
ctx->slen = 0;
4442
ctx->seed = NULL;
4543
}
@@ -157,9 +155,8 @@ int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src,
157155
memcpy(dst, d, dlen);
158156
memcpy(ctx->seed, d + dlen, ctx->slen);
159157
}
160-
memzero_explicit(d, todo);
161158
err_iv:
162-
kfree(d);
159+
kfree_sensitive(d);
163160
err_mem:
164161
return err;
165162
}

drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ static int sun8i_ce_trng_read(struct hwrng *rng, void *data, size_t max, bool wa
9595
memcpy(data, d, max);
9696
err = max;
9797
}
98-
memzero_explicit(d, todo);
9998
err_dst:
100-
kfree(d);
99+
kfree_sensitive(d);
101100
return err;
102101
}
103102

0 commit comments

Comments
 (0)