From patchwork Mon Oct 19 11:52:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Savinay Dharmappa X-Patchwork-Id: 81358 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6AB6DA04DC; Mon, 19 Oct 2020 13:52:29 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8BF51C9B0; Mon, 19 Oct 2020 13:52:27 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id D9326C822 for ; Mon, 19 Oct 2020 13:52:24 +0200 (CEST) IronPort-SDR: 7374a8UonUQ1A/JDUg5Qql+MqdkayBso7DYyO2P6jo8EsR1lutCJWtpXk5X+h8o7w5zbe2SWwJ enen8lLgpdrg== X-IronPort-AV: E=McAfee;i="6000,8403,9778"; a="163527300" X-IronPort-AV: E=Sophos;i="5.77,394,1596524400"; d="scan'208";a="163527300" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2020 04:52:22 -0700 IronPort-SDR: pAY21l6iS8IoTcdPIz8vh1Mi9YWSHA3LuGoKJmMrHLxogZqraE011GegfqiJwarvpePIeOwbpc 6QX1YskCeM9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,394,1596524400"; d="scan'208";a="521977125" Received: from silpixa00400629.ir.intel.com ([10.237.214.112]) by fmsmga006.fm.intel.com with ESMTP; 19 Oct 2020 04:52:21 -0700 From: Savinay Dharmappa To: cristian.dumitrescu@intel.com, jasvinder.singh@intel.com, dev@dpdk.org Cc: savinay.dharmappa@intel.com Date: Mon, 19 Oct 2020 12:52:16 +0100 Message-Id: <20201019115216.96981-1-savinay.dharmappa@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201019105004.76433-1-savinay.dharmappa@intel.com> References: <20201019105004.76433-1-savinay.dharmappa@intel.com> Subject: [dpdk-dev] [PATCH v2] net/softnic: fix out of bound access 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 patch fixes out of bound access of an array. Coverity issue: 363466, 363459 Fixes: b5dfa6703d49 ("net/softnic: update subport rate dynamically") Signed-off-by: Savinay Dharmappa Acked-by: Cristian Dumitrescu --- v2: addressed review comments of v1 --- drivers/net/softnic/rte_eth_softnic_tm.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/softnic/rte_eth_softnic_tm.c b/drivers/net/softnic/rte_eth_softnic_tm.c index 725b0231ae..90baba15ce 100644 --- a/drivers/net/softnic/rte_eth_softnic_tm.c +++ b/drivers/net/softnic/rte_eth_softnic_tm.c @@ -1147,10 +1147,15 @@ update_subport_tc_rate(struct rte_eth_dev *dev, struct tm_node *ns = np->parent_node; uint32_t subport_id = tm_node_subport_id(dev, ns); struct tm_params *t = &p->soft.tm.params; - uint32_t subport_profile_id = t->subport_to_profile[subport_id]; + uint32_t subport_profile_id; struct tm_shaper_profile *sp_old = tm_shaper_profile_search(dev, ss->shaper_profile_id); + if (subport_id >= TM_MAX_SUBPORT_PROFILE) + return -1; + + subport_profile_id = t->subport_to_profile[subport_id]; + /* Derive new subport configuration. */ memcpy(&subport_profile, &p->soft.tm.params.subport_profile[subport_profile_id], @@ -2370,6 +2375,9 @@ subport_profile_get(struct rte_eth_dev *dev, struct tm_node *np) struct tm_params *t = &p->soft.tm.params; uint32_t subport_id = tm_node_subport_id(dev, np->parent_node); + if (subport_id >= TM_MAX_SUBPORT_PROFILE) + return NULL; + return &t->subport_profile[subport_id]; } @@ -3024,6 +3032,9 @@ update_subport_rate(struct rte_eth_dev *dev, struct rte_sched_subport_profile_params profile1; uint32_t subport_profile_id; + if (profile0 == NULL) + return -1; + /* Derive new pipe profile. */ memcpy(&profile1, profile0, sizeof(profile1)); profile1.tb_rate = sp->params.peak.rate;