hash: fix segfault by adding param name NULL check

Message ID 20230706152626.476775-1-conor.fogarty@intel.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series hash: fix segfault by adding param name NULL check |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch-unit-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Conor Fogarty July 6, 2023, 3:26 p.m. UTC
  Add NULL pointer check to params->name, which is later
copied into the hash datastructure. Without this check
the code segfaults on the strlcpy() of a NULL pointer.

Fixes: 48a399119619 ("hash: replace with cuckoo hash implementation")

Signed-off-by: Conor Fogarty <conor.fogarty@intel.com>

---
Cc: pablo.de.lara.guarch@intel.com
---
 lib/hash/rte_cuckoo_hash.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Vladimir Medvedkin March 1, 2024, 5:16 p.m. UTC | #1
+cc stable@

Acked-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>

чт, 6 июл. 2023 г. в 16:26, Conor Fogarty <conor.fogarty@intel.com>:

> Add NULL pointer check to params->name, which is later
> copied into the hash datastructure. Without this check
> the code segfaults on the strlcpy() of a NULL pointer.
>
> Fixes: 48a399119619 ("hash: replace with cuckoo hash implementation")
>
> Signed-off-by: Conor Fogarty <conor.fogarty@intel.com>
>
> ---
> Cc: pablo.de.lara.guarch@intel.com
> ---
>  lib/hash/rte_cuckoo_hash.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
> index d92a903bb3..0aab091c4d 100644
> --- a/lib/hash/rte_cuckoo_hash.c
> +++ b/lib/hash/rte_cuckoo_hash.c
> @@ -166,6 +166,7 @@ rte_hash_create(const struct rte_hash_parameters
> *params)
>         /* Check for valid parameters */
>         if ((params->entries > RTE_HASH_ENTRIES_MAX) ||
>                         (params->entries < RTE_HASH_BUCKET_ENTRIES) ||
> +                       (params->name == NULL) ||
>                         (params->key_len == 0)) {
>                 rte_errno = EINVAL;
>                 RTE_LOG(ERR, HASH, "rte_hash_create has invalid
> parameters\n");
> --
> 2.25.1
>
> --------------------------------------------------------------
> Intel Research and Development Ireland Limited
> Registered in Ireland
> Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
> Registered Number: 308263
>
>
> This e-mail and any attachments may contain confidential material for the
> sole
> use of the intended recipient(s). Any review or distribution by others is
> strictly prohibited. If you are not the intended recipient, please contact
> the
> sender and delete all copies.
>
>
  

Patch

diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
index d92a903bb3..0aab091c4d 100644
--- a/lib/hash/rte_cuckoo_hash.c
+++ b/lib/hash/rte_cuckoo_hash.c
@@ -166,6 +166,7 @@  rte_hash_create(const struct rte_hash_parameters *params)
 	/* Check for valid parameters */
 	if ((params->entries > RTE_HASH_ENTRIES_MAX) ||
 			(params->entries < RTE_HASH_BUCKET_ENTRIES) ||
+			(params->name == NULL) ||
 			(params->key_len == 0)) {
 		rte_errno = EINVAL;
 		RTE_LOG(ERR, HASH, "rte_hash_create has invalid parameters\n");