From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DCC0CA0C5E for ; Thu, 4 Nov 2021 22:58:59 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B5152427A1; Thu, 4 Nov 2021 22:58:58 +0100 (CET) Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by mails.dpdk.org (Postfix) with ESMTP id 329E342757 for ; Thu, 4 Nov 2021 22:58:57 +0100 (CET) Received: by mail-pl1-f178.google.com with SMTP id s24so9638332plp.0 for ; Thu, 04 Nov 2021 14:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version; bh=Kl1Y+3qHw+QJuz7dPTVC2xaGWSNbP722yrFNyLCYfFU=; b=eqbSLKFbYV9aPdZlMIhlpjJlvsJ+0wrxpEprOo8wGJiMDBkaAXS/dEGK0K0cYhhyhC WNewfBtEvd3a8kUJPh7o1sS7qsvmyZIzV8AXtWVzHffbfIxLQDRxEu4wfRiKCJd4UhV5 dIFI6JzlHvoU5tzFBwrWYG3hKZ4y0o01DdNq4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version; bh=Kl1Y+3qHw+QJuz7dPTVC2xaGWSNbP722yrFNyLCYfFU=; b=bYo1VIzitGLX1LLY6UE0cHf8bPMl4rjCsTSvM5on0ahUl6DfK3Qwtahy0LHyZTfDXL s3k1aAduqysi8pWmd4qLRONLIKENgTPYP0ZKyHgaFDM9/gglgIb0Tg1OCbIkOlvE2d93 C8O8UaoIl9uBoXxhKKGwQad/4telRHy76ts9QEKrhMQJO2WCh7xIkvft5xmiRE/U9386 HT5qgHxHAUZzRx69E3lri9IJY0njHT6KBaOLKvowXeWBJ4SRHeZT5GuXoQuMbe4FLLLC szVFQ7MxeQFeLQ+qZ0wovO2jtl8bDDHpDM8VV4F+E420fTvgnivEUKXHDXBqQF68scgJ 4mJQ== X-Gm-Message-State: AOAM533O/W7TdqNO6CXeQiZB2VbaEMjY/QypKP2/UBHq+/v3CGFn8qZX tgq4dL7wVRlXqIPPPy0Y1YT1Hw== X-Google-Smtp-Source: ABdhPJzYeu38hVrWdHjKgG4rReAAzsCH2D4+6KilprVEpICLTLja+MRoat10cxSMCakygYk/lILZGA== X-Received: by 2002:a17:90a:1f8a:: with SMTP id x10mr25768531pja.215.1636063136478; Thu, 04 Nov 2021 14:58:56 -0700 (PDT) Received: from C02GC2QQMD6T.wifi.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id pg5sm8532242pjb.26.2021.11.04.14.58.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Nov 2021 14:58:56 -0700 (PDT) From: Ajit Khaparde To: dev@dpdk.org Cc: Kishore Padmanabha , stable@dpdk.org, Venkat Duvvuru , Mike Baucom , Randy Schacher Date: Thu, 4 Nov 2021 14:58:27 -0700 Message-Id: <20211104215846.58672-4-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20211104215846.58672-1-ajit.khaparde@broadcom.com> References: <20211103005251.25524-1-ajit.khaparde@broadcom.com> <20211104215846.58672-1-ajit.khaparde@broadcom.com> MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="000000000000180b1a05cffda241" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [dpdk-stable] [PATCH v5 03/22] net/bnxt: fix out of bounds issue in hash list X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" --000000000000180b1a05cffda241 Content-Transfer-Encoding: 8bit From: Kishore Padmanabha The number of hash bucket list calculation is fixed. Added check to avoid the out of bounds condition. Fixes: 0001cc58d362 ("net/bnxt: support generic hash table") Cc: stable@dpdk.org Signed-off-by: Kishore Padmanabha Signed-off-by: Venkat Duvvuru Reviewed-by: Mike Baucom Reviewed-by: Randy Schacher Reviewed-by: Ajit Khaparde --- drivers/net/bnxt/tf_ulp/ulp_gen_hash.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/net/bnxt/tf_ulp/ulp_gen_hash.c b/drivers/net/bnxt/tf_ulp/ulp_gen_hash.c index 3c6e7fe924..84c83de35c 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_gen_hash.c +++ b/drivers/net/bnxt/tf_ulp/ulp_gen_hash.c @@ -16,20 +16,21 @@ int32_t ulp_bit_alloc_list_alloc(struct bit_alloc_list *blist, { uint64_t bentry; uint32_t idx = 0, jdx = 0; + uint32_t bsize_64 = blist->bsize / ULP_64B_IN_BYTES; /* Iterate all numbers that have all 1's */ do { bentry = blist->bdata[idx++]; - } while (bentry == -1UL && idx < blist->bsize); + } while (bentry == -1UL && idx <= bsize_64); - if (idx < blist->bsize) { + if (idx <= bsize_64) { if (bentry) jdx = __builtin_clzl(~bentry); *index = ((idx - 1) * ULP_INDEX_BITMAP_SIZE) + jdx; ULP_INDEX_BITMAP_SET(blist->bdata[(idx - 1)], jdx); return 0; } - jdx = (uint32_t)(blist->bsize * ULP_INDEX_BITMAP_SIZE); + jdx = (uint32_t)(bsize_64 * ULP_INDEX_BITMAP_SIZE); BNXT_TF_DBG(ERR, "bit allocator is full reached max:%x\n", jdx); return -1; } @@ -39,9 +40,10 @@ int32_t ulp_bit_alloc_list_dealloc(struct bit_alloc_list *blist, uint32_t index) { uint32_t idx = 0, jdx; + uint32_t bsize_64 = blist->bsize / ULP_64B_IN_BYTES; idx = index / ULP_INDEX_BITMAP_SIZE; - if (idx >= blist->bsize) { + if (idx >= bsize_64) { BNXT_TF_DBG(ERR, "invalid bit index %x:%x\n", idx, blist->bsize); return -EINVAL; @@ -127,7 +129,8 @@ ulp_gen_hash_tbl_list_init(struct ulp_hash_create_params *cparams, hash_tbl->hash_mask = size - 1; /* allocate the memory for the bit allocator */ - size = (cparams->num_key_entries / sizeof(uint64_t)) + 1; + size = (cparams->num_key_entries / sizeof(uint64_t)); + size = ULP_BYTE_ROUND_OFF_8(size); hash_tbl->bit_list.bsize = size; hash_tbl->bit_list.bdata = rte_zmalloc("Generic hash bit alloc", size, ULP_BUFFER_ALIGN_64_BYTE); @@ -311,7 +314,12 @@ ulp_gen_hash_tbl_list_add(struct ulp_gen_hash_tbl *hash_tbl, BNXT_TF_DBG(ERR, "Error in bit list alloc\n"); return -ENOMEM; } - + if (key_index > hash_tbl->num_key_entries) { + BNXT_TF_DBG(ERR, "reached max size %u:%u\n", key_index, + hash_tbl->num_key_entries); + ulp_bit_alloc_list_dealloc(&hash_tbl->bit_list, key_index); + return -ENOMEM; + } /* Update the hash entry */ ULP_HASH_BUCKET_MARK_INUSE(bucket, (uint16_t)key_index); -- 2.30.1 (Apple Git-130) --000000000000180b1a05cffda241--