From patchwork Fri Jul 6 13:21:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remy Horton X-Patchwork-Id: 42510 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3E3891BEB2; Fri, 6 Jul 2018 15:21:24 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 63F361BEA2 for ; Fri, 6 Jul 2018 15:21:22 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2018 06:21:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,316,1526367600"; d="scan'208";a="64907830" Received: from rhorton-mobl1.ger.corp.intel.com (HELO FC23.ir.intel.com) ([163.33.178.248]) by orsmga003.jf.intel.com with ESMTP; 06 Jul 2018 06:21:20 -0700 From: Remy Horton To: dev@dpdk.org Date: Fri, 6 Jul 2018 14:21:19 +0100 Message-Id: <20180706132119.9013-1-remy.horton@intel.com> X-Mailer: git-send-email 2.9.5 Subject: [dpdk-dev] [PATCH v1] lib/metrics: add check for invalid metric keys 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 patchset adds a check to rte_metrics_update_values() that prevents the updating of metrics when presented with an invalid metric key. Previously, doing the latter could result in a crash. Fixes: 349950ddb9c5 ("metrics: add information metrics library") Signed-off-by: Remy Horton Acked-by: Ferruh Yigit --- lib/librte_metrics/rte_metrics.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/librte_metrics/rte_metrics.c b/lib/librte_metrics/rte_metrics.c index 258f058..b5638f5 100644 --- a/lib/librte_metrics/rte_metrics.c +++ b/lib/librte_metrics/rte_metrics.c @@ -159,6 +159,11 @@ rte_metrics_update_values(int port_id, stats = memzone->addr; rte_spinlock_lock(&stats->lock); + + if (key >= stats->cnt_stats) { + rte_spinlock_unlock(&stats->lock); + return -EINVAL; + } idx_metric = key; cnt_setsize = 1; while (idx_metric < stats->cnt_stats) {