coredump: add VM_NODUMP, MADV_NODUMP, MADV_CLEAR_NODUMP
authorJason Baron <jbaron@redhat.com>
Fri, 23 Mar 2012 22:02:51 +0000 (15:02 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 23 Mar 2012 23:58:42 +0000 (16:58 -0700)
Since we no longer need the VM_ALWAYSDUMP flag, let's use the freed bit
for 'VM_NODUMP' flag.  The idea is is to add a new madvise() flag:
MADV_DONTDUMP, which can be set by applications to specifically request
memory regions which should not dump core.

The specific application I have in mind is qemu: we can add a flag there
that wouldn't dump all of guest memory when qemu dumps core.  This flag
might also be useful for security sensitive apps that want to absolutely
make sure that parts of memory are not dumped.  To clear the flag use:
MADV_DODUMP.

[akpm@linux-foundation.org: s/MADV_NODUMP/MADV_DONTDUMP/, s/MADV_CLEAR_NODUMP/MADV_DODUMP/, per Roland]
[akpm@linux-foundation.org: fix up the architectures which broke]
Signed-off-by: Jason Baron <jbaron@redhat.com>
Acked-by: Roland McGrath <roland@hack.frob.com>
Cc: Chris Metcalf <cmetcalf@tilera.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
Cc: Helge Deller <deller@gmx.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/alpha/include/asm/mman.h
arch/mips/include/asm/mman.h
arch/parisc/include/asm/mman.h
arch/xtensa/include/asm/mman.h
fs/binfmt_elf.c
include/asm-generic/mman-common.h
include/linux/mm.h
mm/madvise.c

index 72db984..cbeb361 100644 (file)
 #define MADV_HUGEPAGE  14              /* Worth backing with hugepages */
 #define MADV_NOHUGEPAGE        15              /* Not worth backing with hugepages */
 
+#define MADV_DONTDUMP   16             /* Explicity exclude from the core dump,
+                                          overrides the coredump filter bits */
+#define MADV_DODUMP    17              /* Clear the MADV_NODUMP flag */
+
 /* compatibility flags */
 #define MAP_FILE       0
 
index 785b4ea..46d3da0 100644 (file)
 #define MADV_HUGEPAGE  14              /* Worth backing with hugepages */
 #define MADV_NOHUGEPAGE        15              /* Not worth backing with hugepages */
 
+#define MADV_DONTDUMP   16             /* Explicity exclude from the core dump,
+                                          overrides the coredump filter bits */
+#define MADV_DODUMP    17              /* Clear the MADV_NODUMP flag */
+
 /* compatibility flags */
 #define MAP_FILE       0
 
index f5b7bf5..12219eb 100644 (file)
 #define MADV_HUGEPAGE  67              /* Worth backing with hugepages */
 #define MADV_NOHUGEPAGE        68              /* Not worth backing with hugepages */
 
+#define MADV_DONTDUMP   69             /* Explicity exclude from the core dump,
+                                          overrides the coredump filter bits */
+#define MADV_DODUMP    70              /* Clear the MADV_NODUMP flag */
+
 /* compatibility flags */
 #define MAP_FILE       0
 #define MAP_VARIABLE   0
index 3078901..25bc6c1 100644 (file)
 #define MADV_HUGEPAGE  14              /* Worth backing with hugepages */
 #define MADV_NOHUGEPAGE        15              /* Not worth backing with hugepages */
 
+#define MADV_DONTDUMP   16             /* Explicity exclude from the core dump,
+                                          overrides the coredump filter bits */
+#define MADV_DODUMP    17              /* Clear the MADV_NODUMP flag */
+
 /* compatibility flags */
 #define MAP_FILE       0
 
index b64be5b..504b6ee 100644 (file)
@@ -1127,6 +1127,9 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
        if (always_dump_vma(vma))
                goto whole;
 
+       if (vma->vm_flags & VM_NODUMP)
+               return 0;
+
        /* Hugetlb memory check */
        if (vma->vm_flags & VM_HUGETLB) {
                if ((vma->vm_flags & VM_SHARED) && FILTER(HUGETLB_SHARED))
index 787abbb..d030d2c 100644 (file)
 #define MADV_HUGEPAGE  14              /* Worth backing with hugepages */
 #define MADV_NOHUGEPAGE        15              /* Not worth backing with hugepages */
 
+#define MADV_DONTDUMP   16             /* Explicity exclude from the core dump,
+                                          overrides the coredump filter bits */
+#define MADV_DODUMP    17              /* Clear the MADV_NODUMP flag */
+
 /* compatibility flags */
 #define MAP_FILE       0
 
index 2de2ddb..a6fabdf 100644 (file)
@@ -111,6 +111,7 @@ extern unsigned int kobjsize(const void *objp);
 #define VM_HUGEPAGE    0x01000000      /* MADV_HUGEPAGE marked this vma */
 #endif
 #define VM_INSERTPAGE  0x02000000      /* The vma has had "vm_insert_page()" done on it */
+#define VM_NODUMP      0x04000000      /* Do not include in the core dump */
 
 #define VM_CAN_NONLINEAR 0x08000000    /* Has ->fault & does nonlinear pages */
 #define VM_MIXEDMAP    0x10000000      /* Can contain "struct page" and pure PFN pages */
index f5ab745..1ccbba5 100644 (file)
@@ -65,6 +65,12 @@ static long madvise_behavior(struct vm_area_struct * vma,
                }
                new_flags &= ~VM_DONTCOPY;
                break;
+       case MADV_DONTDUMP:
+               new_flags |= VM_NODUMP;
+               break;
+       case MADV_DODUMP:
+               new_flags &= ~VM_NODUMP;
+               break;
        case MADV_MERGEABLE:
        case MADV_UNMERGEABLE:
                error = ksm_madvise(vma, start, end, behavior, &new_flags);
@@ -293,6 +299,8 @@ madvise_behavior_valid(int behavior)
        case MADV_HUGEPAGE:
        case MADV_NOHUGEPAGE:
 #endif
+       case MADV_DONTDUMP:
+       case MADV_DODUMP:
                return 1;
 
        default: