[PATCH 2/3] compat: backport definition of VM_NODUMP and VM_DONTDUMP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Luis R. Rodriguez" <mcgrof@xxxxxxxxxxxxxxxx>

Commit accb61fe defined and added VM_NODUMP so we backport that
but later VM_NODUMP was renamed to VM_DONTDUMP via commit cdaaa7003.
We backport that definition declaration as well. Note though that
commit 909af768e removed the usage of the same bit field and it
was used previously for VM_ALWAYSDUMP... given that we want to
backport support for it but we can't we make this flag now a no-op
for older kernels.

Usage of VM_NODUMP or VM_DONTDUMP on older kernels will simply yield
in a no-op for memory regions.

mcgrof@frijol ~/linux-next (git::master)$ git describe --contains \
	909af768e88867016f427264ae39d27a57b6a8ed
v3.4-rc1~109^2~7

commit 909af768e88867016f427264ae39d27a57b6a8ed
Author: Jason Baron <jbaron@xxxxxxxxxx>
Date:   Fri Mar 23 15:02:51 2012 -0700

    coredump: remove VM_ALWAYSDUMP flag

    The motivation for this patchset was that I was looking at a way for a
    qemu-kvm process, to exclude the guest memory from its core dump, which
    can be quite large.  There are already a number of filter flags in
    /proc/<pid>/coredump_filter, however, these allow one to specify 'types'
    of kernel memory, not specific address ranges (which is needed in this
    case).

    Since there are no more vma flags available, the first patch eliminates
    the need for the 'VM_ALWAYSDUMP' flag.  The flag is used internally by
    the kernel to mark vdso and vsyscall pages.  However, it is simple
    enough to check if a vma covers a vdso or vsyscall page without the need
    for this flag.

    The second patch then replaces the 'VM_ALWAYSDUMP' flag with a new
    'VM_NODUMP' flag, which can be set by userspace using new madvise flags:
    'MADV_DONTDUMP', and unset via 'MADV_DODUMP'.  The core dump filters
    continue to work the same as before unless 'MADV_DONTDUMP' is set on the
    region.

    The qemu code which implements this features is at:

      http://people.redhat.com/~jbaron/qemu-dump/qemu-dump.patch

    In my testing the qemu core dump shrunk from 383MB -> 13MB with this
    patch.

    I also believe that the 'MADV_DONTDUMP' flag might be useful for
    security sensitive apps, which might want to select which areas are
    dumped.

    This patch:

    The VM_ALWAYSDUMP flag is currently used by the coredump code to
    indicate that a vma is part of a vsyscall or vdso section.  However, we
    can determine if a vma is in one these sections by checking it against
    the gate_vma and checking for a non-NULL return value from
    arch_vma_name().  Thus, freeing a valuable vma bit.

    Signed-off-by: Jason Baron <jbaron@xxxxxxxxxx>
    Acked-by: Roland McGrath <roland@xxxxxxxxxxxxx>
    Cc: Chris Metcalf <cmetcalf@xxxxxxxxxx>
    Cc: Avi Kivity <avi@xxxxxxxxxx>
    Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>

mcgrof@frijol ~/linux-next (git::master)$ git describe --contains accb61fe
v3.4-rc1~109^2~6

commit accb61fe7bb0f5c2a4102239e4981650f9048519
Author: Jason Baron <jbaron@xxxxxxxxxx>
Date:   Fri Mar 23 15:02:51 2012 -0700

    coredump: add VM_NODUMP, MADV_NODUMP, MADV_CLEAR_NODUMP

    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@xxxxxxxxxxxxxxxxxxxx: s/MADV_NODUMP/MADV_DONTDUMP/, s/MADV_CLEAR_NODUMP/MADV_DODUMP/, per Roland]
    [akpm@xxxxxxxxxxxxxxxxxxxx: fix up the architectures which broke]
    Signed-off-by: Jason Baron <jbaron@xxxxxxxxxx>
    Acked-by: Roland McGrath <roland@xxxxxxxxxxxxx>
    Cc: Chris Metcalf <cmetcalf@xxxxxxxxxx>
    Cc: Avi Kivity <avi@xxxxxxxxxx>
    Cc: Ralf Baechle <ralf@xxxxxxxxxxxxxx>
    Cc: Richard Henderson <rth@xxxxxxxxxxx>
    Cc: Ivan Kokshaysky <ink@xxxxxxxxxxxxxxxxxxxx>
    Cc: Matt Turner <mattst88@xxxxxxxxx>
    Cc: "James E.J. Bottomley" <jejb@xxxxxxxxxxxxxxxx>
    Cc: Helge Deller <deller@xxxxxx>
    Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>

VM_NODUMP was renamed to VM_DONTDUMP so for older kernels
just use the old declaration. This commit is not yet on
Linus' tree so in linux-next we trust it will be on v3.7-rc1.

commit cdaaa7003e855fb50be3a566ac8ef96c6ff138cd
Author: Konstantin Khlebnikov <khlebnikov@xxxxxxxxxx>
Date:   Wed Sep 26 11:33:12 2012 +1000

    mm: prepare VM_DONTDUMP for using in drivers

    Rename VM_NODUMP into VM_DONTDUMP: this name matches other negative flags:
    VM_DONTEXPAND, VM_DONTCOPY.  Currently this flag used only for
    sys_madvise.  The next patch will use it for replacing the outdated flag
    VM_RESERVED.

    Also forbid madvise(MADV_DODUMP) for special kernel mappings VM_SPECIAL
    (VM_IO | VM_DONTEXPAND | VM_RESERVED | VM_PFNMAP)

    Signed-off-by: Konstantin Khlebnikov <khlebnikov@xxxxxxxxxx>
    Cc: Alexander Viro <viro@xxxxxxxxxxxxxxxxxx>
    Cc: Carsten Otte <cotte@xxxxxxxxxx>
    Cc: Chris Metcalf <cmetcalf@xxxxxxxxxx>
    Cc: Cyrill Gorcunov <gorcunov@xxxxxxxxxx>
    Cc: Eric Paris <eparis@xxxxxxxxxx>
    Cc: H. Peter Anvin <hpa@xxxxxxxxx>
    Cc: Hugh Dickins <hughd@xxxxxxxxxx>
    Cc: Ingo Molnar <mingo@xxxxxxxxxx>
    Cc: James Morris <james.l.morris@xxxxxxxxxx>
    Cc: Jason Baron <jbaron@xxxxxxxxxx>
    Cc: Kentaro Takeda <takedakn@xxxxxxxxxxxxx>
    Cc: Matt Helsley <matthltc@xxxxxxxxxx>
    Cc: Nick Piggin <npiggin@xxxxxxxxx>
    Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
    Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
    Cc: Robert Richter <robert.richter@xxxxxxx>
    Cc: Suresh Siddha <suresh.b.siddha@xxxxxxxxx>
    Cc: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
    Cc: Venkatesh Pallipadi <venki@xxxxxxxxxx>
    Acked-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>

Cc: Jason Baron <jbaron@xxxxxxxxxx>
Cc: Roland McGrath <roland@xxxxxxxxxxxxx>
Cc: Chris Metcalf <cmetcalf@xxxxxxxxxx>
Cc: Avi Kivity <avi@xxxxxxxxxx>
Cc: Ralf Baechle <ralf@xxxxxxxxxxxxxx>
Cc: Richard Henderson <rth@xxxxxxxxxxx>
Cc: Ivan Kokshaysky <ink@xxxxxxxxxxxxxxxxxxxx>
Cc: Matt Turner <mattst88@xxxxxxxxx>
Cc: "James E.J. Bottomley" <jejb@xxxxxxxxxxxxxxxx>
Cc: Helge Deller <deller@xxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Luis R. Rodriguez <mcgrof@xxxxxxxxxxxxxxxx>
---
 include/linux/compat-3.4.h |   11 +++++++++++
 include/linux/compat-3.7.h |    3 +++
 2 files changed, 14 insertions(+)

diff --git a/include/linux/compat-3.4.h b/include/linux/compat-3.4.h
index 07bfa53..887293d 100644
--- a/include/linux/compat-3.4.h
+++ b/include/linux/compat-3.4.h
@@ -5,6 +5,17 @@
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
 
+/*
+ * defined here to allow things to compile but technically
+ * using this for memory regions will yield in a no-op on newer
+ * kernels but on older kernels (v3.3 and older) this bit was used
+ * for VM_ALWAYSDUMP. The goal was to remove this bit moving forward
+ * and since we can't skip the core dump on old kernels we just make
+ * this bit name now a no-op.
+ *
+ * For details see commits: 909af7 accb61fe cdaaa7003
+ */
+#define VM_NODUMP      0x0
 
 /* This backports:
  *
diff --git a/include/linux/compat-3.7.h b/include/linux/compat-3.7.h
index e4e126c..80c2aad 100644
--- a/include/linux/compat-3.7.h
+++ b/include/linux/compat-3.7.h
@@ -9,6 +9,9 @@
 #include <linux/tty.h>
 #include <linux/pci.h>
 #include <linux/pci_regs.h>
+#include <linux/mm.h>
+
+#define VM_DONTDUMP    VM_NODUMP
 
 #define netlink_notify_portid(__notify) (__notify->pid)
 #define genl_info_snd_portid(__genl_info) (__genl_info->snd_pid)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe backports" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux