Page MenuHomeFreeBSD

coredump: Don't assume that the number of ELF segments is consistent
ClosedPublic

Authored by markj on Thu, Jul 23, 4:48 PM.

Details

Summary

In an ELF coredump, each dumped vm_map_entry is represented by a
segment. __elfN(coredump) first computes the number of segments by
looping over the vm_map entries (in each_dumpable_segment()), then
allocates a buffer to hold the ELF header and program headers, then
loops over the entries again to populate the program headers.

each_dumpable_segment() holds the vm_map read lock, but that lock is
dropped between the two calls. If the map is shared with another
process, via rfork(), then the map can change. cb_put_phdr() did not
account for this, and so could write out of bounds.

Add a check to prevent this; simply do not write out excess segments.

Reported by: Maik Muench of Secfault Security

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj held this revision as a draft.
markj published this revision for review.Thu, Jul 23, 4:48 PM
markj changed the visibility from "Public (No Login Required)" to "Subscribers".
markj changed the edit policy from "All Users" to "Subscribers".
markj added reviewers: kib, jhb.
markj removed subscribers: imp, olce.
markj added subscribers: secteam, kib, jhb.
sys/kern/imgact_elf.c
1713

This M_ZERO is to make sure we don't write out uninitialized memory if the number of phdrs shrinks instead of growing.

In general, if something is mutating the vm_map as we're writing out a core dump, then I don't expect the core dump to be consistent; it's enough to ensure that such races don't trigger any memory safety problems in the kernel.

kib added inline comments.
sys/kern/imgact_elf.c
1713

I would put the text into the comment in the code.

This revision is now accepted and ready to land.Thu, Jul 23, 10:59 PM
This revision now requires review to proceed.Fri, Jul 24, 2:19 PM
This revision is now accepted and ready to land.Fri, Jul 24, 2:49 PM
markj changed the visibility from "Subscribers" to "Public (No Login Required)".Wed, Jul 29, 5:57 PM
markj changed the edit policy from "Subscribers" to "All Users".