From patchwork Mon Jul 31 04:40:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "De Lara Guarch, Pablo" X-Patchwork-Id: 27282 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 85E5D9953; Mon, 31 Jul 2017 14:40:21 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 2F9162629 for ; Mon, 31 Jul 2017 14:40:18 +0200 (CEST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jul 2017 05:40:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,442,1496127600"; d="scan'208";a="133412540" Received: from silpixa00399464.ir.intel.com (HELO silpixa00399464.ger.corp.intel.com) ([10.237.222.157]) by fmsmga005.fm.intel.com with ESMTP; 31 Jul 2017 05:40:16 -0700 From: Pablo de Lara To: declan.doherty@intel.com Cc: dev@dpdk.org, Pablo de Lara Date: Mon, 31 Jul 2017 05:40:37 +0100 Message-Id: <20170731044037.70950-1-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 2.9.4 Subject: [dpdk-dev] [PATCH] examples/l2fwd-crypto: fix possible out-of-bounds 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" rte_cryptodev_socket_id() returns the socket id of a crypto device, unless the device id is not valid, in which case, it returns -1. This should not happen, as the device id is controlled by the application, but just for safety, a check is added. Coverity issue: 158628, 158638, 158656, 158662 Fixes: b3bbd9e5f265 ("cryptodev: support device independent sessions") Signed-off-by: Pablo de Lara --- examples/l2fwd-crypto/main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c index 83446f3..f020be3 100644 --- a/examples/l2fwd-crypto/main.c +++ b/examples/l2fwd-crypto/main.c @@ -662,7 +662,12 @@ initialize_crypto_session(struct l2fwd_crypto_options *options, uint8_t cdev_id) { struct rte_crypto_sym_xform *first_xform; struct rte_cryptodev_sym_session *session; - uint8_t socket_id = rte_cryptodev_socket_id(cdev_id); + int retval = rte_cryptodev_socket_id(cdev_id); + + if (retval < 0) + return NULL; + + uint8_t socket_id = (uint8_t) retval; struct rte_mempool *sess_mp = session_pool_socket[socket_id]; if (options->xform_chain == L2FWD_CRYPTO_AEAD) { @@ -1996,7 +2001,14 @@ initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports, cdev_id++) { struct rte_cryptodev_qp_conf qp_conf; struct rte_cryptodev_info dev_info; - uint8_t socket_id = rte_cryptodev_socket_id(cdev_id); + retval = rte_cryptodev_socket_id(cdev_id); + + if (retval < 0) { + printf("Invalid crypto device id used\n"); + return -1; + } + + uint8_t socket_id = (uint8_t) retval; struct rte_cryptodev_config conf = { .nb_queue_pairs = 1,