Skip to contentSkip to conversation

test/crypto: fix asym session mempool creation

PATCH In review Adam Dybkowski 3 participants 8 messages Jun 8, 2020 – Jul 1, 2020 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 test/crypto: fix asym session mempool creation

This patch fixes the element size of the mempool used for allocating asym crypto sessions and their private data.

Fixes 2c6dab9cd93d ("test/crypto: add RSA and Mod tests")
---
 app/test/test_cryptodev_asym.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
app/test/test_cryptodev_asym.c +3 -2
index b8e050048..dc62ed7bf 100644
@@ -935,8 +935,9 @@ testsuite_setup(void)
 	}
 
 	/* setup asym session pool */
-	unsigned int session_size =
-		rte_cryptodev_asym_get_private_session_size(dev_id);
+	unsigned int session_size = RTE_MAX(
+		rte_cryptodev_asym_get_private_session_size(dev_id),
+		rte_cryptodev_asym_get_header_session_size());
 	/*
 	 * Create mempool with TEST_NUM_SESSIONS * 2,
 	 * to include the session headers
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/3 cryptodev: verify session mempool element size

This patch adds the verification of the element size of the mempool provided for the session creation. Returns the error if the element size is too small to hold the session object.

---
 lib/librte_cryptodev/rte_cryptodev.c | 45 +++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 8 deletions(-)
lib/librte_cryptodev/rte_cryptodev.c +37 -8
index e37b83afd..9ea4ece65 100644
@@ -1422,7 +1422,7 @@ rte_cryptodev_sym_session_init(uint8_t dev_id,
 
 	dev = rte_cryptodev_pmd_get_dev(dev_id);
 
-	if (sess == NULL || xforms == NULL || dev == NULL)
+	if (sess == NULL || xforms == NULL || dev == NULL || mp == NULL)
 		return -EINVAL;
 
 	if (mp->elt_size < sess_priv_sz)
@@ -1540,24 +1540,39 @@ rte_cryptodev_sym_session_data_size(struct rte_cryptodev_sym_session *sess)
 			sess->user_data_sz;
 }
 
+static uint8_t
+rte_cryptodev_sym_is_valid_session_pool(struct rte_mempool *mp)
+{
+	struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
+
+	if (!mp)
+		return 0;
+
+	pool_priv = rte_mempool_get_priv(mp);
+
+	if (!pool_priv || mp->private_data_size < sizeof(*pool_priv) ||
+			pool_priv->nb_drivers != nb_drivers ||
+			mp->elt_size <
+				rte_cryptodev_sym_get_header_session_size()
+				+ pool_priv->user_data_sz)
+		return 0;
+
+	return 1;
+}
+
 struct rte_cryptodev_sym_session *
 rte_cryptodev_sym_session_create(struct rte_mempool *mp)
 {
 	struct rte_cryptodev_sym_session *sess;
 	struct rte_cryptodev_sym_session_pool_private_data *pool_priv;
 
-	if (!mp) {
+	if (!rte_cryptodev_sym_is_valid_session_pool(mp)) {
 		CDEV_LOG_ERR("Invalid mempool\n");
 		return NULL;
 	}
 
 	pool_priv = rte_mempool_get_priv(mp);
 
-	if (!pool_priv || mp->private_data_size < sizeof(*pool_priv)) {
-		CDEV_LOG_ERR("Invalid mempool\n");
-		return NULL;
-	}
-
 	/* Allocate a session structure from the session pool */
 	if (rte_mempool_get(mp, (void **)&sess)) {
 		CDEV_LOG_ERR("couldn't get object from session mempool");
@@ -1582,6 +1597,20 @@ struct rte_cryptodev_asym_session *
 rte_cryptodev_asym_session_create(struct rte_mempool *mp)
 {
 	struct rte_cryptodev_asym_session *sess;
+	unsigned int session_size =
+			rte_cryptodev_asym_get_header_session_size();
+
+	if (!mp) {
+		CDEV_LOG_ERR("invalid mempool\n");
+		return NULL;
+	}
+
+	/* Verify if provided mempool can hold elements big enough. */
+	if (mp->elt_size < session_size) {
+		CDEV_LOG_ERR(
+			"mempool elements too small to hold session objects");
+		return NULL;
+	}
 
 	/* Allocate a session structure from the session pool */
 	if (rte_mempool_get(mp, (void **)&sess)) {
@@ -1592,7 +1621,7 @@ rte_cryptodev_asym_session_create(struct rte_mempool *mp)
 	/* Clear device session pointer.
 	 * Include the flag indicating presence of private data
 	 */
-	memset(sess, 0, (sizeof(void *) * nb_drivers) + sizeof(uint8_t));
+	memset(sess, 0, session_size);
 
 	rte_cryptodev_trace_asym_session_create(mp, sess);
 	return sess;
Signature · 1 line
2.25.1
Acked-by on v1 2/3
#2 lore raw

Re: [dpdk-dev] [PATCH 2/3] cryptodev: verify session mempool element size

Quoted 8 lines

-----Original Message-----
From: Dybkowski, AdamX <[email protected]>
Sent: Monday, June 8, 2020 2:15 PM
To: [email protected]; Trahe, Fiona <[email protected]>; [email protected]
Cc: Dybkowski, AdamX <[email protected]>
Subject: [PATCH 2/3] cryptodev: verify session mempool element size

Quoted 5 lines

This patch adds the verification of the element size of the mempool provided for the session creation. Returns the error if the element size is too small to hold the session object.

Acked-by
#3 lore raw

Re: [dpdk-dev] [PATCH 2/3] cryptodev: verify session mempool element size

Quoted 8 lines
Quoted 7 lines

Subject: [PATCH 2/3] cryptodev: verify session mempool element size

This patch adds the verification of the element size of the mempool provided for the session creation. Returns the error if the element size is too small to hold the session object.

Series applied to dpdk-next-crypto

Thanks.

#4 lore raw

PATCH 3/3 crypto/qat: verify session IOVA

In reply to Adam Dybkowski

This patch adds the verification of the crypto session IOVA that should be known (not zero) to proceed with the session initialisation. In case of unknown IOVA the error code -EINVAL is returned.

---
 drivers/crypto/qat/qat_sym_session.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/crypto/qat/qat_sym_session.c +9 -1
index 58bdbd343..11b459ee8 100644
@@ -537,8 +537,16 @@ qat_sym_session_set_parameters(struct rte_cryptodev *dev,
 	int ret;
 	int qat_cmd_id;
 
+	/* Verify the session physical address is known */
+	rte_iova_t session_paddr = rte_mempool_virt2iova(session);
+	if (session_paddr == 0 || session_paddr == RTE_BAD_IOVA) {
+		QAT_LOG(ERR,
+			"Session physical address unknown. Bad memory pool.");
+		return -EINVAL;
+	}
+
 	/* Set context descriptor physical address */
-	session->cd_paddr = rte_mempool_virt2iova(session) +
+	session->cd_paddr = session_paddr +
 			offsetof(struct qat_sym_session, cd);
 
 	session->min_qat_dev_gen = QAT_GEN1;
Signature · 1 line
2.25.1
Acked-by on v1 3/3
#5 lore raw

Re: [dpdk-dev] [PATCH 3/3] crypto/qat: verify session IOVA

Quoted 9 lines

-----Original Message-----
From: Dybkowski, AdamX <[email protected]>
Sent: Monday, June 8, 2020 2:15 PM
To: [email protected]; Trahe, Fiona <[email protected]>; [email protected]
Cc: Dybkowski, AdamX <[email protected]>
Subject: [PATCH 3/3] crypto/qat: verify session IOVA

Quoted 6 lines

This patch adds the verification of the crypto session IOVA that should be known (not zero) to proceed with the session initialisation. In case of unknown IOVA the error code -EINVAL is returned.

Acked-by on v1 1/3
#6 lore raw
In reply to Adam Dybkowski
Quoted 9 lines

-----Original Message-----
From: Dybkowski, AdamX <[email protected]>
Sent: Monday, June 8, 2020 2:15 PM
To: [email protected]; Trahe, Fiona <[email protected]>; [email protected]
Cc: Dybkowski, AdamX <[email protected]>; [email protected]
Subject: [PATCH 1/3] test/crypto: fix asym session mempool creation

Quoted 7 lines

This patch fixes the element size of the mempool used for allocating asym crypto sessions and their private data.

Fixes 2c6dab9cd93d ("test/crypto: add RSA and Mod tests")