Skip to content

Commit

Permalink
Kernel: Exclude PROT_NONE regions from coredumps
Browse files Browse the repository at this point in the history
As PROT_NONE regions can't be accessed by processes, and their only real
use is for reserving ranges of virtual memory, there's no point in
including them in coredumps.
  • Loading branch information
BertalanD authored and bgianfo committed Dec 22, 2021
1 parent ce1bf37 commit 2f1b4b8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Kernel/Coredump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Coredump::Coredump(NonnullRefPtr<Process> process, NonnullRefPtr<OpenFileDescrip
if (looks_like_userspace_heap_region(*region))
continue;
#endif

if (region->access() == Memory::Region::Access::None)
continue;
++m_num_program_headers;
}
++m_num_program_headers; // +1 for NOTE segment
Expand Down Expand Up @@ -128,6 +131,9 @@ ErrorOr<void> Coredump::write_program_headers(size_t notes_size)
continue;
#endif

if (region->access() == Memory::Region::Access::None)
continue;

ElfW(Phdr) phdr {};

phdr.p_type = PT_LOAD;
Expand Down Expand Up @@ -177,6 +183,9 @@ ErrorOr<void> Coredump::write_regions()
continue;
#endif

if (region->access() == Memory::Region::Access::None)
continue;

region->set_readable(true);
region->remap();

Expand Down Expand Up @@ -254,6 +263,9 @@ ErrorOr<void> Coredump::create_notes_regions_data(auto& builder) const
continue;
#endif

if (region->access() == Memory::Region::Access::None)
continue;

ELF::Core::MemoryRegionInfo info {};
info.header.type = ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo;

Expand Down

0 comments on commit 2f1b4b8

Please sign in to comment.