core dump: re-purpose VM_ALWAYSDUMP to user controlled VM_DONTDUMP
Subsystems (15)
cover core dump: re-purpose VM_ALWAYSDUMP to user controlled VM_DONTDUMP
Hi,
The motivation for this change 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_DONTDUMP' flag, which can be set by userspace using new madvise flags:
'MADV_DONTDUMP', and unset via 'MADV_DUMP'. 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.
Thanks,
-Jason
Jason Baron (2):
core dump: drop VM_ALWAYSDUMP flag
core dump: add a new VM_DONTDUMP flag
arch/arm/kernel/process.c | 2 +- arch/hexagon/kernel/vdso.c | 3 +-- arch/mips/kernel/vdso.c | 3 +-- arch/powerpc/kernel/vdso.c | 3 +-- arch/s390/kernel/vdso.c | 3 +-- arch/sh/kernel/vsyscall/vsyscall.c | 3 +-- arch/tile/mm/elf.c | 3 +-- arch/unicore32/kernel/process.c | 2 +- arch/x86/um/mem_32.c | 8 -------- arch/x86/um/vdso/vma.c | 3 +-- arch/x86/vdso/vdso32-setup.c | 11 ++--------- arch/x86/vdso/vma.c | 3 +-- fs/binfmt_elf.c | 23 +++++++++++++++++++++-- include/asm-generic/mman-common.h | 3 +++ include/linux/mm.h | 2 +- mm/madvise.c | 8 ++++++++ mm/memory.c | 8 +------- 17 files changed, 46 insertions(+), 45 deletions(-)
Signature · 1 line
1.7.7.6
PATCH 1/2 core dump: drop VM_ALWAYSDUMP flag
The VM_ALWAYSDUMP flag is currently used by the coredump code to indicate that a vma is part of a vsyscall or vdso section, and then always dump it. However, we can determine if a vma is in in one of these sections by using 'arch_vma_name()', and thus re-purpose a valuable vma bit.
--- arch/arm/kernel/process.c | 2 +- arch/hexagon/kernel/vdso.c | 3 +-- arch/mips/kernel/vdso.c | 3 +-- arch/powerpc/kernel/vdso.c | 3 +-- arch/s390/kernel/vdso.c | 3 +-- arch/sh/kernel/vsyscall/vsyscall.c | 3 +-- arch/tile/mm/elf.c | 3 +-- arch/unicore32/kernel/process.c | 2 +- arch/x86/um/mem_32.c | 8 -------- arch/x86/um/vdso/vma.c | 3 +-- arch/x86/vdso/vdso32-setup.c | 11 ++--------- arch/x86/vdso/vma.c | 3 +-- fs/binfmt_elf.c | 20 ++++++++++++++++++-- include/linux/mm.h | 1 - mm/memory.c | 8 +------- 15 files changed, 31 insertions(+), 45 deletions(-)
arch/arm/kernel/process.c +1 -1
@@ -536,7 +536,7 @@ int vectors_user_mapping(void)return install_special_mapping (mm,0xffff0000 ,PAGE_SIZE ,VM_READ |VM_EXEC |VM_MAYREAD |VM_MAYEXEC | -VM_ALWAYSDUMP |VM_RESERVED , +VM_RESERVED ,NULL ); }
arch/hexagon/kernel/vdso.c +1 -2
@@ -78,8 +78,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)/* MAYWRITE to allow gdb to COW and set breakpoints. */ ret =install_special_mapping (mm, vdso_base,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , &vdso_page);if (ret)
arch/mips/kernel/vdso.c +1 -2
@@ -88,8 +88,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) ret =install_special_mapping (mm, addr,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , &vdso_page);if (ret)
arch/powerpc/kernel/vdso.c +1 -2
@@ -272,8 +272,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)*/ rc =install_special_mapping (mm, vdso_base, vdso_pages <<PAGE_SHIFT ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso_pagelist);if (rc) { current->mm->context.vdso_base =0 ;
arch/s390/kernel/vdso.c +1 -2
@@ -262,8 +262,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)*/ rc =install_special_mapping (mm, vdso_base, vdso_pages <<PAGE_SHIFT ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso_pagelist);if (rc) current->mm->context.vdso_base =0 ;
arch/sh/kernel/vsyscall/vsyscall.c +1 -2
@@ -73,8 +73,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) ret =install_special_mapping (mm, addr,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , syscall_pages);if (unlikely (ret)) goto up_fail;
arch/tile/mm/elf.c +1 -2
@@ -126,8 +126,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, vdso_base =VDSO_BASE ; retval =install_special_mapping (mm, vdso_base,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso_pages);#ifndef __tilegx__
arch/unicore32/kernel/process.c +1 -1
@@ -381,7 +381,7 @@ int vectors_user_mapping(void)return install_special_mapping (mm,0xffff0000 ,PAGE_SIZE ,VM_READ |VM_EXEC |VM_MAYREAD |VM_MAYEXEC | -VM_ALWAYSDUMP |VM_RESERVED , +VM_RESERVED ,NULL ); }
arch/x86/um/mem_32.c +0 -8
@@ -23,14 +23,6 @@ static int __init gate_vma_init(void) gate_vma.vm_flags =VM_READ |VM_MAYREAD |VM_EXEC |VM_MAYEXEC ; gate_vma.vm_page_prot = __P101; -/* -* Make sure the vDSO gets into every core dump. -* Dumping its contents makes post-mortem fully interpretable later -* without matching up the same kernel and hardware config to see -* what PC values meant. -*/ - gate_vma.vm_flags |=VM_ALWAYSDUMP ; -return 0 ; }__initcall (gate_vma_init);
arch/x86/um/vdso/vma.c +1 -2
@@ -64,8 +64,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) err =install_special_mapping (mm, um_vdso_addr,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdsop);up_write (&mm->mmap_sem);
arch/x86/vdso/vdso32-setup.c +2 -9
@@ -250,13 +250,7 @@ static int __init gate_vma_init(void) gate_vma.vm_end =FIXADDR_USER_END ; gate_vma.vm_flags =VM_READ |VM_MAYREAD |VM_EXEC |VM_MAYEXEC ; gate_vma.vm_page_prot = __P101; -/* -* Make sure the vDSO gets into every core dump. -* Dumping its contents makes post-mortem fully interpretable later -* without matching up the same kernel and hardware config to see -* what PC values meant. -*/ - gate_vma.vm_flags |=VM_ALWAYSDUMP ; +return 0 ; }
@@ -352,8 +346,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)*/ ret =install_special_mapping (mm, addr,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso32_pages);if (ret)
arch/x86/vdso/vma.c +1 -2
@@ -124,8 +124,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) ret =install_special_mapping (mm, addr, vdso_size,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso_pages);if (ret) { current->mm->context.vdso =NULL ;
fs/binfmt_elf.c +18 -2
@@ -1094,6 +1094,22 @@ out:* Jeremy Fitzhardinge <[email protected]> */ +/* Determine if the vma should always be output in the coredump */ +static bool always_dump_vma (struct vm_area_struct *vma) +{ +const char *vma_name =arch_vma_name (vma); + +if (vma_name) { +if ((strcmp (vma_name,"[vdso]" ) ==0 ) || + (strcmp (vma_name,"[vectors]" ) ==0 ) || + (strcmp (vma_name,"[vsyscall]" ) ==0 )) +return true; + } +if (vma ==get_gate_vma (vma->vm_mm)) +return true; +return false; +} +/* * Decide what to dump of a segment, part, all or none. */
@@ -1102,8 +1118,8 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma, {#define FILTER (type) (mm_flags & (1UL << MMF_DUMP_##type)) -/* The vma can be set up to tell us the answer directly. */ -if (vma->vm_flags &VM_ALWAYSDUMP ) +/* always dump the vdso and vsyscall sections */ +if (always_dump_vma (vma)) goto whole;/* Hugetlb memory check */
include/linux/mm.h +0 -1
@@ -111,7 +111,6 @@ 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_ALWAYSDUMP 0x04000000/* Always include in core dumps */ #define VM_CAN_NONLINEAR 0x08000000/* Has ->fault & does nonlinear pages */ #define VM_MIXEDMAP 0x10000000/* Can contain "struct page" and pure PFN pages */
mm/memory.c +1 -7
@@ -3611,13 +3611,7 @@ static int __init gate_vma_init(void) gate_vma.vm_end =FIXADDR_USER_END ; gate_vma.vm_flags =VM_READ |VM_MAYREAD |VM_EXEC |VM_MAYEXEC ; gate_vma.vm_page_prot = __P101; -/* -* Make sure the vDSO gets into every core dump. -* Dumping its contents makes post-mortem fully interpretable later -* without matching up the same kernel and hardware config to see -* what PC values meant. -*/ - gate_vma.vm_flags |=VM_ALWAYSDUMP ; +return 0 ; }__initcall (gate_vma_init);
Signature · 1 line
1.7.7.6
Re: [PATCH 1/2] core dump: drop VM_ALWAYSDUMP flag
Quoted 4 lines · Jason Baron
+ if (
vma_name) {
+ if ((strcmp(vma_name, "[vdso]")== 0) ||
+ (strcmp(vma_name, "[vectors]")== 0) ||
+ (strcmp(vma_name, "[vsyscall]")== 0))
That's just disgusting.
Re: [PATCH 1/2] core dump: drop VM_ALWAYSDUMP flag
Quoted 7 lines · Roland McGrath
Quoted 4 lines · Jason Baron
+ if (
vma_name) {
+ if ((strcmp(vma_name, "[vdso]")== 0) ||
+ (strcmp(vma_name, "[vectors]")== 0) ||
+ (strcmp(vma_name, "[vsyscall]")== 0))That's just disgusting.
well, sure, we can provide an arch interface, for this check. I'm more concerned with the general idea. If it seems ok, I can re-do this bit with an arch interface.
Thanks,
-Jason
Re: [PATCH 1/2] core dump: drop VM_ALWAYSDUMP flag
Quoted 3 lines
well, sure, we can provide an arch interface, for this check. I'm more concerned with the general idea. If it seems ok, I can re-do this bit with an arch interface.
Anything based on strcmp is dismal. VM_ALWAYSDUMP was nice and clean. A hook along the lines of arch_vma_name would be clean enough I suppose. In fact, there is only one instance today (tile) where arch_vma_name()!=NULL wouldn't do just what you need.
Thanks,
Roland
Re: [PATCH 1/2] core dump: drop VM_ALWAYSDUMP flag
Quoted 9 lines · Roland McGrath
Quoted 3 lines
well, sure, we can provide an arch interface, for this check. I'm more concerned with the general idea. If it seems ok, I can re-do this bit with an arch interface.
Anything based on strcmp is dismal.
VM_ALWAYSDUMPwas nice and clean. A hook along the lines ofarch_vma_namewould be clean enough I suppose. In fact, there is only one instance today (tile) where arch_vma_name()!=NULL wouldn't do just what you need.
Yeah, so I think something like the following would work (adding Tile maintainer to 'cc list).
Thanks,
-Jason
The VM_ALWAYSDUMP flag is currently used by the coredump code to indicate that a vma is part of a vsyscall or vdso section, and then always dump it. However, we can determine if a vma is in one of these sections by using 'arch_vma_name()', and thus re-purpose a valuable vma bit.
--- arch/arm/kernel/process.c | 2 +- arch/hexagon/kernel/vdso.c | 3 +-- arch/mips/kernel/vdso.c | 3 +-- arch/powerpc/kernel/vdso.c | 3 +-- arch/s390/kernel/vdso.c | 3 +-- arch/sh/kernel/vsyscall/vsyscall.c | 3 +-- arch/tile/mm/elf.c | 3 +-- arch/unicore32/kernel/process.c | 2 +- arch/x86/um/mem_32.c | 8 -------- arch/x86/um/vdso/vma.c | 3 +-- arch/x86/vdso/vdso32-setup.c | 11 ++--------- arch/x86/vdso/vma.c | 3 +-- fs/binfmt_elf.c | 22 ++++++++++++++++++++-- include/linux/mm.h | 1 - mm/memory.c | 8 +------- 15 files changed, 33 insertions(+), 45 deletions(-)
arch/arm/kernel/process.c +1 -1
@@ -536,7 +536,7 @@ int vectors_user_mapping(void)return install_special_mapping (mm,0xffff0000 ,PAGE_SIZE ,VM_READ |VM_EXEC |VM_MAYREAD |VM_MAYEXEC | -VM_ALWAYSDUMP |VM_RESERVED , +VM_RESERVED ,NULL ); }
arch/hexagon/kernel/vdso.c +1 -2
@@ -78,8 +78,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)/* MAYWRITE to allow gdb to COW and set breakpoints. */ ret =install_special_mapping (mm, vdso_base,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , &vdso_page);if (ret)
arch/mips/kernel/vdso.c +1 -2
@@ -88,8 +88,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) ret =install_special_mapping (mm, addr,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , &vdso_page);if (ret)
arch/powerpc/kernel/vdso.c +1 -2
@@ -272,8 +272,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)*/ rc =install_special_mapping (mm, vdso_base, vdso_pages <<PAGE_SHIFT ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso_pagelist);if (rc) { current->mm->context.vdso_base =0 ;
arch/s390/kernel/vdso.c +1 -2
@@ -262,8 +262,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)*/ rc =install_special_mapping (mm, vdso_base, vdso_pages <<PAGE_SHIFT ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso_pagelist);if (rc) current->mm->context.vdso_base =0 ;
arch/sh/kernel/vsyscall/vsyscall.c +1 -2
@@ -73,8 +73,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) ret =install_special_mapping (mm, addr,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , syscall_pages);if (unlikely (ret)) goto up_fail;
arch/tile/mm/elf.c +1 -2
@@ -126,8 +126,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, vdso_base =VDSO_BASE ; retval =install_special_mapping (mm, vdso_base,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso_pages);#ifndef __tilegx__
arch/unicore32/kernel/process.c +1 -1
@@ -381,7 +381,7 @@ int vectors_user_mapping(void)return install_special_mapping (mm,0xffff0000 ,PAGE_SIZE ,VM_READ |VM_EXEC |VM_MAYREAD |VM_MAYEXEC | -VM_ALWAYSDUMP |VM_RESERVED , +VM_RESERVED ,NULL ); }
arch/x86/um/mem_32.c +0 -8
@@ -23,14 +23,6 @@ static int __init gate_vma_init(void) gate_vma.vm_flags =VM_READ |VM_MAYREAD |VM_EXEC |VM_MAYEXEC ; gate_vma.vm_page_prot = __P101; -/* -* Make sure the vDSO gets into every core dump. -* Dumping its contents makes post-mortem fully interpretable later -* without matching up the same kernel and hardware config to see -* what PC values meant. -*/ - gate_vma.vm_flags |=VM_ALWAYSDUMP ; -return 0 ; }__initcall (gate_vma_init);
arch/x86/um/vdso/vma.c +1 -2
@@ -64,8 +64,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) err =install_special_mapping (mm, um_vdso_addr,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdsop);up_write (&mm->mmap_sem);
arch/x86/vdso/vdso32-setup.c +2 -9
@@ -250,13 +250,7 @@ static int __init gate_vma_init(void) gate_vma.vm_end =FIXADDR_USER_END ; gate_vma.vm_flags =VM_READ |VM_MAYREAD |VM_EXEC |VM_MAYEXEC ; gate_vma.vm_page_prot = __P101; -/* -* Make sure the vDSO gets into every core dump. -* Dumping its contents makes post-mortem fully interpretable later -* without matching up the same kernel and hardware config to see -* what PC values meant. -*/ - gate_vma.vm_flags |=VM_ALWAYSDUMP ; +return 0 ; }
@@ -352,8 +346,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)*/ ret =install_special_mapping (mm, addr,PAGE_SIZE ,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso32_pages);if (ret)
arch/x86/vdso/vma.c +1 -2
@@ -124,8 +124,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) ret =install_special_mapping (mm, addr, vdso_size,VM_READ |VM_EXEC | -VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC | -VM_ALWAYSDUMP , +VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso_pages);if (ret) { current->mm->context.vdso =NULL ;
fs/binfmt_elf.c +20 -2
@@ -1094,6 +1094,24 @@ out:* Jeremy Fitzhardinge <[email protected]> */ +/* Determine if the vma should always be output in the coredump */ +static bool always_dump_vma (struct vm_area_struct *vma) +{ +const char *vma_name =arch_vma_name (vma); + +if (vma_name) { +#ifdef CONFIG_TILE +/* Tile user-interrupt mapping which we don't always dump */ +if (is_arch_mappable_range (vma->vm_start,0 )) +return false; +#endif +return true; + } +if (vma ==get_gate_vma (vma->vm_mm)) +return true; +return false; +} +/* * Decide what to dump of a segment, part, all or none. */
@@ -1102,8 +1120,8 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma, {#define FILTER (type) (mm_flags & (1UL << MMF_DUMP_##type)) -/* The vma can be set up to tell us the answer directly. */ -if (vma->vm_flags &VM_ALWAYSDUMP ) +/* always dump the vdso and vsyscall sections */ +if (always_dump_vma (vma)) goto whole;/* Hugetlb memory check */
include/linux/mm.h +0 -1
@@ -111,7 +111,6 @@ 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_ALWAYSDUMP 0x04000000/* Always include in core dumps */ #define VM_CAN_NONLINEAR 0x08000000/* Has ->fault & does nonlinear pages */ #define VM_MIXEDMAP 0x10000000/* Can contain "struct page" and pure PFN pages */
mm/memory.c +1 -7
@@ -3611,13 +3611,7 @@ static int __init gate_vma_init(void) gate_vma.vm_end =FIXADDR_USER_END ; gate_vma.vm_flags =VM_READ |VM_MAYREAD |VM_EXEC |VM_MAYEXEC ; gate_vma.vm_page_prot = __P101; -/* -* Make sure the vDSO gets into every core dump. -* Dumping its contents makes post-mortem fully interpretable later -* without matching up the same kernel and hardware config to see -* what PC values meant. -*/ - gate_vma.vm_flags |=VM_ALWAYSDUMP ; +return 0 ; }__initcall (gate_vma_init);
Signature · 1 line
1.7.7.6
Re: [PATCH 1/2] core dump: drop VM_ALWAYSDUMP flag
Quoted 11 lines · Jason Baron
Quoted 8 lines · Roland McGrath
Quoted 3 lines
well, sure, we can provide an arch interface, for this check. I'm more concerned with the general idea. If it seems ok, I can re-do this bit with an arch interface.
Anything based on strcmp is dismal.
VM_ALWAYSDUMPwas nice and clean. A hook along the lines ofarch_vma_namewould be clean enough I suppose. In fact, there is only one instance today (tile) where arch_vma_name()!=NULL wouldn't do just what you need.Yeah, so I think something like the following would work (adding Tile maintainer to 'cc list).
Thanks!
My instinct would be not to special-case it in always_dump_vma(). Since it's just a one-page region anyway, and it is at least potentially interesting, I'm happy to always dump it. Alternately, we can just get rid of the "[intrpt]" name, which I just put in to be cute (and since it was easy to identify the mapping in question). Regardless, since that region doesn't exist on our current 64-bit architecture, I'm not too concerned with how it's handled going forward, since I expect the 32-bit platform to become less popular over time. I'd vote for generic code cleanliness.
Signature · 2 lines
Chris Metcalf, Tilera Corp. http://www.tilera.com
Re: [PATCH 1/2] core dump: drop VM_ALWAYSDUMP flag
Quoted 15 lines · Chris Metcalf
Quoted 11 lines · Jason Baron
Quoted 8 lines · Roland McGrath
Quoted 3 lines
well, sure, we can provide an arch interface, for this check. I'm more concerned with the general idea. If it seems ok, I can re-do this bit with an arch interface.
Anything based on strcmp is dismal.
VM_ALWAYSDUMPwas nice and clean. A hook along the lines ofarch_vma_namewould be clean enough I suppose. In fact, there is only one instance today (tile) where arch_vma_name()!=NULL wouldn't do just what you need.Yeah, so I think something like the following would work (adding Tile maintainer to 'cc list).
Thanks!
Quoted 9 lines
My instinct would be not to special-case it in
always_dump_vma(). Since it's just a one-page region anyway, and it is at least potentially interesting, I'm happy to always dump it. Alternately, we can just get rid of the "[intrpt]" name, which I just put in to be cute (and since it was easy to identify the mapping in question). Regardless, since that region doesn't exist on our current 64-bit architecture, I'm not too concerned with how it's handled going forward, since I expect the 32-bit platform to become less popular over time. I'd vote for generic code cleanliness.
Ok, I'll just always dump it.
Thanks!
-Jason
Re: [PATCH 1/2] core dump: drop VM_ALWAYSDUMP flag
In reply to Jason BaronA few of the vDSO VM_ALWAYSDUMP cases have a comment about the core dump. (It looks like they were all copied from my original comment in arch/x86/vdso/vdso32-setup.c.) So those should be removed where they are. (You removed some of them, but not all.) You should put that comment into always_dump_vma.
get_gate_vma is always defined quite trivially, and is also the most logically obvious case, so I would test it first.
It sounds like the Tile special case is unnecessary, so just arch_vma_name(vma) != NULL is an adequate test. Please give it a clear comment about why that test makes sense, i.e. because all extant uses are for a vDSO or something similar.
Thanks,
Roland
PATCH 2/2 core dump: add a new VM_DONTDUMP flag
In reply to Jason BaronSince we no longer need the VM_ALWAYSDUMP flag, let's use the freed bit for 'VM_DONTDUMP' flag. The idea 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.
--- fs/binfmt_elf.c | 3 +++ include/asm-generic/mman-common.h | 3 +++ include/linux/mm.h | 1 + mm/madvise.c | 8 ++++++++ 4 files changed, 15 insertions(+), 0 deletions(-)
fs/binfmt_elf.c +3 -0
@@ -1122,6 +1122,9 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,if (always_dump_vma (vma)) goto whole; +if (vma->vm_flags &VM_DONTDUMP ) +return 0 ; +/* Hugetlb memory check */ if (vma->vm_flags &VM_HUGETLB ) {if ((vma->vm_flags &VM_SHARED ) &&FILTER (HUGETLB_SHARED ))
include/asm-generic/mman-common.h +3 -0
@@ -48,6 +48,9 @@#define MADV_HUGEPAGE 14/* Worth backing with hugepages */ #define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ +#define MADV_DUMP 16 +#define MADV_DONTDUMP 17 +/* compatibility flags */ #define MAP_FILE 0
include/linux/mm.h +1 -0
@@ -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_DONTDUMP 0x04000000/* Do not include in core dump */ #define VM_CAN_NONLINEAR 0x08000000/* Has ->fault & does nonlinear pages */ #define VM_MIXEDMAP 0x10000000/* Can contain "struct page" and pure PFN pages */
mm/madvise.c +8 -0
@@ -65,6 +65,12 @@ static long madvise_behavior(struct vm_area_struct * vma, } new_flags &= ~VM_DONTCOPY ;break ; +case MADV_DONTDUMP : + new_flags |=VM_DONTDUMP ; +break ; +case MADV_DUMP : + new_flags &= ~VM_DONTDUMP ; +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_DUMP : +case MADV_DONTDUMP :return 1 ;default :
Signature · 1 line
1.7.7.6
Andrew Morton
maintainerQuoted 8 lines · On Wed, 7 Mar 2012 12:00:46 -0500 Jason Baron <[email protected]> wrote:
Hi,
The motivation for this change 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).
Quoted 4 lines
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.
Gee, we ran out?
That makes it pretty inevitable that we will grow the vma by four bytes. Once we have done that, your always_dump_vma() trickery becomes unneeded and undesirable, yes? If so, we may as well recognise reality and grow the vma now.
Quoted 5 lines
The second patch then replaces the '
VM_ALWAYSDUMP' flag with a new 'VM_DONTDUMP' flag, which can be set by userspace using new madvise flags:
'MADV_DONTDUMP', and unset via 'MADV_DUMP'. The core dump filters continue to work the same as before unless 'MADV_DONTDUMP' is set on the region.
Quoted 8 lines
The qemu code which implements this features is at:
http://people.redhat.com/~jbaron/qemu-dump/qemu-dump.patchIn 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.
Is there any way for userspace to query the state of the flag?
Quoted 16 lines · Andrew Morton
Quoted 8 lines · On Wed, 7 Mar 2012 12:00:46 -0500 Jason Baron <[email protected]> wrote:
Hi,
The motivation for this change 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).
Quoted 4 lines
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.
Quoted 7 lines
Gee, we ran out?
That makes it pretty inevitable that we will grow the vma by four bytes. Once we have done that, your
always_dump_vma()trickery becomes unneeded and undesirable, yes? If so, we may as well recognise reality and grow the vma now.
We could. The reason I didn't propose increasing them was because I saw in the archives that there was resistance when this was tried before:
http://lkml.indiana.edu/hypermail/linux/kernel/1111.1/02053.html
Also, the current use of 'VM_ALWAYSDUMP' is for vdso and gate pages exclusively. That means that VM_ALWAYSDUMP flag is 0 the majority of the time, and thus it probably makes sense to re-purpose it, now that we are tight on flags.
Quoted 8 lines
Quoted 8 lines
The second patch then replaces the '
VM_ALWAYSDUMP' flag with a new 'VM_DONTDUMP' flag, which can be set by userspace using new madvise flags:
'MADV_DONTDUMP', and unset via 'MADV_DUMP'. 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
Quoted 8 lines
Quoted 5 lines
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.Is there any way for userspace to query the state of the flag?
A place for that might be /proc/<pid>/maps, but I don't think any of the other vm flags are exposed.
Thanks,
-Jason
Jason,
Quoted 18 lines · Jason Baron
Hi,
The motivation for this change 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_DONTDUMP' flag, which can be set by userspace using new madvise flags:
'MADV_DONTDUMP', and unset via 'MADV_DUMP'. The core dump filters continue to work the same as before unless 'MADV_DONTDUMP' is set on the region.
Quoted 7 lines
The qemu code which implements this features is at:
http://people.redhat.com/~jbaron/qemu-dump/qemu-dump.patchIn 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.
Since we haveMADV_DODUMPMADV_DONTDUMPMADV_NODUMP
heading for userspace in 3.4, would you be willing to write patches for the madvise(2) man page to describe these flags?
See http://www.kernel.org/doc/man-pages/download.html for details on accessing man-pages Git.
Cheers,
Michael
PS Please also CC linux-api@ when making API/ABI changes.
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Author of "The Linux Programming Interface", http://blog.man7.org/
Quoted 36 lines · Michael Kerrisk
Jason,
Quoted 18 lines · Jason Baron
Hi,
The motivation for this change 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_DONTDUMP' flag, which can be set by userspace using new madvise flags:
'MADV_DONTDUMP', and unset via 'MADV_DUMP'. The core dump filters continue to work the same as before unless 'MADV_DONTDUMP' is set on the region.Quoted 7 lines
The qemu code which implements this features is at:
http://people.redhat.com/~jbaron/qemu-dump/qemu-dump.patchIn 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.Since we have
MADV_DODUMPMADV_DONTDUMPMADV_NODUMP
heading for userspace in 3.4, would you be willing to write patches for the madvise(2) man page to describe these flags?
Quoted 9 lines
See http://www.kernel.org/doc/man-pages/download.html for details on accessing man-pages Git.
Cheers,
Michael
PS Please also CC linux-api@ when making API/ABI changes.
Ok, here's a stab at manpage patch, let me know if I should send it as a separate patch. Thanks.
-Jason
man2/madvise.2 +18 -1
@@ -247,6 +247,22 @@ Ensures that memory in the address range specified by and .IR length will not be collapsed into huge pages. +.TP +.BR MADV_DONTDUMP " (since Linux 3.4)" +Explicitly exclude from a core dump those pages in the range specified by +.I addr +and +.IR length . +Applications may have large areas of memory which are known not to be useful in +diagnosing a core dump. This specification takes precedence over the bit mask that +is set via the +.I /proc/PID/coredump_filter +file (see +.BR core (5)). +.TP +.BR MADV_DODUMP " (since Linux 3.4)" +Undo the effect of an earlier +.BR MADV_DONTDUMP. .SH "RETURN VALUE" On success .BR madvise ()
@@ -356,4 +372,5 @@ from the system call, as it should). .BR mmap (2), .BR mprotect (2), .BR msync (2), -.BR munmap (2) +.BR munmap (2), +.BR core (5)
Hello Jason,
Quoted 81 lines · Jason Baron
Quoted 36 lines · Michael Kerrisk
Jason,
Quoted 18 lines · Jason Baron
Hi,
The motivation for this change 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_DONTDUMP' flag, which can be set by userspace using new madvise flags:
'MADV_DONTDUMP', and unset via 'MADV_DUMP'. The core dump filters continue to work the same as before unless 'MADV_DONTDUMP' is set on the region.Quoted 7 lines
The qemu code which implements this features is at:
http://people.redhat.com/~jbaron/qemu-dump/qemu-dump.patchIn 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.Since we have
MADV_DODUMPMADV_DONTDUMPMADV_NODUMP
heading for userspace in 3.4, would you be willing to write patches for the madvise(2) man page to describe these flags?Quoted 9 lines
See http://www.kernel.org/doc/man-pages/download.html for details on accessing man-pages Git.
Cheers,
Michael
PS Please also CC linux-api@ when making API/ABI changes.
Ok, here's a stab at manpage patch, let me know if I should send it as a separate patch. Thanks.
(quoted diff) +0
-1-Jasonman2/madvise.2 +0
-0@@ -247,6 +247,22 @@ Ensures that memory in the address range specified byand
.IR length
will not be collapsed into huge pages.
+.TP
+.BRMADV_DONTDUMP" (since Linux 3.4)"man2/madvise.2 +14
-0+Explicitly exclude from a core dump those pages in the range specified by +.I addr +and +.IR length . +Applications may have large areas of memory which are known not to be useful in +diagnosing a core dump. This specification takes precedence over the bit mask that +is set via the +.I /proc/PID/coredump_filter +file (see +.BR core (5)). +.TP +.BR MADV_DODUMP " (since Linux 3.4)" +Undo the effect of an earlier +.BR MADV_DONTDUMP..SH "RETURN VALUE"
On success
.BR madvise ()
man2/madvise.2 from the system call, as it should). · line 376
Quoted 6 lines
man2/madvise.2 +2
-1@@ -356,4 +372,5 @@ from the system call, as it should). .BR mmap (2), .BR mprotect (2), .BR msync (2), -.BR munmap (2) +.BR munmap (2), +.BR core (5)
Thanks! I tweaked this patch a little and applied the version below.
Cheers,
Michael
man2/madvise.2 +20 -1
@@ -247,6 +247,24 @@ Ensures that memory in the address range specified by and .IR length will not be collapsed into huge pages. +.TP +.BR MADV_DONTDUMP " (since Linux 3.4)" +Exclude from a core dump those pages in the range specified by +.I addr +and +.IR length . +This is useful in applications that have large areas of memory +that are known not to be useful in a core dump. +The effect of +.BR MADV_DONTDUMP +takes precedence over the bit mask that is set via the +.I /proc/PID/coredump_filter +file (see +.BR core (5)). +.TP +.BR MADV_DODUMP " (since Linux 3.4)" +Undo the effect of an earlier +.BR MADV_DONTDUMP . .SH "RETURN VALUE" On success .BR madvise ()
@@ -356,4 +374,5 @@ from the system call, as it should). .BR mmap (2), .BR mprotect (2), .BR msync (2), -.BR munmap (2) +.BR munmap (2), +.BR core (5)
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Author of "The Linux Programming Interface"; http://man7.org/tlpi/