소스 검색

libdl: first execute all destructors, then munmap library

Fix problem which might exist since 2011. We need to execute
the destructors for all dependant libraries, before munmap the
shared libraries, otherwise running destructor of a dependent library
might cause a segfault, trying to access an already unmapped memory.

This fixes for example segfaults while running php -m with ldap
module.

Reported-By: Dave Flogeras <dflogeras2@gmail.com>
Tested-By: Dave Flogeras <dflogeras2@gmail.com>
Waldemar Brodkorb 7 년 전
부모
커밋
14be0795f4
1개의 변경된 파일5개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      ldso/libdl/libdl.c

+ 5 - 0
ldso/libdl/libdl.c

@@ -849,7 +849,12 @@ static int do_dlclose(void *vhandle, int need_fini)
 					DL_CALL_FUNC_AT_ADDR (dl_elf_fini, tpnt->loadaddr, (int (*)(void)));
 				}
 			}
+		}
+	}
 
+	for (j = 0; j < handle->init_fini.nlist; ++j) {
+		tpnt = handle->init_fini.init_fini[j];
+		if (tpnt->usage_count == 0) {
 			_dl_if_debug_print("unmapping: %s\n", tpnt->libname);
 			end = 0;
 			for (i = 0, ppnt = tpnt->ppnt;