From nobody Sat May 30 12:56:58 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 4gSKxX4nNxz6fskr for ; Sat, 30 May 2026 12:57:04 +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 4gSKxX2PP5z3SQ4 for ; Sat, 30 May 2026 12:57:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1780145824; 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=wYEdbnyfpfIUI/TzEWmfOVFZAMCdUz1W5QCm2EJGDABEdoTIBdygvzf6dLvsEz6JqQoNEo A1kv9Z/E0WuSOVKSFsFyWbIt1rx5Kxz9Ad5avocKtDLyTjY2fGDxj0B+9W81si0DaO9OvK KpGpfjlYGEE2+x0/DD0hu2NqAf8k2yqzvIIJXJ2Xs34kOoE2tMBFDxqoPOOaF4kJd6NZjS 9NYMG+u9BqbJUWKGSq+76226JtMNko7rs4ifEivOWVGaCCj/J1/1EC8QRufC5+zykope5A 7zy5yCagOdrdyNjT2/UW6s2NkAJ+sX41npP1Y2z5TalV+gXj1DfiqT4xi72Jhw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1780145824; a=rsa-sha256; cv=none; b=OihmXvFx2jgaKVdarDQZ/Up/ZyI+0wbJQRkjMLF/GAkHPlMNMUm2qkFSS7cEBpw3FrOrP8 Q9IRYw8I+JmKyfa1zNQMsjWQVncIk5+tYMAPgP/M6Fl+wksU70t6sl8a+/mUTIGNLM8jlo l8tYWTpyXiJ2gjmRFv3v0x/rhDd88F+paAyvFUjz7y0sM12mVNty5fu9nZFKSYF/6Aa01y lKuwB/d17a+WC0qDyoSg9V+xbvZq+P8AEgExsmxVSEfyI16CYaaMZmghKrN01b+wc5Sv62 CcLh5fyKia3+SUFCFXwMFQssdamikifihNQHwtMS+woIgELlEtMulQTdr1WH/Q== 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=1780145824; 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=RegPXwjt+i3NlY0s32txZnWPvkpwBW1/8wgktwH3CPnDTb9rMv7z9BLSSX351JLEKXpRuh Ow4VsOAOWMyllYjXsmr2nCZ7ws7+LH8slVQMBOB4wjnbhJIhZYO80rHeGiKRpeaPrwPC8s rBauHpdjTX2TGOjSxko2ihQXwib0FOz6TYQnfMpbKAlNEYG9P8SbiuCONECat9tSnGXQrg EQVQSLoXjxP9bSAo6jKTxQ6PHyNSeba1vBWBLGoQH8rKE+CD5mIu4g+ArWvBO859VWw3hp tJMuTAsqJQEeGgjjfNltfg1bS6QOSpkigNMPI8righ5r2kPNqwGdQauQlc2LHQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gSKxX1C1Mz1KFx for ; Sat, 30 May 2026 12:57:04 +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 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: 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),