Skip to content

Commit fdebe3d

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 97bef50 commit fdebe3d

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,4 +38,10 @@
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
#endif

linux-user/elfload.c

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

4070+
if (flags & PAGE_DONTDUMP) {
4071+
return 0;
4072+
}
4073+
40704074
/*
40714075
* Usually we don't dump executable pages as they contain
40724076
* 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
@@ -1243,6 +1243,11 @@ abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice)
12431243
*/
12441244
mmap_lock();
12451245
switch (advice) {
1246+
case MADV_DONTDUMP:
1247+
if (len > 0) {
1248+
page_set_flags(start, start + len - 1, PAGE_DONTDUMP);
1249+
}
1250+
break;
12461251
case MADV_WIPEONFORK:
12471252
case MADV_KEEPONFORK:
12481253
ret = -EINVAL;

0 commit comments

Comments
 (0)