lkml.org 
[lkml]   [2003]   [Oct]   [7]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
DateTue, 7 Oct 2003 01:28:15 -0700
FromRoland McGrath <>
Subject[PATCH] dump read-only anonymous memory in core files
Currently core dumps omit all pages that are read-only at the time of the
dump.  I think that anonymous pages should be included even if read-only.
This patch makes that change.  Take for example this program:

	#include <sys/mman.h>
	#include <string.h>
	#include <unistd.h>

	int main ()
	{
	  const size_t pagesz = sysconf (_SC_PAGE_SIZE);
	  void *page = mmap (0, pagesz, PROT_READ|PROT_WRITE,
			     MAP_ANON|MAP_PRIVATE, -1, 0);
	  memset (page, 0x17, pagesz);
	  mprotect (page, pagesz, PROT_READ);
	  printf ("pid %d address %p size %x\n", getpid (),
		  page, (unsigned int) pagesz);
	  abort ();
	}
Without this change, the core dump will not include the `page' page--when
examining the dump, there will be no way to know it contains 0x17.  This is
obviously a contrived and useless example.  But such cases do exist in the
real world, e.g. garbage collectors that temporarily mprotect some pages to
read-only--in a core dump of such a process, knowing the contents of these
pages could be important.  With my change, that page appears in the dump.


Thanks,
Roland


Index: linux-2.6/fs/binfmt_elf.c
===================================================================
RCS file: /home/cvs/linux-2.5/fs/binfmt_elf.c,v
retrieving revision 1.57
diff -u -b -p -r1.57 binfmt_elf.c
--- linux-2.6/fs/binfmt_elf.c 3 Oct 2003 15:35:40 -0000 1.57
+++ linux-2.6/fs/binfmt_elf.c 7 Oct 2003 06:35:06 -0000
@@ -960,12 +960,13 @@ static int maydump(struct vm_area_struct
 	/* Do not dump I/O mapped devices! -DaveM */
 	if (vma->vm_flags & VM_IO)
 		return 0;
-#if 1
+	/* Dump anything writable.  */
 	if (vma->vm_flags & (VM_WRITE|VM_GROWSUP|VM_GROWSDOWN))
 		return 1;
-	if (vma->vm_flags & (VM_READ|VM_EXEC|VM_EXECUTABLE|VM_SHARED))
+	/* Don't dump unwritable segments mapped from files.  */
+	if (vma->vm_file != NULL)
 		return 0;
-#endif
+	/* Dump everything else.  */
 	return 1;
 }
 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 13:49    [from the cache]
©2003-2008