From nobody Sat May 30 12:56:58 2026 X-Original-To: dev-commits-src-main@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 4gSKxR0hwMz6fsqf for ; Sat, 30 May 2026 12:56:59 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gSKxQ6Zwmz3SY2 for ; Sat, 30 May 2026 12:56:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1780145818; 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=jNAYHPVIEe0vnEIq5eNJJlcZ+3gr2sEgO4p/79o7N7A=; b=RISdCyp+iI29wM2duGoDaS7WwMTGYxXk9q8OhwdZKR0GhTCmoEsiuub3yReLyZ5MbzlHUl +jj60XzZhfKYt7qe+PGQs+1HcC3xwngedD6+GPdSiyv6oiu4TrptFtRQWd9bDH9V8hpajp 8Nhz6pW/xABuEOquhtU5vUfI0bMnPjUKrBBJ2gWqNLLbxzHGXnvnQDZYKDhOac67aJV+tA lKD6pUSEIy/5NtyKunE+DIKq5ewxR5txfjh6QbmTUAP2YzQfQ/+ByseFgdJ1o7or+pzHzD nEKQNJXIMWsM2sPFwIy0fZ41aDfcwnl5a4MLh9HmQj5myacrR2PXHTZ/2pTLgw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1780145818; a=rsa-sha256; cv=none; b=FwFnv8vWRq2dGvRukthk90m/R1IaSUsHbUE4pnFJJq+MX6qJRYeN/Uvjxb6nokDFRKF7aj 50WbxIjWhbS38ftn+X2LKtCZc4zAhEo+cyvKF6y/7aesKhv6YgC65TOPFxnCxsAROCkB0L SH6mFnpnXS//WMMNDKLskLkS3S5JN0CaN+T0x3nVDwM6odTLIEM/TnE1TjpyX+lHHYIkJk vjEUAEzX9X4pMIBIi8HhzVZuZgTisLSx8eXg2dtFS+7gE/tPSvjGadtBg/srFGvu7ZBhog RT+8AI49zlOSV81ERgfLNh/D83F7AKVu8jU5Lm1JdgOgZ16jmB+sWE8PGjij8w== 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=1780145818; 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=jNAYHPVIEe0vnEIq5eNJJlcZ+3gr2sEgO4p/79o7N7A=; b=EmS3gbkHCbsbYc6LsENy5i/GrIpM8nglZDFP163Bg5BtFfvr+eEhtHL5/geyxIjSAXzMmA yJpota32vdHydM9209qljiyQ+6yUBnjRxsoEVWtFoMXBELQWJTB+yeZ+Sn9wKWW6LLMeWf zfVWX7OrLU4ZKEVGGWCjG6RYNwr7XhtI6INpgN7qArrqzmtmvilCtwSK+jQFilGRpMAC8j dIO5GLd16s3zXBtYgI1/A2i+1fgEZC4jdGcpDz21K4ej9ce9EL5XNBL9KerB4RBdd0n9bc zdsPPyW1/mA2WkeHi3GajyJwRGvuz/OClvcDt6r0dTazvgXcv51yBxT/6YgwDA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gSKxQ5kS6z1KTs for ; Sat, 30 May 2026 12:56:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 222f8 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 30 May 2026 12:56:58 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 201090678e03 - main - imgact_elf: add sysctl kern.elfXX.phnums for the number of program headers List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 201090678e033237e20d80eb29cc059e0df9a1e1 Auto-Submitted: auto-generated Date: Sat, 30 May 2026 12:56:58 +0000 Message-Id: <6a1ade9a.222f8.4f36754a@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=201090678e033237e20d80eb29cc059e0df9a1e1 commit 201090678e033237e20d80eb29cc059e0df9a1e1 Author: Konstantin Belousov AuthorDate: 2026-05-29 14:47:31 +0000 Commit: Konstantin Belousov CommitDate: 2026-05-30 12:56:40 +0000 imgact_elf: add sysctl kern.elfXX.phnums for the number of program headers that are accepted in the activated image or interpreter. Requested by: jhb Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D57328 --- sys/kern/imgact_elf.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index e3969223c170..b889c4a14866 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -84,8 +84,6 @@ #define ELF_NOTE_ROUNDSIZE 4 #define OLD_EI_BRAND 8 -#define ELF_OFFPAGE_PHNUM 128 - /* * ELF_ABI_NAME is a string name of the ELF ABI. ELF_ABI_ID is used * to build variable names. @@ -229,6 +227,11 @@ SYSCTL_BOOL(ELF_NODE_OID, OID_AUTO, allow_wx, CTLFLAG_RWTUN, &__elfN(allow_wx), 0, "Allow pages to be mapped simultaneously writable and executable"); +static u_int __elfN(phnums) = 128; +SYSCTL_UINT(ELF_NODE_OID, OID_AUTO, phnums, + CTLFLAG_RWTUN, &__elfN(phnums), 0, + "Max number of program headers to accept"); + static const Elf_Brandinfo *elf_brand_list[MAX_BRANDS]; #define aligned(a, t) (rounddown2((u_long)(a), sizeof(t)) == (u_long)(a)) @@ -855,17 +858,14 @@ __elfN(load_file)(struct thread *td, const char *file, u_long *addr, goto fail; } - if (!aligned(imgp->image_header + hdr->e_phoff, Elf_Addr)) { + if (!aligned(imgp->image_header + hdr->e_phoff, Elf_Addr) || + hdr->e_phnum > __elfN(phnums)) { error = ENOEXEC; goto fail; } if (__elfN(phdr_in_zero_page)(hdr)) { phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); } else { - if (hdr->e_phnum > ELF_OFFPAGE_PHNUM) { - error = ENOEXEC; - goto fail; - } VOP_UNLOCK(imgp->vp); phdr = m_phdrs = malloc(hdr->e_phnum * sizeof(Elf_Phdr), M_TEMP, M_WAITOK | M_ZERO); @@ -1165,11 +1165,13 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) uprintf("PHDRS wrap\n"); return (ENOEXEC); } + if (hdr->e_phnum > __elfN(phnums)) { + uprintf("Too many program headers (%u, %u max)\n", + hdr->e_phnum, __elfN(phnums)); + return (ENOEXEC); + } if (__elfN(phdr_in_zero_page)(hdr)) { phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); - } else if (hdr->e_phnum > ELF_OFFPAGE_PHNUM) { - uprintf("Too many program headers\n"); - return (ENOEXEC); } else { VOP_UNLOCK(imgp->vp); phdr = m_phdrs = malloc(hdr->e_phnum * sizeof(Elf_Phdr),