mem: fix use after free in legacy mem init

Message ID e6f96c0a1a26b2c73e19ef6f9be55a12f87f190e.1541513401.git.anatoly.burakov@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series mem: fix use after free in legacy mem init |

Checks

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

Commit Message

Burakov, Anatoly Nov. 6, 2018, 2:13 p.m. UTC
  Adding an additional failure path in DMA mask check has exposed an
issue where `hugepage` pointer may point to memory that has already
been unmapped, but pointer value is still not NULL, so failure
handler will attempt to unmap it second time if DMA mask check
fails. Fix it by setting `hugepage` pointer to NULL once it is no
longer needed.

Coverity ID: 325730

Fixes: 165c89b84538 ("mem: use DMA mask check for legacy memory")
Cc: alejandro.lucero@netronome.com

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Thomas Monjalon Nov. 6, 2018, 11:08 p.m. UTC | #1
06/11/2018 15:13, Anatoly Burakov:
> Adding an additional failure path in DMA mask check has exposed an
> issue where `hugepage` pointer may point to memory that has already
> been unmapped, but pointer value is still not NULL, so failure
> handler will attempt to unmap it second time if DMA mask check
> fails. Fix it by setting `hugepage` pointer to NULL once it is no
> longer needed.
> 
> Coverity ID: 325730
> 
> Fixes: 165c89b84538 ("mem: use DMA mask check for legacy memory")
> Cc: alejandro.lucero@netronome.com
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index c1b5e0791..48b23ce19 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1617,6 +1617,7 @@  eal_legacy_hugepage_init(void)
 	tmp_hp = NULL;
 
 	munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
+	hugepage = NULL;
 
 	/* we're not going to allocate more pages, so release VA space for
 	 * unused memseg lists