diff mbox series

crypto: sun8i-ce: rename kfree() to kfree_sensitive()

Message ID 1614594641-35606-1-git-send-email-yang.lee@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series crypto: sun8i-ce: rename kfree() to kfree_sensitive() | expand

Commit Message

Yang Li March 1, 2021, 10:30 a.m. UTC
Rename kfree() to kfree_sensitive() to  make the intention of the API
more explicit.

fixed the following coccicheck:
./drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c:30:16-17: WARNING
opportunity for kfree_sensitive/kvfree_sensitive (memset at line 29)
./drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c:42:16-17: WARNING
opportunity for kfree_sensitive/kvfree_sensitive (memset at line 41)
./drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c:161:8-9: WARNING
opportunity for kfree_sensitive/kvfree_sensitive (memset at line 109)

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---
 drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Herbert Xu March 1, 2021, 10:32 a.m. UTC | #1
On Mon, Mar 01, 2021 at 06:30:41PM +0800, Yang Li wrote:
> Rename kfree() to kfree_sensitive() to  make the intention of the API
> more explicit.
> 
> fixed the following coccicheck:
> ./drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c:30:16-17: WARNING
> opportunity for kfree_sensitive/kvfree_sensitive (memset at line 29)
> ./drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c:42:16-17: WARNING
> opportunity for kfree_sensitive/kvfree_sensitive (memset at line 41)
> ./drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c:161:8-9: WARNING
> opportunity for kfree_sensitive/kvfree_sensitive (memset at line 109)
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
> ---
>  drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> index cfde9ee..8259d52 100644
> --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> @@ -27,7 +27,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);

Any reason why you're keeping the memzero?

Thanks,
Christophe Leroy March 1, 2021, 10:35 a.m. UTC | #2
Le 01/03/2021 à 11:30, Yang Li a écrit :
> Rename kfree() to kfree_sensitive() to  make the intention of the API
> more explicit.

As far as I understand, you are not renaming kfree() to kfree_sensitive().

You are making a change to use kfree_sensitive() instead of using kfree().

Christophe

> 
> fixed the following coccicheck:
> ./drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c:30:16-17: WARNING
> opportunity for kfree_sensitive/kvfree_sensitive (memset at line 29)
> ./drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c:42:16-17: WARNING
> opportunity for kfree_sensitive/kvfree_sensitive (memset at line 41)
> ./drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c:161:8-9: WARNING
> opportunity for kfree_sensitive/kvfree_sensitive (memset at line 109)
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
> ---
>   drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> index cfde9ee..8259d52 100644
> --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
> @@ -27,7 +27,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;
>   }
> @@ -39,7 +39,7 @@ int sun8i_ce_prng_seed(struct crypto_rng *tfm, const u8 *seed,
>   
>   	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;
>   	}
> @@ -158,7 +158,7 @@ int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src,
>   	}
>   	memzero_explicit(d, todo);
>   err_iv:
> -	kfree(d);
> +	kfree_sensitive(d);
>   err_mem:
>   	return err;
>   }
>
diff mbox series

Patch

diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
index cfde9ee..8259d52 100644
--- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
+++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c
@@ -27,7 +27,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;
 }
@@ -39,7 +39,7 @@  int sun8i_ce_prng_seed(struct crypto_rng *tfm, const u8 *seed,
 
 	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;
 	}
@@ -158,7 +158,7 @@  int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src,
 	}
 	memzero_explicit(d, todo);
 err_iv:
-	kfree(d);
+	kfree_sensitive(d);
 err_mem:
 	return err;
 }