From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D688FC10F14 for ; Thu, 3 Oct 2019 16:13:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ACD9120700 for ; Thu, 3 Oct 2019 16:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119187; bh=cJIv5/qNCRfpgoyHBGiQr4dN6PXNAlmJtOYktcQtAUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=yXmBYOvxnGhC+gv4zDHcMLRyQQ2LSPQNM9Ngn6YmC2tEFYnGdWbfn6UeuJ80xBTI3 Lqnw0LWklZt2SAKMGo4fJZp9tVMYgwABqv6VAZR7qxHF6vL3/yyKDDTma5r5Csr6O2 d0DwFpMDYrR6ArqcjbdR46f+N9cuxvYiqm2W4XHE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733140AbfJCQNH (ORCPT ); Thu, 3 Oct 2019 12:13:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:35566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388195AbfJCQNA (ORCPT ); Thu, 3 Oct 2019 12:13:00 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9781720700; Thu, 3 Oct 2019 16:12:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119179; bh=cJIv5/qNCRfpgoyHBGiQr4dN6PXNAlmJtOYktcQtAUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lAO/3TiOWvlDNPXdhetIIyqNslEY71gdEYg6kYmW1A5WUyLoqLlkfrzaNMRLp+/oC 4+60bGmZGO6IrKXzTHOODdQGuCsmpf/dhNXZm1PXa39EaCoyjN7mUufp9aUJBNnNwV 3rECLUEFBw5zE6zHkMYc8Aopanoxc/JdgekgQgKY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Linus Torvalds , Richard Kojedzinszky Subject: [PATCH 4.14 154/185] binfmt_elf: Do not move brk for INTERP-less ET_EXEC Date: Thu, 3 Oct 2019 17:53:52 +0200 Message-Id: <20191003154514.087761098@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154437.541662648@linuxfoundation.org> References: <20191003154437.541662648@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook commit 7be3cb019db1cbd5fd5ffe6d64a23fefa4b6f229 upstream. When brk was moved for binaries without an interpreter, it should have been limited to ET_DYN only. In other words, the special case was an ET_DYN that lacks an INTERP, not just an executable that lacks INTERP. The bug manifested for giant static executables, where the brk would end up in the middle of the text area on 32-bit architectures. Reported-and-tested-by: Richard Kojedzinszky Fixes: bbdc6076d2e5 ("binfmt_elf: move brk out of mmap when doing direct loader exec") Cc: stable@vger.kernel.org Signed-off-by: Kees Cook Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/binfmt_elf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1123,7 +1123,8 @@ static int load_elf_binary(struct linux_ * (since it grows up, and may collide early with the stack * growing down), and into the unused ELF_ET_DYN_BASE region. */ - if (IS_ENABLED(CONFIG_ARCH_HAS_ELF_RANDOMIZE) && !interpreter) + if (IS_ENABLED(CONFIG_ARCH_HAS_ELF_RANDOMIZE) && + loc->elf_ex.e_type == ET_DYN && !interpreter) current->mm->brk = current->mm->start_brk = ELF_ET_DYN_BASE;