From: Roland McGrath <roland@redhat.com>
To: Andrew Morton <akpm@osdl.org>, Linus Torvalds <torvalds@osdl.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] dump read-only anonymous memory in core files
Date: Tue, 7 Oct 2003 01:28:15 -0700 [thread overview]
Message-ID: <200310070828.h978SFQO028412@magilla.sf.frob.com> (raw)
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;
}
next reply other threads:[~2003-10-07 8:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-07 8:28 Roland McGrath [this message]
2003-10-07 9:06 ` Linus Torvalds
2003-10-07 14:33 ` Dave McCracken
2003-10-07 19:07 ` Roland McGrath
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200310070828.h978SFQO028412@magilla.sf.frob.com \
--to=roland@redhat.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®