diff mbox series

KEYS: trusted: dcp: Use kfree_sensitive() to fix Coccinelle warnings

Message ID 20250320103557.7236-1-liubo03@inspur.com (mailing list archive)
State New
Headers show
Series KEYS: trusted: dcp: Use kfree_sensitive() to fix Coccinelle warnings | expand

Commit Message

Bo Liu March 20, 2025, 10:35 a.m. UTC
Replace memzero_explicit() and kfree() with kfree_sensitive() to fix
warnings reported by Coccinelle:

WARNING opportunity for kfree_sensitive/kvfree_sensitive
WARNING opportunity for kfree_sensitive/kvfree_sensitive

Signed-off-by: Bo Liu <liubo03@inspur.com>
---
 security/keys/trusted-keys/trusted_dcp.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Jarkko Sakkinen March 20, 2025, 3:16 p.m. UTC | #1
On Thu, Mar 20, 2025 at 06:35:57AM -0400, Bo Liu wrote:
> Replace memzero_explicit() and kfree() with kfree_sensitive() to fix
> warnings reported by Coccinelle:
> 
> WARNING opportunity for kfree_sensitive/kvfree_sensitive
> WARNING opportunity for kfree_sensitive/kvfree_sensitive

Even if you get the error from Coccinelle, you should still go trouble
why this warning happens. Otherwise, you are contributing a change that
you don't understand yourself.

> 
> Signed-off-by: Bo Liu <liubo03@inspur.com>
> ---
>  security/keys/trusted-keys/trusted_dcp.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/security/keys/trusted-keys/trusted_dcp.c b/security/keys/trusted-keys/trusted_dcp.c
> index 7b6eb655df0c..c967837e72ee 100644
> --- a/security/keys/trusted-keys/trusted_dcp.c
> +++ b/security/keys/trusted-keys/trusted_dcp.c
> @@ -233,8 +233,7 @@ static int trusted_dcp_seal(struct trusted_key_payload *p, char *datablob)
>  	ret = 0;
>  
>  out:
> -	memzero_explicit(plain_blob_key, AES_KEYSIZE_128);
> -	kfree(plain_blob_key);
> +	kfree_sensitive(plain_blob_key);
>  
>  	return ret;
>  }
> @@ -283,8 +282,7 @@ static int trusted_dcp_unseal(struct trusted_key_payload *p, char *datablob)
>  	ret = 0;
>  out:
>  	if (plain_blob_key) {
> -		memzero_explicit(plain_blob_key, AES_KEYSIZE_128);
> -		kfree(plain_blob_key);
> +		kfree_sensitive(plain_blob_key);
>  	}
>  
>  	return ret;
> -- 
> 2.31.1
> 

Not gonna fly because you did not include KEYS-TRUSTED-DCP maintainer to
the CC list.

BR, Jarkko
diff mbox series

Patch

diff --git a/security/keys/trusted-keys/trusted_dcp.c b/security/keys/trusted-keys/trusted_dcp.c
index 7b6eb655df0c..c967837e72ee 100644
--- a/security/keys/trusted-keys/trusted_dcp.c
+++ b/security/keys/trusted-keys/trusted_dcp.c
@@ -233,8 +233,7 @@  static int trusted_dcp_seal(struct trusted_key_payload *p, char *datablob)
 	ret = 0;
 
 out:
-	memzero_explicit(plain_blob_key, AES_KEYSIZE_128);
-	kfree(plain_blob_key);
+	kfree_sensitive(plain_blob_key);
 
 	return ret;
 }
@@ -283,8 +282,7 @@  static int trusted_dcp_unseal(struct trusted_key_payload *p, char *datablob)
 	ret = 0;
 out:
 	if (plain_blob_key) {
-		memzero_explicit(plain_blob_key, AES_KEYSIZE_128);
-		kfree(plain_blob_key);
+		kfree_sensitive(plain_blob_key);
 	}
 
 	return ret;