From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 538EEA04F2; Mon, 8 Jun 2020 15:15:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A26ED4C90; Mon, 8 Jun 2020 15:15:10 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id C7229293C for ; Mon, 8 Jun 2020 15:15:07 +0200 (CEST) IronPort-SDR: GRH28G9hd/cXHBt8J3G5BjZdRew3xJsKsu5SssZrw7hqQu002GgHGIENVNj9i38gK1BW7JT66X AZ1KIESxuKXA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2020 06:15:07 -0700 IronPort-SDR: xM11gUOKi8AkJ8ukWvlSBxuH1FkzGcFppCzJ+320CmSk8hjkChaXsPYQUIx+/wXvgzEUkmcTPD QeBWRZVQvPGA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="scan'208";a="349165774" Received: from unknown (HELO adamdybx-MOBL.ger.corp.intel.com) ([10.104.113.106]) by orsmga001.jf.intel.com with ESMTP; 08 Jun 2020 06:15:05 -0700 From: Adam Dybkowski To: dev@dpdk.org, fiona.trahe@intel.com, akhil.goyal@nxp.com Cc: Adam Dybkowski Date: Mon, 8 Jun 2020 15:15:02 +0200 Message-Id: <20200608131503.4003-2-adamx.dybkowski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608131503.4003-1-adamx.dybkowski@intel.com> References: <20200608131503.4003-1-adamx.dybkowski@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 2/3] cryptodev: verify session mempool element size X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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. Signed-off-by: Adam Dybkowski --- lib/librte_cryptodev/rte_cryptodev.c | 45 +++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index e37b83afd..9ea4ece65 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -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; -- 2.25.1