From nobody Sun Dec 19 02:44:32 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 BD56118E4C3D; Sun, 19 Dec 2021 02:44:34 +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 4JGn9r6Pdxz4qVV; Sun, 19 Dec 2021 02:44:32 +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 9EE151ADAE; Sun, 19 Dec 2021 02:44:32 +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 1BJ2iWDl012686; Sun, 19 Dec 2021 02:44:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BJ2iW9r012685; Sun, 19 Dec 2021 02:44:32 GMT (envelope-from git) Date: Sun, 19 Dec 2021 02:44:32 GMT Message-Id: <202112190244.1BJ2iW9r012685@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: f1b1fa3505e6 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: f1b1fa3505e666134c66588659ba63601615e947 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639881873; 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=S79TWqcRuqgryDIeCz7x96yXDlvLgwOv9Ih4q00oTC8=; b=OcaDjomeyhsBuJvBk9pHHNYjmq2UExZpr0eEHcUYDxi9YW+RMfrTba+lDKtpvOtwPySshb MbZdljrtVI3z4IrMVgYNMVt9OKHFNhaqBbnRP2Y/XlNHdIOrt6UIqmeLKtjvyVcNIIrHvr ZFzA3bCv5U2286baX1jsCQa/JUHuT+N0+qxafJpWigOES0I3q5Nq0+ze3gDSnOUwcv6zm4 dYG401LpiI8RzCveKerg6xAXdq0Dnx5mO8UshR871RTezqHm4ZE+3Y0Ugl5ft3O2JecMlp bCDkKz1gv/d+SDax1VGgO5z8RRTdgW7E5q8enkV3saSY8zxXgGup/D+rBGc7Aw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639881873; a=rsa-sha256; cv=none; b=RSAr3cbcwxgYBZFor6dmzCSxgW1KJfNKHs11G9UxLw8MWdBCCx5txB1u/trb976ptRhach VjgYigo8UiWheWhulj7KJvJ+vQha9pS5b1SYH+yXIySEIgAAg+5UfNPlOXEq1bqvXfubFE NNIMc9rsA7f/8IQJhzGlodbvgrajoPGRwF4UdcBtqT9dLWCPYz8tidwcd3psI81nakhRyR tgMI8ammImj6A8KHqUe6z/JYSEJPyVQHiJMDJmiPNBhGvqX5v9fkDxRieyZiGouk8NRPeb ApBISz4s5XSHomDZGLcgmuuJ1jnxLFPM1TnIuMe2DQKtGxhP+g9A3rDxyv4/Ug== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=f1b1fa3505e666134c66588659ba63601615e947 commit f1b1fa3505e666134c66588659ba63601615e947 Author: Konstantin Belousov AuthorDate: 2021-12-08 09:33:19 +0000 Commit: Konstantin Belousov CommitDate: 2021-12-19 02:42:51 +0000 imgact_elf: avoid mapsz overflow (cherry picked from commit bf839416381cb9f63a8a82ea6e897a22830a8009) --- 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 17c0752c35fa..0f42017cb7ef 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -1162,6 +1162,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++; @@ -1290,6 +1295,11 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) imgp->proc->p_sysent = sv; 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"));