diff mbox series

[v3] KEYS: use kfree_sensitive with key

Message ID 20230622124719.93393-1-mngyadam@amazon.com (mailing list archive)
State New
Headers show
Series [v3] KEYS: use kfree_sensitive with key | expand

Commit Message

Mahmoud Adam June 22, 2023, 12:47 p.m. UTC
key might contain private part of the key, so better use
kfree_sensitive to free it
---
v1: conflicts with c3d03e8e35e0:
KEYS: asymmetric: Copy sig and digest in public_key_verify_signature()
kfree_sensitive the buf variable also because it might has private
part

 crypto/asymmetric_keys/public_key.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--
2.40.1

Comments

Herbert Xu July 14, 2023, 8:52 a.m. UTC | #1
On Thu, Jun 22, 2023 at 12:47:22PM +0000, Mahmoud Adam wrote:
> key might contain private part of the key, so better use
> kfree_sensitive to free it
> ---
> v1: conflicts with c3d03e8e35e0:
> KEYS: asymmetric: Copy sig and digest in public_key_verify_signature()
> kfree_sensitive the buf variable also because it might has private
> part
> 
>  crypto/asymmetric_keys/public_key.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Patch applied.  Thanks.
diff mbox series

Patch

diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c
index 50c933f86b21..170f06982381 100644
--- a/crypto/asymmetric_keys/public_key.c
+++ b/crypto/asymmetric_keys/public_key.c
@@ -43,7 +43,7 @@  static void public_key_describe(const struct key *asymmetric_key,
 void public_key_free(struct public_key *key)
 {
 	if (key) {
-		kfree(key->key);
+		kfree_sensitive(key->key);
 		kfree(key->params);
 		kfree(key);
 	}
@@ -218,7 +218,7 @@  static int software_key_query(const struct kernel_pkey_params *params,
 	ret = 0;

 error_free_key:
-	kfree(key);
+	kfree_sensitive(key);
 error_free_tfm:
 	crypto_free_akcipher(tfm);
 	pr_devel("<==%s() = %d\n", __func__, ret);
@@ -303,7 +303,7 @@  static int software_key_eds_op(struct kernel_pkey_params *params,
 		ret = req->dst_len;

 error_free_key:
-	kfree(key);
+	kfree_sensitive(key);
 error_free_req:
 	akcipher_request_free(req);
 error_free_tfm:
@@ -460,7 +460,7 @@  int public_key_verify_signature(const struct public_key *pkey,
 	ret = crypto_wait_req(crypto_akcipher_verify(req), &cwait);

 error_free_buf:
-	kfree(buf);
+	kfree_sensitive(buf);
 error_free_req:
 	akcipher_request_free(req);
 error_free_tfm: