From 2fb8c6371ba29e8dd457e090edd5274efc8bed5a Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 2 Feb 2022 09:07:58 +0300 Subject: Discard sections with pseudo-paths except heap in register_map_entries If USE_PROC_FOR_LIBRARIES, this commit prevents addition of special writable sections (from proc maps) like stacks. * dyn_load.c [(SCO_ELF || DGUX || HURD || NACL || __ELF__ && (LINUX || FREEBSD || NETBSD || OPENBSD)) && USE_PROC_FOR_LIBRARIES] (GC_register_map_entries): Declare path local variable and pass it to GC_parse_map_entry; discard writable section if its path (mapping name) starts with '[' but does not match "[heap]". --- dyn_load.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'dyn_load.c') diff --git a/dyn_load.c b/dyn_load.c index 82aec824..f14242f9 100644 --- a/dyn_load.c +++ b/dyn_load.c @@ -309,7 +309,7 @@ static void sort_heap_sects(struct HeapSect *base, size_t number_of_elements) STATIC void GC_register_map_entries(const char *maps) { - const char *prot; + const char *prot, *path; ptr_t start, end; unsigned int maj_dev; ptr_t least_ha, greatest_ha; @@ -322,7 +322,7 @@ STATIC void GC_register_map_entries(const char *maps) + GC_our_memory[GC_n_memory-1].hs_bytes; for (;;) { - maps = GC_parse_map_entry(maps, &start, &end, &prot, &maj_dev, 0); + maps = GC_parse_map_entry(maps, &start, &end, &prot, &maj_dev, &path); if (NULL == maps) break; if (prot[1] == 'w') { @@ -334,6 +334,9 @@ STATIC void GC_register_map_entries(const char *maps) /* Stack mapping; discard */ continue; } + if (path[0] == '[' && strncmp(path+1, "heap]", 5) != 0) + continue; /* discard if a pseudo-path unless "[heap]" */ + # ifdef THREADS /* This may fail, since a thread may already be */ /* unregistered, but its thread stack may still be there. */ -- cgit v1.2.1