From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 398EAA0512; Tue, 14 Jan 2020 18:18:41 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B28DF1C0DD; Tue, 14 Jan 2020 18:18:39 +0100 (CET) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 0857E1C033; Tue, 14 Jan 2020 18:18:37 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jan 2020 09:18:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,433,1574150400"; d="scan'208";a="256378801" Received: from silpixa00400072.ir.intel.com ([10.237.222.213]) by fmsmga002.fm.intel.com with ESMTP; 14 Jan 2020 09:18:35 -0800 From: Vladimir Medvedkin To: dev@dpdk.org Cc: vladimir.medvedkin@intel.com, stable@dpdk.org Date: Tue, 14 Jan 2020 17:18:32 +0000 Message-Id: <1579022312-396072-1-git-send-email-vladimir.medvedkin@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] fib: fix possible integer overflow 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" Coverity issue: 350596 Coverity issue: 350597 Fixes: c3e12e0f0354 ("fib: add dataplane algorithm for IPv6") Cc: vladimir.medvedkin@intel.com Cc: stable@dpdk.org Signed-off-by: Vladimir Medvedkin --- lib/librte_fib/trie.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/librte_fib/trie.c b/lib/librte_fib/trie.c index 124aa8b..2ae2add 100644 --- a/lib/librte_fib/trie.c +++ b/lib/librte_fib/trie.c @@ -240,9 +240,8 @@ tbl8_alloc(struct rte_trie_tbl *dp, uint64_t nh) tbl8_idx = tbl8_get(dp); if (tbl8_idx < 0) return tbl8_idx; - tbl8_ptr = (uint8_t *)dp->tbl8 + - ((tbl8_idx * TRIE_TBL8_GRP_NUM_ENT) << - dp->nh_sz); + tbl8_ptr = get_tbl_p_by_idx(dp->tbl8, + tbl8_idx * TRIE_TBL8_GRP_NUM_ENT, dp->nh_sz); /*Init tbl8 entries with nexthop from tbl24*/ write_to_dp((void *)tbl8_ptr, nh, dp->nh_sz, TRIE_TBL8_GRP_NUM_ENT); @@ -317,7 +316,7 @@ get_idx(const uint8_t *ip, uint32_t prev_idx, int bytes, int first_byte) bitshift = (int8_t)(((first_byte + bytes - 1) - i)*BYTE_SIZE); idx |= ip[i] << bitshift; } - return (prev_idx * 256) + idx; + return (prev_idx * TRIE_TBL8_GRP_NUM_ENT) + idx; } static inline uint64_t @@ -354,8 +353,8 @@ recycle_root_path(struct rte_trie_tbl *dp, const uint8_t *ip_part, return; if (common_tbl8 != 0) { - p = get_tbl_p_by_idx(dp->tbl8, (val >> 1) * 256 + *ip_part, - dp->nh_sz); + p = get_tbl_p_by_idx(dp->tbl8, (val >> 1) * + TRIE_TBL8_GRP_NUM_ENT + *ip_part, dp->nh_sz); recycle_root_path(dp, ip_part + 1, common_tbl8 - 1, p); } tbl8_recycle(dp, prev, val >> 1); @@ -388,7 +387,8 @@ build_common_root(struct rte_trie_tbl *dp, const uint8_t *ip, j = i; cur_tbl = dp->tbl8; } - *tbl = get_tbl_p_by_idx(cur_tbl, prev_idx * 256, dp->nh_sz); + *tbl = get_tbl_p_by_idx(cur_tbl, prev_idx * TRIE_TBL8_GRP_NUM_ENT, + dp->nh_sz); return 0; } @@ -411,8 +411,8 @@ write_edge(struct rte_trie_tbl *dp, const uint8_t *ip_part, uint64_t next_hop, return tbl8_idx; val = (tbl8_idx << 1)|TRIE_EXT_ENT; } - p = get_tbl_p_by_idx(dp->tbl8, (tbl8_idx * 256) + *ip_part, - dp->nh_sz); + p = get_tbl_p_by_idx(dp->tbl8, (tbl8_idx * + TRIE_TBL8_GRP_NUM_ENT) + *ip_part, dp->nh_sz); ret = write_edge(dp, ip_part + 1, next_hop, len - 1, edge, p); if (ret < 0) return ret; @@ -420,8 +420,8 @@ write_edge(struct rte_trie_tbl *dp, const uint8_t *ip_part, uint64_t next_hop, write_to_dp((uint8_t *)p + (1 << dp->nh_sz), next_hop << 1, dp->nh_sz, UINT8_MAX - *ip_part); } else { - write_to_dp(get_tbl_p_by_idx(dp->tbl8, tbl8_idx * 256, - dp->nh_sz), + write_to_dp(get_tbl_p_by_idx(dp->tbl8, tbl8_idx * + TRIE_TBL8_GRP_NUM_ENT, dp->nh_sz), next_hop << 1, dp->nh_sz, *ip_part); } tbl8_recycle(dp, &val, tbl8_idx); -- 2.7.4