From nobody Wed Jul 29 17:48:00 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4h9KYX637fz6mZYF for ; Wed, 29 Jul 2026 17:48:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4h9KYX2yLjz3gGV for ; Wed, 29 Jul 2026 17:48:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785347280; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sSJNApQzgWvEF93npG7rPKycUEkHut6bzXGdB3pKo8s=; b=RI3Ha8ctKqpyJK5/5GchBaPNXp1M2m5Uw00V1mARMeYqtUuoQqBtceQ6BOfiH0K1HSbYCi RE0snsChxKAdAQ8u53JJo2hV6k3nRX7mef4mmYuNh7bGY6EV4zBGkMtzU3gQUA3idR5Xi4 9Tlhd8D8yLeQq3w15OEmnC1r2itA/DDT1kuEpp9t1eR4xBRlQj0xMpr5gjA8yv98XQ7jLP 8JxOKUTp06PD31x0KU3B51QqbGNgbFmBcxuvI0Ah1Z82+AYEmpxDFBupXU1ao0il7AFfUj SnzXtStGYzlEN3i0B8C7UuIlQcl4CJZrz1vRy5E7yYpbdtNQZ+Witg8KwZAn0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785347280; a=rsa-sha256; cv=none; b=jTMNXLi1lPDbjwNnqKStzWhDqHMJTGjRhQbD8o4cCiDupujFV060CyIBqOqOyn0Bj5/elJ ppdv/IH2PlEHuA8CwBY9cNkcsFvkS4gROIr//sGc8MIO6t0QnHc4HSqf2mP0R5VE13h4NY gJDmHoP3qBsrVz+uUsTgtU5z5Pw0lmh+lTMVXkc7YShiT7nQflwNgErIsuVQhcMhFw0Y9i yej5jSsI4f0xnUF8LquHBiccYxRQdChIOoXdberJHUvD7pLxpHRycWogazsL25R6VN/OHI Ulw2vDQKE8ltDZZKoAXr/lZF/Mnq4z++HiA5UTxrlMHR91rWWbbvxIlUcDqmsw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785347280; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sSJNApQzgWvEF93npG7rPKycUEkHut6bzXGdB3pKo8s=; b=rgBzciINMC/LhGf1ykwRW9ropSB22LKpsVucg3L6GB7J9CRgpYLGMCXm8gztxc21KqRxUf o9RfMt9tTnpyJMcwNppNAUXuQxoct+SdiVfzRkJaZcN1ckEXMphUyatjaeJFsGQsvgFxWV 1MAkOoYV5zwYizwEZPxqn5EOv3zTRJsDyjGNijZg8HKIyDUtoAP6COGRUL2Z+FKMjCt3NE tXwRfqWKXhVt/J5QdvBXuh5ejQq/LeDJMvn5OWDsVWo0gf5K82mLm+W6ZFQV4V0FBf3fNl X0fmzjbD+S8XNIayBJh0Mw3MD9+p5cExd7Wg7Rf67HBizhXED5hDvIgu8ccp3Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4h9KYX1bt1zcsb for ; Wed, 29 Jul 2026 17:48:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3ab37 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 29 Jul 2026 17:48:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 7893a7edb43e - main - coredump: Don't assume that the number of ELF segments is consistent List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7893a7edb43e7c7328f8f46e3929e2412b45d048 Auto-Submitted: auto-generated Date: Wed, 29 Jul 2026 17:48:00 +0000 Message-Id: <6a6a3cd0.3ab37.7c9e3a6b@gitrepo.freebsd.org> The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7893a7edb43e7c7328f8f46e3929e2412b45d048 commit 7893a7edb43e7c7328f8f46e3929e2412b45d048 Author: Mark Johnston AuthorDate: 2026-07-27 15:42:49 +0000 Commit: Mark Johnston CommitDate: 2026-07-29 17:45:02 +0000 coredump: Don't assume that the number of ELF segments is consistent 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. Approved by: so Security: FreeBSD-SA-26:55.elf Security: CVE-2026-58088 Reported by: Maik Muench of Secfault Security Reviewed by: kib, emaste Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D58416 --- sys/kern/imgact_elf.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 7c78d66b3648..08e9718c4d24 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -1585,6 +1585,8 @@ typedef void (*segment_callback)(vm_map_entry_t, void *); struct phdr_closure { Elf_Phdr *phdr; /* Program header to fill in */ Elf_Off offset; /* Offset of segment in core file */ + int numsegs; /* Maximum number of segments */ + int nextseg; /* Next segment to fill in */ }; struct note_info { @@ -1701,10 +1703,15 @@ __elfN(coredump)(struct thread *td, struct coredump_writer *cdw, off_t limit, in } /* - * Allocate memory for building the header, fill it up, - * and write it out following the notes. + * Allocate memory for building the header, fill it up, and write it out + * following the notes. + * + * Note that a process sharing our vmspace might be concurrently + * mutating the map, in which case we could populate fewer than + * seginfo.count headers. Zero the buffer to ensure that unpopulated + * headers are still initialized. */ - hdr = malloc(hdrsize, M_TEMP, M_WAITOK); + hdr = malloc(hdrsize, M_TEMP, M_WAITOK | M_ZERO); error = __elfN(corehdr)(¶ms, seginfo.count, hdr, hdrsize, ¬elst, notesz, flags); @@ -1757,6 +1764,11 @@ cb_put_phdr(vm_map_entry_t entry, void *closure) struct phdr_closure *phc = (struct phdr_closure *)closure; Elf_Phdr *phdr = phc->phdr; + if (phc->nextseg >= phc->numsegs) { + /* Only write as many headers as we have space for. */ + return; + } + phc->offset = round_page(phc->offset); phdr->p_type = PT_LOAD; @@ -1769,6 +1781,8 @@ cb_put_phdr(vm_map_entry_t entry, void *closure) phc->offset += phdr->p_filesz; phc->phdr++; + + phc->nextseg++; } /* @@ -2031,6 +2045,8 @@ __elfN(puthdr)(struct thread *td, void *hdr, size_t hdrsize, int numsegs, /* All the writable segments from the program. */ phc.phdr = phdr; phc.offset = round_page(hdrsize + notesz); + phc.numsegs = numsegs; + phc.nextseg = 0; each_dumpable_segment(td, cb_put_phdr, &phc, flags); }