From nobody Wed Jul 29 17:48:45 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 4h9KZP5LcJz6mZcB for ; Wed, 29 Jul 2026 17:48:45 +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 4h9KZP1zm8z3hhP for ; Wed, 29 Jul 2026 17:48:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785347325; 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=mueZpHtyTJ+Ser53PgH/5QGXlqhuc4/HUHk3mhyOUZo=; b=vc4MYKomYM2LqJfZTGrymWCvU7RwcDmoVKnUHhK+u/cSiE5M/6jNRWVu2bBD+1LAso+Cnb Tq0VU7YXA0Sn1Rs8b1+FOG9dvaUffTJEaTiaUW0NCVK7tmXz1yX76PjfUJx4ug+Y74Z56F HDAZ+A/E1KIjUHimxmMPhkmQb96WQOK727vaKdr3M/o4GgV8kOQ0as0+TdnerRFjfUm18J YOhpewuxcWC2ni3U+dXxNCUOKs+C6NjDIlrMblVEvo9JBqL90fTRtzVjUh765QDDIe/7yP cLWbqsO1Jt/ImPNAmzZHOYMw/hHywZpzL4Co/p/h5f5ebUt01vDPJNvx8l7FPA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785347325; a=rsa-sha256; cv=none; b=B2hfjPdd+Tj/f3lP6oZeThzMIiz5Y60hoclfY8JjKqojNxY3fKnmi9yEQOruJuse+aHkqV q39CsuKeM13Tmilx97mp3alr3TLpdQ7kJMKUWihF2OJ/DpWU6jf0xq9LFuM0Qn9jWbKTHQ eiaFgBGJ1GfXaisPsPLpflWWspJDILICdvC+xpocKWlMtZsnsOtkuj3BGC8nOaLyxmx+0K PyGrqV5Wyq/Csx/OiIJ+6ffHz5VikV/5x7o3XflZPJXvxBH6JxgB+NKQpGRAHzQ104BnCD EisSWNJCbKtZgiW1PM4qKmTgoHIvr1BQe7dNHNUzN0KCPIqrsaQOP31XjHV14g== 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=1785347325; 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=mueZpHtyTJ+Ser53PgH/5QGXlqhuc4/HUHk3mhyOUZo=; b=iWDYUK+nx3bRKNuODOXlOEvzpRZ3YOCEYPBZ46IgvBRHj+sFz+HJL8vCJIdWqbr/MyGWjG KYLs5NcLbUKZsEnHwAs0fnaIjyv5as/6r2J0sJBq+8OQ5czf5Sp5kYrH0U+6fxl7ZaUws6 rUdm+41drpVF8Rf2p2VvibgA7b/qw9kaN7RIZnSRLsrSYkmlEVQDQkzw41E05pGylMeeTL k6YKEr0jOEhmW3n/pKjxGuGHi1WU+T5E+kPOFbQNkdoqsjq3l6Kw4CMk0xfckCVs7Z6ImV Ck85UkO1x4sqq0ZbQB9T0FQgCgdXvLAzPZBFNaITK+iZo+mW2WljNzMoso6QXA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4h9KZP10crzcsf for ; Wed, 29 Jul 2026 17:48:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3af88 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 29 Jul 2026 17:48:45 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 008d3bafa124 - stable/15 - 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/stable/15 X-Git-Reftype: branch X-Git-Commit: 008d3bafa124fc0751cbacbd0557cb1927856624 Auto-Submitted: auto-generated Date: Wed, 29 Jul 2026 17:48:45 +0000 Message-Id: <6a6a3cfd.3af88.61b917ee@gitrepo.freebsd.org> The branch stable/15 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=008d3bafa124fc0751cbacbd0557cb1927856624 commit 008d3bafa124fc0751cbacbd0557cb1927856624 Author: Mark Johnston AuthorDate: 2026-07-27 15:42:49 +0000 Commit: Mark Johnston CommitDate: 2026-07-29 17:48:13 +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 a9ee58d941c4..c27d61e81ed4 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -1584,6 +1584,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 { @@ -1700,10 +1702,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); @@ -1756,6 +1763,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; @@ -1768,6 +1780,8 @@ cb_put_phdr(vm_map_entry_t entry, void *closure) phc->offset += phdr->p_filesz; phc->phdr++; + + phc->nextseg++; } /* @@ -2030,6 +2044,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); }