[v2,04/11] memzone: check result of malloc_elem_from_data

Message ID 20221121223208.1147154-5-okaya@kernel.org (mailing list archive)
State Superseded, archived
Headers
Series codeql fixes for various subsystems |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Sinan Kaya Nov. 21, 2022, 10:32 p.m. UTC
  From: Sinan Kaya <okaya@kernel.org>

In memzone_reserve_aligned_thread_unsafe result of call
to malloc_elem_from_data is dereferenced here and may be null.

Signed-off-by: Sinan Kaya <okaya@kernel.org>
---
 lib/eal/common/eal_common_memzone.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Dmitry Kozlyuk Nov. 22, 2022, 3:52 p.m. UTC | #1
2022-11-21 17:32 (UTC-0500), okaya@kernel.org:
> From: Sinan Kaya <okaya@kernel.org>
> 
> In memzone_reserve_aligned_thread_unsafe result of call
> to malloc_elem_from_data is dereferenced here and may be null.
> 
> Signed-off-by: Sinan Kaya <okaya@kernel.org>

Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
  

Patch

diff --git a/lib/eal/common/eal_common_memzone.c b/lib/eal/common/eal_common_memzone.c
index 8d472505eb..930fee5fdc 100644
--- a/lib/eal/common/eal_common_memzone.c
+++ b/lib/eal/common/eal_common_memzone.c
@@ -169,6 +169,10 @@  memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,
 	}
 
 	struct malloc_elem *elem = malloc_elem_from_data(mz_addr);
+	if (elem == NULL) {
+		rte_errno = ENOSPC;
+		return NULL;
+	}
 
 	/* fill the zone in config */
 	mz_idx = rte_fbarray_find_next_free(arr, 0);