Support madvise(MADV_DONTDUMP) when creating core dumps for qemu-user
PATCH v2 1/1 Support madvise(MADV_DONTDUMP) when creating core dumps for qemu-user
When running applications which make large (sparsely populated) address ranges (e.g. when using address sanitizer with LibAFL) the inability to exclude these regions from any core dump can result in very large files which fill the disk. A coredump is obvously very useful for performing a post-mortem when fuzzing.
Whilst the man pages state that madvise provides only a hint (and hence can be ignored), this patch adds support to handle MADV_DONTDUMP and set a corresponding flag in the page flags, thus allowing QEMU to exclude these regions from the core file.
--- include/exec/page-protection.h | 6 ++++++ linux-user/elfload.c | 4 ++++ linux-user/mmap.c | 5 +++++ 3 files changed, 15 insertions(+)
include/exec/page-protection.h +6 -0
@@ -38,4 +38,10 @@*/ #define PAGE_PASSTHROUGH 0x0800 +/* +* For linux-user, indicates that the page should not be included in a core +* dump. +*/ +#define PAGE_DONTDUMP 0x1000 +#endif
linux-user/elfload.c +4 -0
@@ -4067,6 +4067,10 @@ static size_t vma_dump_size(target_ulong start, target_ulong end,return 0 ; } +if (flags &PAGE_DONTDUMP ) { +return 0 ; + } +/* * Usually we don't dump executable pages as they contain * non-writable code that debugger can read directly from
linux-user/mmap.c +5 -0
@@ -1247,6 +1247,11 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)*/ mmap_lock ();switch (advice) { +case MADV_DONTDUMP : +if (len >0 ) { +page_set_flags (start, start + len -1 ,PAGE_DONTDUMP ); + } +break ;case MADV_WIPEONFORK :case MADV_KEEPONFORK : ret = -EINVAL ;
Signature · 1 line
2.43.0
Hi Jon,
Quoted 11 lines · WorksButNotTested
When running applications which make large (sparsely populated) address ranges (e.g. when using address sanitizer with LibAFL) the inability to exclude these regions from any core dump can result in very large files which fill the disk. A coredump is obvously very useful for performing a post-mortem when fuzzing.
Whilst the man pages state that madvise provides only a hint (and hence can be ignored), this patch adds support to handle
MADV_DONTDUMPand set a corresponding flag in the page flags, thus allowing QEMU to exclude these regions from the core file.Signed-off-by WorksButNotTested <[email protected]>
In v1 you use Jon Wilson <[email protected]>, is this other address the one you really want to use here?
Quoted 52 lines
--- include/exec/page-protection.h | 6 ++++++ linux-user/elfload.c | 4 ++++ linux-user/mmap.c | 5 +++++ 3 files changed, 15 insertions(+)include/exec/page-protection.h +6
-0@@ -38,4 +38,10 @@*/ #define PAGE_PASSTHROUGH 0x0800 +/* +* For linux-user, indicates that the page should not be included in a core +* dump. +*/ +#define PAGE_DONTDUMP 0x1000 +#endif linux-user/elfload.c +4
-0@@ -4067,6 +4067,10 @@ static size_t vma_dump_size(target_ulong start, target_ulong end,return 0 ; } +if (flags &PAGE_DONTDUMP ) { +return 0 ; + } +/* * Usually we don't dump executable pages as they contain * non-writable code that debugger can read directly from linux-user/mmap.c +5
-0@@ -1247,6 +1247,11 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)*/ mmap_lock ();switch (advice) { +case MADV_DONTDUMP : +if (len >0 ) { +page_set_flags (start, start + len -1 ,PAGE_DONTDUMP ); + } +break ;case MADV_WIPEONFORK :case MADV_KEEPONFORK : ret = -EINVAL ;