Commit b3a30410 authored by Roland McGrath's avatar Roland McGrath Committed by Linus Torvalds

[PATCH] Unbacked shared memory not included in ELF core dump

We're currently not including sysv shared memory segments in coredumps.

This patch intends to include any shared mapping whose target file has zero
links.  That covers sysv shm and MAP_ANON|MAP_SHARED mmap's (which I think
are only ever useful if you want to share pages with a fork'd child).  I
think it also covers a regular file that was unlinked but is still mmap'd. 
It doesn't cover mapping of a tmpfs file like /dev/shm/foo, but those are
still available to be seen after your program crashes, until reboot. 

Note that this still omits plenty of cases that the old code would include,
such as all writable shared mappings of regular files.  It also will
include some arcane cases the old one wouldn't, like a read-only shared
mapping of an unlinked file; that comes up e.g., for the text segment of a
shared library or executable that was removed/renamed-over while still in
use.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ecce8424
...@@ -1140,10 +1140,14 @@ static int dump_seek(struct file *file, off_t off) ...@@ -1140,10 +1140,14 @@ static int dump_seek(struct file *file, off_t off)
*/ */
static int maydump(struct vm_area_struct *vma) static int maydump(struct vm_area_struct *vma)
{ {
/* Do not dump I/O mapped devices, shared memory, or special mappings */ /* Do not dump I/O mapped devices or special mappings */
if (vma->vm_flags & (VM_IO | VM_SHARED | VM_RESERVED)) if (vma->vm_flags & (VM_IO | VM_RESERVED))
return 0; return 0;
/* Dump shared memory only if mapped from an anonymous file. */
if (vma->vm_flags & VM_SHARED)
return vma->vm_file->f_dentry->d_inode->i_nlink == 0;
/* If it hasn't been written to, don't write it out */ /* If it hasn't been written to, don't write it out */
if (!vma->anon_vma) if (!vma->anon_vma)
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment