From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stable-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 49077A034F
	for <public@inbox.dpdk.org>; Mon, 21 Feb 2022 11:20:05 +0100 (CET)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 3D0A6410F0;
	Mon, 21 Feb 2022 11:20:05 +0100 (CET)
Received: from mga17.intel.com (mga17.intel.com [192.55.52.151])
 by mails.dpdk.org (Postfix) with ESMTP id D8F894013F;
 Mon, 21 Feb 2022 11:20:01 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1645438802; x=1676974802;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=ylx1U1StRiM5pYZ4KClOZXIMptYFu4ACwgsl33TyzjA=;
 b=LwdnNlPvQ04MemHOulU2numzQdh1HSASXM+nsuiLNp04GYoFSHO3RcTw
 dJD0qDPGR7MrYdkHED3uJlwj+YF3amy45RtaxczQrXFv1u1PyXXHLYB/j
 EwOwqUThXzVCXNXTN+saYVWcq/Vm2oI432qivWaJTQD9EZMlTNQnx6yyb
 IbG61hMmzVWNi/VqWZCCxs9QuQN/JODsOCwuElf/3fwfooF7Lrzl4Ho8/
 bzAG9pFprDXopjG8NXvAGWi00FB069OlN3iLQQkHLsMCGLjgwzHAQZk0f
 P82h18m3fu1TjZHYPQVrpV7LLOwOiuJb0BstMrH/E57cHVtUAfHBXVVnc A==;
X-IronPort-AV: E=McAfee;i="6200,9189,10264"; a="232102410"
X-IronPort-AV: E=Sophos;i="5.88,385,1635231600"; d="scan'208";a="232102410"
Received: from orsmga006.jf.intel.com ([10.7.209.51])
 by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 21 Feb 2022 02:19:54 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.88,385,1635231600"; d="scan'208";a="507587981"
Received: from silpixa00401214.ir.intel.com ([10.55.129.112])
 by orsmga006.jf.intel.com with ESMTP; 21 Feb 2022 02:19:53 -0800
From: Reshma Pattan <reshma.pattan@intel.com>
To: dev@dpdk.org
Cc: stephen@networkplumber.org, ferruh.yigit@intel.com,
 Reshma Pattan <reshma.pattan@intel.com>, vipin.varghese@intel.com,
 stable@dpdk.org
Subject: [PATCH v2] app/pdump: check lcore is not the maximum core
Date: Mon, 21 Feb 2022 10:19:44 +0000
Message-Id: <20220221101944.4216-1-reshma.pattan@intel.com>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20220218151841.116135-1-reshma.pattan@intel.com>
References: <20220218151841.116135-1-reshma.pattan@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
Errors-To: stable-bounces@dpdk.org

Check lcore id value is not the maximum core supported.
Using lcore id without this check might cause
out of bound access inside the rte_eal_wait_lcore.

Coverity issue: 375841
Fixes: b2854d5317e8 ("app/pdump: support multi-core capture")
Cc: vipin.varghese@intel.com
Cc: stable@dpdk.org

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
 app/pdump/main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 04a38e8911..7677a5f8f5 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -930,12 +930,15 @@ dump_packets(void)
 		return;
 	}
 
-	lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
 
 	for (i = 0; i < num_tuples; i++) {
+		lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
+		if (lcore_id == RTE_MAX_LCORE)
+			rte_exit(EXIT_FAILURE,
+				"Max core limit %u reached for packet capture", lcore_id);
+
 		rte_eal_remote_launch(dump_packets_core,
 				&pdump_t[i], lcore_id);
-		lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
 
 		if (rte_eal_wait_lcore(lcore_id) < 0)
 			rte_exit(EXIT_FAILURE, "failed to wait\n");
-- 
2.27.0