mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dump read-only anonymous memory in core files
@ 2003-10-07  8:28 Roland McGrath
  2003-10-07  9:06 ` Linus Torvalds
  0 siblings, 1 reply; 4+ messages in thread
From: Roland McGrath @ 2003-10-07  8:28 UTC (permalink / raw)
  To: Andrew Morton, Linus Torvalds; +Cc: Linux Kernel Mailing List

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;
 }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-10-07 19:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-07  8:28 [PATCH] dump read-only anonymous memory in core files Roland McGrath
2003-10-07  9:06 ` Linus Torvalds
2003-10-07 14:33   ` Dave McCracken
2003-10-07 19:07   ` Roland McGrath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®