From patchwork Wed Sep 20 07:47:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slawomir Mrozowicz X-Patchwork-Id: 28975 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 B70CB9FE; Wed, 20 Sep 2017 09:49:16 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 0DC06968; Wed, 20 Sep 2017 09:49:14 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Sep 2017 00:49:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,420,1500966000"; d="scan'208";a="137406243" Received: from unknown (HELO Sent) ([10.103.102.77]) by orsmga002.jf.intel.com with SMTP; 20 Sep 2017 00:49:10 -0700 Received: by Sent (sSMTP sendmail emulation); Wed, 20 Sep 2017 09:47:39 +0200 From: Slawomir Mrozowicz To: john.mcnamara@intel.com Cc: dev@dpdk.org, Slawomir Mrozowicz , ian.betts@intel.com, stable@dpdk.org Date: Wed, 20 Sep 2017 09:47:34 +0200 Message-Id: <1505893654-25460-1-git-send-email-slawomirx.mrozowicz@intel.com> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH] examples/performance-thread: fix out-of-bounds read 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" Overrunning array schedcore of 128 8-byte elements at element index 128 using index lcore_id. Fixed by correct check index lcoreid condition and change type of lcoreid to unsigned. Coverity issue: 143459 Fixes: 116819b9ed0d ("examples/performance-thread: add lthread subsystem") Cc: ian.betts@intel.com Cc: stable@dpdk.org Signed-off-by: Slawomir Mrozowicz Acked-by: Michal Jastrzebski --- examples/performance-thread/common/lthread.h | 2 +- examples/performance-thread/common/lthread_sched.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/performance-thread/common/lthread.h b/examples/performance-thread/common/lthread.h index 5c2c1a5f0..0cde5919b 100644 --- a/examples/performance-thread/common/lthread.h +++ b/examples/performance-thread/common/lthread.h @@ -87,7 +87,7 @@ int _lthread_desched_sleep(struct lthread *lt); void _lthread_free(struct lthread *lt); -struct lthread_sched *_lthread_sched_get(int lcore_id); +struct lthread_sched *_lthread_sched_get(unsigned int lcore_id); struct lthread_stack *_stack_alloc(void); diff --git a/examples/performance-thread/common/lthread_sched.c b/examples/performance-thread/common/lthread_sched.c index 98291478e..3484387b4 100644 --- a/examples/performance-thread/common/lthread_sched.c +++ b/examples/performance-thread/common/lthread_sched.c @@ -562,11 +562,14 @@ void lthread_run(void) * Return the scheduler for this lcore * */ -struct lthread_sched *_lthread_sched_get(int lcore_id) +struct lthread_sched *_lthread_sched_get(unsigned int lcore_id) { - if (lcore_id > LTHREAD_MAX_LCORES) - return NULL; - return schedcore[lcore_id]; + struct lthread_sched *res = NULL; + + if (lcore_id < LTHREAD_MAX_LCORES) + res = schedcore[lcore_id]; + + return res; } /*