From patchwork Fri Jun 2 15:20:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 9762827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 942E460360 for ; Fri, 2 Jun 2017 15:21:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8670E2857B for ; Fri, 2 Jun 2017 15:21:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B4F528585; Fri, 2 Jun 2017 15:21:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id AB09728577 for ; Fri, 2 Jun 2017 15:21:03 +0000 (UTC) Received: (qmail 19747 invoked by uid 550); 2 Jun 2017 15:20:34 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 19591 invoked from network); 2 Jun 2017 15:20:31 -0000 X-Authentication-Warning: annuminas.surriel.com: riel set sender to riel@redhat.com using -f From: riel@redhat.com To: linux-kernel@vger.kernel.org Cc: kernel-hardening@lists.openwall.com, akpm@linux-foundation.org, mingo@kernel.org, oleg@redhat.com, lwoodman@redhat.com, mhocko@suse.de, danielmicay@gmail.com, will.deacon@arm.com, benh@kernel.crashing.org Date: Fri, 2 Jun 2017 11:20:05 -0400 Message-Id: <20170602152010.2064-2-riel@redhat.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170602152010.2064-1-riel@redhat.com> References: <20170602152010.2064-1-riel@redhat.com> Subject: [kernel-hardening] [PATCH 1/6] binfmt_elf: document load_bias a little bit X-Virus-Scanned: ClamAV using ClamSMTP From: Rik van Riel After me and another unnamed developer got confused by the subtraction of vaddr in this branch of the code, followed by adding vaddr back in a little bit later, for the third time, maybe it is time to document this quirky bit of code. Signed-off-by: Rik van Riel Acked-by: Kees Cook --- fs/binfmt_elf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 5075fd5c62c8..8c3f4dbc7603 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -930,10 +930,16 @@ static int load_elf_binary(struct linux_binprm *bprm) if (loc->elf_ex.e_type == ET_EXEC || load_addr_set) { elf_flags |= MAP_FIXED; } else if (loc->elf_ex.e_type == ET_DYN) { - /* Try and get dynamic programs out of the way of the + /* + * Try and get dynamic programs out of the way of the * default mmap base, as well as whatever program they * might try to exec. This is because the brk will - * follow the loader, and is not movable. */ + * follow the loader, and is not movable. + * + * The load_bias is the difference between the address + * in the elf header and the address where the binary + * is mmapped. + */ load_bias = ELF_ET_DYN_BASE - vaddr; if (current->flags & PF_RANDOMIZE) load_bias += arch_mmap_rnd();