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

* Re: [PATCH] dump read-only anonymous memory in core files
  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
  0 siblings, 2 replies; 4+ messages in thread
From: Linus Torvalds @ 2003-10-07  9:06 UTC (permalink / raw)
  To: Roland McGrath; +Cc: Andrew Morton, Linux Kernel Mailing List


What about shared mappings (that test should be VM_MAYSHARE)?

My inclination would be to not dump them if they are backed by a file, 
even if the mmap is writable.

Also, the VM_WRITE test should possibly be VM_MAYWRITE, since the thing
could have been mprotect()'ed. Alternatively, we could really add a "this
mapping has been writable" flag (a kind of "sticky VM_WRITE" bit). It's
only mprotect that can do this, anyway.

Ehh?

Which would make the logic be something like

	/* Do not dump I/O mapped devices! -DaveM */
	if (vma->vm_flags & VM_IO)
		return 0;

	/* file-backed mapping? */
	if (vma->vm_file) {
		if (vma->vm_flags & VM_MAYSHARE)
			return 0;
		if (!(vma->vm_flags & VM_MAYWRITE))
			return 0;
	}

	return 1;

Hmm?

		Linus


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

* Re: [PATCH] dump read-only anonymous memory in core files
  2003-10-07  9:06 ` Linus Torvalds
@ 2003-10-07 14:33   ` Dave McCracken
  2003-10-07 19:07   ` Roland McGrath
  1 sibling, 0 replies; 4+ messages in thread
From: Dave McCracken @ 2003-10-07 14:33 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Roland McGrath, Andrew Morton, Linux Kernel Mailing List


--On Tuesday, October 07, 2003 02:06:34 -0700 Linus Torvalds
<torvalds@osdl.org> wrote:

> What about shared mappings (that test should be VM_MAYSHARE)?
> 
> My inclination would be to not dump them if they are backed by a file, 
> even if the mmap is writable.

All shared areas are 'file backed' but some of them are only backed by
shmfs.  I think we should at least dump those areas since they can't be
retrieved later.  I agree it'd be reasonable to not dump areas backed by
real files, but it'd require a simple way to distinguish them from
shmfs-backed areas.

Dave McCracken

======================================================================
Dave McCracken          IBM Linux Base Kernel Team      1-512-838-3059
dmccr@us.ibm.com                                        T/L   678-3059


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

* Re: [PATCH] dump read-only anonymous memory in core files
  2003-10-07  9:06 ` Linus Torvalds
  2003-10-07 14:33   ` Dave McCracken
@ 2003-10-07 19:07   ` Roland McGrath
  1 sibling, 0 replies; 4+ messages in thread
From: Roland McGrath @ 2003-10-07 19:07 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Andrew Morton, Linux Kernel Mailing List

> 
> What about shared mappings (that test should be VM_MAYSHARE)?
> 
> My inclination would be to not dump them if they are backed by a file, 
> even if the mmap is writable.

That sounds reasonable to me (perhaps modulo the shmfs issue).  I intended
my patch not to omit any vmas that were dumped before, so I didn't consider
omitting any writable areas.  (I don't really understand the difference
between VM_MAYSHARE and VM_SHARED, so I might be assuming something wrong
when saying you are right.)

> Also, the VM_WRITE test should possibly be VM_MAYWRITE, since the thing
> could have been mprotect()'ed. Alternatively, we could really add a "this
> mapping has been writable" flag (a kind of "sticky VM_WRITE" bit). It's
> only mprotect that can do this, anyway.

Actually the ideal would be "this mapping has been written to" (or might
have been, i.e. it at least was writable in a pte, if not actually dirty).
Then if you mmap some pages PROT_READ|PROT_WRITE, and then mprotect them
PROT_READ before ever touching them, you don't dump those pages just as you
wouldn't dump always-read-only pages.  (If you had that, you could apply it
to anonymous mappings as well and omit all zero-fill pages.)  Ideally this
would dump PROT_NONE pages that have been written in the past as well,
which is ruled out by the VM_READ test at the top of maydump.  Despite the
comment, it looks to me like dump_write's use of get_user_pages will make
it work, so it could be a VM_MAYREAD check. 


Thanks,
Roland

^ 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®