From nobody Sun Dec 12 14:30:37 2021 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 1EABE18E8FCC; Sun, 12 Dec 2021 14:30:43 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JBn9q57f7z4mRT; Sun, 12 Dec 2021 14:30:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 82C86220F6; Sun, 12 Dec 2021 14:30:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BCEUbIR066743; Sun, 12 Dec 2021 14:30:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BCEUbmS066742; Sun, 12 Dec 2021 14:30:37 GMT (envelope-from git) Date: Sun, 12 Dec 2021 14:30:37 GMT Message-Id: <202112121430.1BCEUbmS066742@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: bf839416381c - main - imgact_elf: avoid mapsz overflow 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org 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: bf839416381cb9f63a8a82ea6e897a22830a8009 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639319441; 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=wQFPTkGE/hSkOEuZrfGmr0GpHKhz2kYBXvr7Z5rFdTI=; b=gc3TgSYnNPDGA7x2lBmiHdxF8/VD8X5nDM+se0mTvROLZbaTnVdA1ItoqBb+8r43A85hHI lDm9i5RrugwGDo/muT8FE4DLNWmcv+nzfsZu/QI8L/KZKM/K6iG9efrQxhGj8H40y84hKQ SvASQa0jTdVSO8sZNTr5vZCsJNLWvnULMh/nLleCsaIaS5SGkDdztjzdixgJG2xEdJXE78 vvg7S0Lk2N18oUy5d3iGevDDVM+EvwVMFFsTJTZ/8QYbsMZi6wk679yHzKgNLIEIyBaGaK BBwYCxvaG5lSk3VRKxITVTOPjI8c9piA04jqLThLtBAuB4z52MVmAegHaZGxHg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639319441; a=rsa-sha256; cv=none; b=VuRhhxxIc5zgpBHQrECu0H9wjK73P2FUrLZW06YbA1GSYhI7X7TLJ2zpNlsHAY9QTtnqj0 gRtqrcS101vzSQCaNnKNMpjzvvMLjkfsUc/cFyHYnC2ic1/BJw0dM0InlmvBSdJ2RnNgbZ mtggIleA3hZ+jW8Obn5++L/K0WXNm2Ex/s9CvOEFM6aV73morUrH98D7FJHckxy1sIjVbc SlO/OcrkIECug9iIICBzxwvEBE9zrAXVw7MTT06pV+AUJtcMlSXD9w2PzZp8/LpZ4Ar2+t N93VIsDub8ZMe4VVnP/QhDoFDe0yZhqWE9nQAbXWzYMc3x4DOYQni9now3l/Pg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=bf839416381cb9f63a8a82ea6e897a22830a8009 commit bf839416381cb9f63a8a82ea6e897a22830a8009 Author: Konstantin Belousov AuthorDate: 2021-12-08 09:33:19 +0000 Commit: Konstantin Belousov CommitDate: 2021-12-12 14:28:39 +0000 imgact_elf: avoid mapsz overflow Reported and tested by: pho Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33359 --- sys/kern/imgact_elf.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index d4c5a6341ee6..b926bc926611 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -1182,6 +1182,11 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) } if (phdr[i].p_align > maxalign) maxalign = phdr[i].p_align; + if (mapsz + phdr[i].p_memsz < mapsz) { + uprintf("Mapsize overflow\n"); + error = ENOEXEC; + goto ret; + } mapsz += phdr[i].p_memsz; n++; @@ -1311,6 +1316,11 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) imgp->proc->p_elf_brandinfo = brand_info; maxv = vm_map_max(map) - lim_max(td, RLIMIT_STACK); + if (mapsz >= maxv - vm_map_min(map)) { + uprintf("Excessive mapping size\n"); + error = ENOEXEC; + } + if (error == 0 && et_dyn_addr == ET_DYN_ADDR_RAND) { KASSERT((map->flags & MAP_ASLR) != 0, ("ET_DYN_ADDR_RAND but !MAP_ASLR"));