vppinfra: fix SIGSEGV in clib_mem_vm_unmap 78/33078/3
authorchenqijun <chenqijun@corp.netease.com>
Mon, 12 Jul 2021 02:51:05 +0000 (10:51 +0800)
committerDamjan Marion <dmarion@me.com>
Tue, 13 Jul 2021 16:50:59 +0000 (16:50 +0000)
while one mprotect PROT_NONE on hdr->next or hdr->prev,
the other one with the PROT_NONE is unmap at the same time,
cause SIGSEGV.

Type: fix

Signed-off-by: arikachen <eaglesora@gmail.com>
Change-Id: I21c0497da140c9654b566e47f767a90346715ed8

src/vppinfra/linux/mem.c

index cb46df8..036890f 100644 (file)
@@ -513,14 +513,13 @@ clib_mem_vm_unmap (void *base)
   uword size, sys_page_sz = 1ULL << mm->log2_page_sz;
   clib_mem_vm_map_hdr_t *hdr = base - sys_page_sz;;
 
+  map_lock ();
   if (mprotect (hdr, sys_page_sz, PROT_READ | PROT_WRITE) != 0)
-    return CLIB_MEM_ERROR;
+    goto out;
 
   size = hdr->num_pages << hdr->log2_page_sz;
   if (munmap ((void *) hdr->base_addr, size) != 0)
-    return CLIB_MEM_ERROR;
-
-  map_lock ();
+    goto out;
 
   if (hdr->next)
     {
@@ -546,6 +545,9 @@ clib_mem_vm_unmap (void *base)
     return CLIB_MEM_ERROR;
 
   return 0;
+out:
+  map_unlock ();
+  return CLIB_MEM_ERROR;
 }
 
 __clib_export void