Skip to content

Commit 15fcf9a

Browse files
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.
1 parent 54b1f3f commit 15fcf9a

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

include/exec/page-protection.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
*/
3939
#define PAGE_PASSTHROUGH 0x0800
4040

41+
/*
42+
* For linux-user, indicates that the page should not be included in a core
43+
* dump.
44+
*/
45+
#define PAGE_DONTDUMP 0x1000
46+
4147
#ifdef CONFIG_USER_ONLY
4248

4349
void TSA_NO_TSA mmap_lock(void);

linux-user/elfload.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4068,6 +4068,10 @@ static size_t vma_dump_size(target_ulong start, target_ulong end,
40684068
return 0;
40694069
}
40704070

4071+
if (flags & PAGE_DONTDUMP) {
4072+
return 0;
4073+
}
4074+
40714075
/*
40724076
* Usually we don't dump executable pages as they contain
40734077
* non-writable code that debugger can read directly from

linux-user/mmap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,11 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)
12461246
*/
12471247
mmap_lock();
12481248
switch (advice) {
1249+
case MADV_DONTDUMP:
1250+
if (len > 0) {
1251+
page_set_flags(start, start + len - 1, PAGE_DONTDUMP);
1252+
}
1253+
break;
12491254
case MADV_WIPEONFORK:
12501255
case MADV_KEEPONFORK:
12511256
ret = -EINVAL;

0 commit comments

Comments
 (0)