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 2923DA0C4C for ; Wed, 3 Nov 2021 01:53:05 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2206141144; Wed, 3 Nov 2021 01:53:01 +0100 (CET) Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by mails.dpdk.org (Postfix) with ESMTP id 2A3624113F for ; Wed, 3 Nov 2021 01:53:00 +0100 (CET) Received: by mail-pj1-f53.google.com with SMTP id y14-20020a17090a2b4e00b001a5824f4918so220111pjc.4 for ; Tue, 02 Nov 2021 17:53:00 -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=9JHPgW3Zb/5LVBeFYw/2VbHF3kUx7XOTMRRisSIQPAg=; b=Q7dMH7Z+gLVFGTEjKzJBjut7nHKKelpJUmwkwBUaTApOZfeN5NM5XgHklKtjWjhslm TnoVKlmJNqBakSG6uZjCb5taxDm0bNkl7oRo3CVcu5wmUdk6ORTbYmzOgbq3wPoQw1Zr VBD+r+1TJ29ZDpsQ+kviabmLi3cr0+NTe2xYk= 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=9JHPgW3Zb/5LVBeFYw/2VbHF3kUx7XOTMRRisSIQPAg=; b=vEhLlGlL9YalVGX2GIW/74/LukENKVSIQv2TzGqnHIfZcUsy3MTaBel0RZF0nq7/VS ez18mSy0K/zS9LqVHzXA4E5UoktnaOhXVz1WdHcD9qO28BCbXRDrM5FjcyKkmz1TmP1D J8SG3w56vZD8JNb80oVgBaquWQn5sm56SRyVmLXMnTdDFv09syGYVWRA01Gq/jJRclwa MaFH/2+nt5Fpt9ptbvTyM7DG3eZkOf27Hrn2w9DHUT2L4HUJnK3fr3I4AqYdDCwqRw9b wmnYXgEqZaUew5VBjRYVW86jn3FB9NJ8thxj1z1Lsd6dzf1wNj+D3qkjIjY2Iv8YGgS+ nSkA== X-Gm-Message-State: AOAM532AYvK4kdp9hirlS58ILdMTKyBqMZLfDTFyVvmK/87+dM3UOGx/ egx1z/FUQkAmwLjCM31sqqunHg== X-Google-Smtp-Source: ABdhPJwkRZhgUaZC+S6UvZjjE4JMtbgRZmCiIUe1uRhvGpimKXpEgpYXFRXxmdleMah6LKeRzzrJkw== X-Received: by 2002:a17:90a:3488:: with SMTP id p8mr11259132pjb.114.1635900779408; Tue, 02 Nov 2021 17:52:59 -0700 (PDT) Received: from localhost.localdomain ([192.19.224.250]) by smtp.gmail.com with ESMTPSA id k2sm323450pfu.112.2021.11.02.17.52.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Nov 2021 17:52:58 -0700 (PDT) From: Ajit Khaparde To: dev@dpdk.org Cc: Kishore Padmanabha , stable@dpdk.org, Venkat Duvvuru , Mike Baucom , Randy Schacher Date: Tue, 2 Nov 2021 17:52:34 -0700 Message-Id: <20211103005251.25524-4-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20211103005251.25524-1-ajit.khaparde@broadcom.com> References: <20211102040556.7840-1-venkatkumar.duvvuru@broadcom.com> <20211103005251.25524-1-ajit.khaparde@broadcom.com> MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="000000000000db702705cfd7d49d" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [dpdk-stable] [PATCH v4 03/20] 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" --000000000000db702705cfd7d49d 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) --000000000000db702705cfd7d49d--