[dpdk-dev] memory: fix segfault on rte_mem_virt2memseg() call with invalid addr

Message ID 1527859375-160704-1-git-send-email-dariuszx.stojaczyk@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Stojaczyk, DariuszX June 1, 2018, 1:22 p.m. UTC
  When trying to use it with an address that's not
managed by DPDK it would segfault due to a missing
check. The doc says this function returns either
a pointer or NULL, so let it do so.

Change-Id: Ib292f148914e67054f5d7b664077f19cba7000e4
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
---
 lib/librte_eal/common/eal_common_memory.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Anatoly Burakov June 1, 2018, 10:50 a.m. UTC | #1
On 01-Jun-18 2:22 PM, Dariusz Stojaczyk wrote:
> When trying to use it with an address that's not
> managed by DPDK it would segfault due to a missing
> check. The doc says this function returns either
> a pointer or NULL, so let it do so.
> 
> Change-Id: Ib292f148914e67054f5d7b664077f19cba7000e4
> Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
> ---

Generally speaking, if the commit is a bugfix, reference to the original 
commit that introduces the issue should be part of the commit message. 
See DPDK contribution guidelines [1] and "git fixline" [2].

[1] http://dpdk.org/doc/guides/contributing/patches.html
[2] http://dpdk.org/dev

Change-Id: is probably a leftover from Gerrit, this shouldn't be part of 
the commit message.

On the substance of the patch itself:

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  

Patch

diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index 4f0688f..ecc5bb2 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -536,6 +536,9 @@  virt2memseg(const void *addr, const struct rte_memseg_list *msl)
 	void *start, *end;
 	int ms_idx;
 
+	if (msl == NULL)
+		return NULL;
+
 	/* a memseg list was specified, check if it's the right one */
 	start = msl->base_va;
 	end = RTE_PTR_ADD(start, (size_t)msl->page_sz * msl->memseg_arr.len);