From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 54CFF8D35 for ; Wed, 18 Apr 2018 12:37:49 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Apr 2018 03:37:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,464,1517904000"; d="scan'208";a="221365230" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga005.fm.intel.com with ESMTP; 18 Apr 2018 03:37:45 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w3IAbicK018457; Wed, 18 Apr 2018 11:37:44 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w3IAbi9x015814; Wed, 18 Apr 2018 11:37:44 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w3IAbiZh015806; Wed, 18 Apr 2018 11:37:44 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: thomas@monjalon.net, anatoly.burakov@intel.com Date: Wed, 18 Apr 2018 11:37:42 +0100 Message-Id: <822a2658f3dd71c6d4d71968dc1114528d8df5cc.1524047073.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 09/10] mem: fix negative return value 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: , X-List-Received-Date: Wed, 18 Apr 2018 10:37:50 -0000 Although unlikely during normal operation, rte_socket_id_by_idx() may return a negative value, which would've caused an out-of-bounds read. Fix it by making socket ID signed, and check for negative return. Coverity issue: 272577 Coverity issue: 272578 Fixes: 66cc45e293ed ("mem: replace memseg with memseg lists") Cc: anatoly.burakov@intel.com Signed-off-by: Anatoly Burakov --- lib/librte_eal/common/eal_common_memory.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c index 24a9ed5..68fc70e 100644 --- a/lib/librte_eal/common/eal_common_memory.c +++ b/lib/librte_eal/common/eal_common_memory.c @@ -205,7 +205,8 @@ memseg_primary_init_32(void) { struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; int active_sockets, hpi_idx, msl_idx = 0; - unsigned int socket_id, i; + unsigned int i; + int socket_id; struct rte_memseg_list *msl; uint64_t extra_mem_per_socket, total_extra_mem, total_requested_mem; uint64_t max_mem; @@ -238,6 +239,11 @@ memseg_primary_init_32(void) uint64_t mem; socket_id = rte_socket_id_by_idx(i); + if (socket_id < 0) { + RTE_LOG(ERR, EAL, "Invalid socket index: %u\n", + i); + continue; + } mem = internal_config.socket_mem[socket_id]; if (mem == 0) @@ -281,6 +287,10 @@ memseg_primary_init_32(void) bool skip; socket_id = rte_socket_id_by_idx(i); + if (socket_id < 0) { + RTE_LOG(ERR, EAL, "Invalid socket index: %u\n", i); + continue; + } #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES if (socket_id > 0) @@ -294,10 +304,11 @@ memseg_primary_init_32(void) * socket, and this is not master lcore */ master_lcore_socket = rte_lcore_to_socket_id(cfg->master_lcore); - skip |= active_sockets == 0 && socket_id != master_lcore_socket; + skip |= active_sockets == 0 && + (unsigned int)socket_id != master_lcore_socket; if (skip) { - RTE_LOG(DEBUG, EAL, "Will not preallocate memory on socket %u\n", + RTE_LOG(DEBUG, EAL, "Will not preallocate memory on socket %i\n", socket_id); continue; } -- 2.7.4