DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Kai Ji <kai.ji@intel.com>
Subject: [PATCH v3 03/11] crypto/qat: force zero of keys
Date: Wed, 13 Nov 2024 18:35:52 -0800	[thread overview]
Message-ID: <20241114023738.141821-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20241114023738.141821-1-stephen@networkplumber.org>

Just doing memset() on keys is not enough, compiler can optimize
it away. Need something with a barrier.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/crypto/qat/qat_sym_session.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/qat/qat_sym_session.c b/drivers/crypto/qat/qat_sym_session.c
index 50d687fd37..2fce8fcb16 100644
--- a/drivers/crypto/qat/qat_sym_session.c
+++ b/drivers/crypto/qat/qat_sym_session.c
@@ -26,6 +26,7 @@
 #include <rte_crypto_sym.h>
 #include <rte_security_driver.h>
 #include <rte_ether.h>
+#include <rte_string_fns.h>
 
 #include "qat_logs.h"
 #include "qat_sym_session.h"
@@ -1633,7 +1634,7 @@ static int qat_sym_do_precomputes(enum icp_qat_hw_auth_algo hash_alg,
 			aes_cmac_key_derive(k0, k1);
 			aes_cmac_key_derive(k1, k2);
 
-			memset(k0, 0, ICP_QAT_HW_AES_128_KEY_SZ);
+			rte_memset_sensitive(k0, 0, ICP_QAT_HW_AES_128_KEY_SZ);
 			*p_state_len = ICP_QAT_HW_AES_XCBC_MAC_STATE2_SZ;
 			rte_free(in);
 			goto out;
@@ -1668,7 +1669,7 @@ static int qat_sym_do_precomputes(enum icp_qat_hw_auth_algo hash_alg,
 							&enc_key) != 0) {
 					rte_free(in -
 					  (x * ICP_QAT_HW_AES_XCBC_MAC_KEY_SZ));
-					memset(out -
+					rte_memset_sensitive(out -
 					   (x * ICP_QAT_HW_AES_XCBC_MAC_KEY_SZ),
 					  0, ICP_QAT_HW_AES_XCBC_MAC_STATE2_SZ);
 					return -EFAULT;
@@ -1698,7 +1699,7 @@ static int qat_sym_do_precomputes(enum icp_qat_hw_auth_algo hash_alg,
 			return -ENOMEM;
 		}
 
-		memset(in, 0, ICP_QAT_HW_GALOIS_H_SZ);
+		rte_memset_sensitive(in, 0, ICP_QAT_HW_GALOIS_H_SZ);
 		if (AES_set_encrypt_key(auth_key, auth_keylen << 3,
 			&enc_key) != 0) {
 			return -EFAULT;
@@ -1757,8 +1758,8 @@ static int qat_sym_do_precomputes(enum icp_qat_hw_auth_algo hash_alg,
 	}
 
 	/*  don't leave data lying around */
-	memset(ipad, 0, block_size);
-	memset(opad, 0, block_size);
+	rte_memset_sensitive(ipad, 0, block_size);
+	rte_memset_sensitive(opad, 0, block_size);
 out:
 	return 0;
 }
@@ -2006,8 +2007,8 @@ static int qat_sym_do_precomputes_ipsec_mb(enum icp_qat_hw_auth_algo hash_alg,
 
 out:
 	/*  don't leave data lying around */
-	memset(ipad, 0, block_size);
-	memset(opad, 0, block_size);
+	rte_memset_sensitive(ipad, 0, block_size);
+	rte_memset_sensitive(opad, 0, block_size);
 	free_mb_mgr(m);
 	return ret;
 }
@@ -3232,7 +3233,7 @@ qat_security_session_destroy(void *dev __rte_unused,
 		if (s->mb_mgr)
 			free_mb_mgr(s->mb_mgr);
 #endif
-		memset(s, 0, qat_sym_session_get_private_size(dev));
+		rte_memset_sensitive(s, 0, qat_sym_session_get_private_size(dev));
 	}
 
 	return 0;
-- 
2.45.2


  parent reply	other threads:[~2024-11-14  2:38 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-14  1:10 [PATCH 0/3] introduce rte_memset_sensative Stephen Hemminger
2024-11-14  1:10 ` [PATCH 1/3] eal: " Stephen Hemminger
2024-11-14  1:10 ` [PATCH 2/3] crypto/qat: use rte_memset_sensative Stephen Hemminger
2024-11-14  1:10 ` [PATCH 3/3] eal: add rte_free_sensative Stephen Hemminger
2024-11-14  1:52 ` [PATCH v2 0/8] memset security handling Stephen Hemminger
2024-11-14  1:52   ` [PATCH v2 1/8] eal: introduce new secure memory fill Stephen Hemminger
2024-11-14  1:52   ` [PATCH v2 2/8] eal: add new secure free function Stephen Hemminger
2024-11-14  1:52   ` [PATCH v2 3/8] crypto/qat: force zero of keys Stephen Hemminger
2024-11-14  1:52   ` [PATCH v2 4/8] crypto/qat: fix size calculation for memset Stephen Hemminger
2024-11-14  1:52   ` [PATCH v2 5/8] crypto/qat: use secure memset Stephen Hemminger
2024-11-14  1:52   ` [PATCH v2 6/8] bus/uacce: remove memset before free Stephen Hemminger
2024-11-14  1:52   ` [PATCH v2 7/8] compress/octeontx: remove unnecessary memset Stephen Hemminger
2024-11-14  1:52   ` [PATCH v2 8/8] test: remove unneeded memset Stephen Hemminger
2024-11-14  2:35 ` [PATCH v3 00/11] memset security handling Stephen Hemminger
2024-11-14  2:35   ` [PATCH v3 01/11] eal: introduce new secure memory fill Stephen Hemminger
2024-11-14  2:35   ` [PATCH v3 02/11] eal: add new secure free function Stephen Hemminger
2024-11-14  2:35   ` Stephen Hemminger [this message]
2024-11-14  2:35   ` [PATCH v3 04/11] crypto/qat: fix size calculation for memset Stephen Hemminger
2024-11-14  2:35   ` [PATCH v3 05/11] crypto/qat: use secure memset Stephen Hemminger
2024-11-14  2:35   ` [PATCH v3 06/11] bus/uacce: remove memset before free Stephen Hemminger
2024-11-14  2:35   ` [PATCH v3 07/11] compress/octeontx: remove unnecessary memset Stephen Hemminger
2024-11-14  2:35   ` [PATCH v3 08/11] test: remove unneeded memset Stephen Hemminger
2024-11-14  2:35   ` [PATCH v3 09/11] net/ntnic: remove unnecessary void cast Stephen Hemminger
2024-11-14  2:35   ` [PATCH v3 10/11] net/ntnic: check result of malloc Stephen Hemminger
2024-11-14  2:36   ` [PATCH v3 11/11] net/ntnic: remove unnecessary memset Stephen Hemminger
2024-11-14 18:43 ` [PATCH v4 00/12] memset security fixes Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 01/12] eal: introduce new secure memory fill Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 02/12] eal: add new secure free function Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 03/12] crypto/qat: force zero of keys Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 04/12] crypto/qat: fix size calculation for memset Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 05/12] crypto/qat: use secure memset Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 06/12] bus/uacce: remove memset before free Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 07/12] compress/octeontx: remove unnecessary memset Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 08/12] test: remove unneeded memset Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 09/12] net/ntnic: remove unnecessary void cast Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 10/12] net/ntnic: check result of malloc Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 11/12] net/ntnic: remove unnecessary memset Stephen Hemminger
2024-11-14 18:43   ` [PATCH v4 12/12] devtools/cocci: add script to find problematic memset Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241114023738.141821-4-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=kai.ji@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).