From nobody Wed Jul 29 17:50:37 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 4h9KcZ1g3xz6mb8P for ; Wed, 29 Jul 2026 17:50:38 +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 4h9KcY33LBz3mdb for ; Wed, 29 Jul 2026 17:50:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785347437; 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=rBdxGX97qkvusu8xYR/a4m8rSm0HHHpXwDEo2WWfrE0=; b=gHlEZUKJRgS8J5PuiTjAjxGsfbPS6DVj36tad3jezUEhbUQR+ifPTRT/Ya+Zg7GiSNsxIK k7NB8D3FnRajFmUvTxk4p7c+WtgA8dqZcQkqGnX2iguU7hPJFszu7G8kameVg14gLnI0Nm O72t4Fn/wWItU0Nso/TjXLnCawbfJjRixUVCKA4AYL2mMrGWAwG5Ea6zfbL5gXZPw6zji/ Cn71xr/B/0zq2mnwhaogj1FsB0CQ6+EGCDHDeJyoFv0tuvQoCCI1OaHMFwfjd8mpEhQ/Ok BiHgooAgSfaTUqtohoNRJN6o6g1U+MOd1Qe8rrD6TRbJXJuvnd7RcXml0IgwTQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785347437; a=rsa-sha256; cv=none; b=nLFDHPuibdllARyrsFlxia5LlibsyMXD/CrpZgfoxf6So0LC64bgS3lR9o5BA+QInnabux 8UsiT88cF62D5A/N2+g3BXSJzNWOPMxNTMz5jDn33ws4P5N3e4FQ7iEv3gJIopP7jKvbL9 vAb2izj6ZPoHRmIYYRHSbS0bwAkgwPqPQX5mSviCg9k5wCi+XuC6rJzNyzkQAYlQLjbgSH JaxAM/nJdGS/95ehYW1F8HzP209BC3QHk6THI2CTuJ2Jv1nY5kLTFwEBtI2x2wrER5chNT NbgwLVnuDmCVrB9AZIYxXaa3p1NStimw2SSVCB6/V+Id/JtTGTm4FShcbYkGAQ== 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=1785347437; 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=rBdxGX97qkvusu8xYR/a4m8rSm0HHHpXwDEo2WWfrE0=; b=h5Uvg0m56EN/dq7+7Jx1P7SGds5zkfpLP3xnTTdQlKWaDGx8xnXyX4D4wUj+S5llL8VTXi dc/uBMRyJQu0dePvr1Xa3ncVVe+p6buNr0sM4iWkKj3uRiMd/bRqOkYFLYUxQ8H1F0mWBj P9tHVrgf0yZpp5/WXLbwV8Pp1JmBfto8ge89l1Sx+2Lm/OwwdX5Y1V9S2vftNJB9sjs6MT /TvwOvdwWaxSUqXQADzMrBbjesYTOZAsqATFcRAY0ppnFtzwWNKHboBhT8ScvY9gIlDPdo xfADHrkgpbaxkFNYBZlUPxGkx7dEGA6gbEo4OZ/f06EgNnqmQdkX6j5B/k/fYQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4h9KcY1yHGzcw4 for ; Wed, 29 Jul 2026 17:50:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3baff by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 29 Jul 2026 17:50:37 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 8592efddadf6 - releng/15.1 - 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/releng/15.1 X-Git-Reftype: branch X-Git-Commit: 8592efddadf6f192740a1ad8404c1ad9cee57245 Auto-Submitted: auto-generated Date: Wed, 29 Jul 2026 17:50:37 +0000 Message-Id: <6a6a3d6d.3baff.22c5183@gitrepo.freebsd.org> The branch releng/15.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=8592efddadf6f192740a1ad8404c1ad9cee57245 commit 8592efddadf6f192740a1ad8404c1ad9cee57245 Author: Mark Johnston AuthorDate: 2026-07-27 15:42:49 +0000 Commit: Mark Johnston CommitDate: 2026-07-28 17:34:40 +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 27b7b0da824e..52223c3b1ce4 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -1555,6 +1555,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 { @@ -1671,10 +1673,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); @@ -1727,6 +1734,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; @@ -1739,6 +1751,8 @@ cb_put_phdr(vm_map_entry_t entry, void *closure) phc->offset += phdr->p_filesz; phc->phdr++; + + phc->nextseg++; } /* @@ -2001,6 +2015,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); }