From patchwork Tue Jul 30 05:51:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11064931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B757D13A4 for ; Tue, 30 Jul 2019 05:52:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8FCD28704 for ; Tue, 30 Jul 2019 05:52:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D80328718; Tue, 30 Jul 2019 05:52:42 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15C4628704 for ; Tue, 30 Jul 2019 05:52:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3323D8E0002; Tue, 30 Jul 2019 01:52:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2E1CF8E0003; Tue, 30 Jul 2019 01:52:38 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 182788E0002; Tue, 30 Jul 2019 01:52:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id B14998E0003 for ; Tue, 30 Jul 2019 01:52:37 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id b12so39572633ede.23 for ; Mon, 29 Jul 2019 22:52:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zeV7cRDg//NBM0c2n9mDOnVPZ/BNPft3Bx8vY7oRip8=; b=LULngB6248yWJFeMvI8Z67om7OEs8M0AlSR9LbJ0vLCTHI5eqJsVh9ASR983Y50xHZ mGJzm4Uy5wJDq2FmQQOU3nBmT9Nd4rABqu4EhZbSDkYF6t9T2jZ3thjKyF34bNe7RsoU ygSe7t37EYbBN1gpMdkansaUbfG6AFiGlIhwBpo7dkWEtRkNqEva/Tm333rist2bxM3+ abqTtZL8F0NaaMS/nsk6FZjb9HhyayWWa2AKBY72qj7YB60ybeR+0V6tymszFcesBnpV M258Dk8is1kTr3ldrhlvNfoZcZrb0c4x01cYlr8LcQtuoEhsRZsx5xF3PQd5g52kRyzX WmCg== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAWoshToAwgoOcF1U3lVaOLL4SLMfYnwOH/yJjpz+mWxfL0e4ktL z6X1uiXRzLz34nSkFNQxGFUYlWtFv/9w9+1YHyFcutwCYZes4r4ezuIQC6uLsAhZKKdVjAWEr7z vhJC5CH/eg9AFGp76u0qaaUb4NO8GQo982wlDk/CdBjmwQfF3tauj2CpPqLU7cE0= X-Received: by 2002:a17:906:19c6:: with SMTP id h6mr31213ejd.262.1564465957256; Mon, 29 Jul 2019 22:52:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhMCCh14+Xe11jHiRbURLfr6oG98TiTHAuZzT5wxJ3mk+Gp+U/Dik7TJ8t8lBani6Yf1BD X-Received: by 2002:a17:906:19c6:: with SMTP id h6mr31185ejd.262.1564465956375; Mon, 29 Jul 2019 22:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564465956; cv=none; d=google.com; s=arc-20160816; b=NotiSM/eF9udhu4P58FYLf/kitMsZSBVMWTW6zzMLsYRdTcFnAEczlmJPGN12CAvZC 3pw3fDVPgAnZa9/aCjG4CBWJQOnVuVtclyC/EyJM8DvOtn2V5EihpNHVWG32OTUWXwLp cmih37DslNcP75y2woCzWaxVjwQ//UbvZsrb34XgAgg1K1nSZSd6U4IXD93+JNWBmNCD li13luQoYvmwZaL10dZxAk+PRrNK+Fke2CWHNopgvosZV1lxWQyf3QMBbm+Rx9U3frQb ZrQdJ6hz3FHluf2kioO6t0OgImnSUwdh+MWv2JlSizPBI2vUWvFR5YjiTKmjiAJAsJGu eoXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=zeV7cRDg//NBM0c2n9mDOnVPZ/BNPft3Bx8vY7oRip8=; b=QZNLVswtKByMe2cwSWygXAe515rlSis5qO4SupUQBzJoDvDtAFtG2r6UPjQCXn9otA f0WnNUcBoymPYQPfSuttvT32kV1wFQhp5R6vZ50AdZrSxOHqjiIr6GwIOjVmRm4rKzt6 V+OjzKgBgY57v4u8m1WTVBD6MmVsnJOJ42wgZeSNaN/jD1uNojgcAjJYxxhgFkXz3hPq iGVm6SfeNuQ+9sP9kGAWSVBalkv9ouwjAiAyROCSFyWdpOnnECqtmxb8PcicB5BMEGKM cE+GeLjViyvEa2xxTkSOnOpgVnJSEiLs/XWjndDZKUNYOPIKZRhm4w4qKKu4v9QyjGd3 9IVw== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net. [217.70.183.201]) by mx.google.com with ESMTPS id by8si16345785ejb.129.2019.07.29.22.52.36 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 22:52:36 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.201; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id C4A9E1BF20E; Tue, 30 Jul 2019 05:52:31 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH v5 01/14] mm, fs: Move randomize_stack_top from fs to mm Date: Tue, 30 Jul 2019 01:51:00 -0400 Message-Id: <20190730055113.23635-2-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This preparatory commit moves this function so that further introduction of generic topdown mmap layout is contained only in mm/util.c. Signed-off-by: Alexandre Ghiti Acked-by: Kees Cook Reviewed-by: Christoph Hellwig Reviewed-by: Luis Chamberlain --- fs/binfmt_elf.c | 20 -------------------- include/linux/mm.h | 2 ++ mm/util.c | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index d4e11b2e04f6..cec3b4146440 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -670,26 +670,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex, * libraries. There is no binary dependent code anywhere else. */ -#ifndef STACK_RND_MASK -#define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT - 12)) /* 8MB of VA */ -#endif - -static unsigned long randomize_stack_top(unsigned long stack_top) -{ - unsigned long random_variable = 0; - - if (current->flags & PF_RANDOMIZE) { - random_variable = get_random_long(); - random_variable &= STACK_RND_MASK; - random_variable <<= PAGE_SHIFT; - } -#ifdef CONFIG_STACK_GROWSUP - return PAGE_ALIGN(stack_top) + random_variable; -#else - return PAGE_ALIGN(stack_top) - random_variable; -#endif -} - static int load_elf_binary(struct linux_binprm *bprm) { struct file *interpreter = NULL; /* to shut gcc up */ diff --git a/include/linux/mm.h b/include/linux/mm.h index 0334ca97c584..ae0e5d241eb8 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2351,6 +2351,8 @@ extern int install_special_mapping(struct mm_struct *mm, unsigned long addr, unsigned long len, unsigned long flags, struct page **pages); +unsigned long randomize_stack_top(unsigned long stack_top); + extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); extern unsigned long mmap_region(struct file *file, unsigned long addr, diff --git a/mm/util.c b/mm/util.c index e6351a80f248..15a4fb0f5473 100644 --- a/mm/util.c +++ b/mm/util.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include @@ -293,6 +295,26 @@ int vma_is_stack_for_current(struct vm_area_struct *vma) return (vma->vm_start <= KSTK_ESP(t) && vma->vm_end >= KSTK_ESP(t)); } +#ifndef STACK_RND_MASK +#define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT - 12)) /* 8MB of VA */ +#endif + +unsigned long randomize_stack_top(unsigned long stack_top) +{ + unsigned long random_variable = 0; + + if (current->flags & PF_RANDOMIZE) { + random_variable = get_random_long(); + random_variable &= STACK_RND_MASK; + random_variable <<= PAGE_SHIFT; + } +#ifdef CONFIG_STACK_GROWSUP + return PAGE_ALIGN(stack_top) + random_variable; +#else + return PAGE_ALIGN(stack_top) - random_variable; +#endif +} + #if defined(CONFIG_MMU) && !defined(HAVE_ARCH_PICK_MMAP_LAYOUT) void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) { From patchwork Tue Jul 30 05:51:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11064955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 971E713A4 for ; Tue, 30 Jul 2019 05:53:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83DCE28704 for ; Tue, 30 Jul 2019 05:53:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 754A428714; Tue, 30 Jul 2019 05:53:45 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E656028704 for ; Tue, 30 Jul 2019 05:53:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D0AF8E0008; Tue, 30 Jul 2019 01:53:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 181748E0003; Tue, 30 Jul 2019 01:53:44 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 049828E0008; Tue, 30 Jul 2019 01:53:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id AAD918E0003 for ; Tue, 30 Jul 2019 01:53:43 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id r21so39634995edc.6 for ; Mon, 29 Jul 2019 22:53:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LklZI+jjNy9P/Vf1oDAlKWfBdOZ3w4ODTtcULXIYH+w=; b=Qir4hcLqluTph1VEMJeyNWolANlmbocuX1H5jDM6B4dCGBuPq2JQt+XErxZUbUwVyv x4lVzBBpq1dNwj7KEOCyMyQb2QeBo8eX79rqUFEcLXPkQBIeYZmYRM1rAzW0sOZ4pYXM GWlOKGW2KixrqGW0eWaaHNIqSYfWZe6a+C1Mp1nh7oGcBazQCIiNcfamPhVUZ6HALjFR NBa1GrquQtKSLVp9VN36yQkvVmNfwolwb36/68/ho2zgfjigxJ8RpVpN8KnP+5CSOuWp uJdNO4xDX5KSwBTkd9bJ+6XTE+knCRCOFIzWL5tIHCNHVbonfSbJE9c3QN6WvrS2Q2JU RteA== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAXpsIyAhpPFSidvmRWkgV9Xdl/T6qdp1YcP7FNkwvpE3ThNBvR3 gazqKwHjIFg0/HNhqMS1xel7PG4kqvVcm3gfFy+F9+g1iCZBHN7w8BkygR+qb3qQziqefbEcEPG fnuSJRH2LpjzZ7po+9QLu8EOzCTljKgpIQX7zh0GN8CDvjks2xvuwldJkhl8amn4= X-Received: by 2002:a50:9729:: with SMTP id c38mr102498609edb.283.1564466023218; Mon, 29 Jul 2019 22:53:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqzckmsRdiSFtrdRq/s9cZSyOxhH1cbkR2ytIbHagtmh9mCnSZNFAJDedONgQgU2XZ1WJU91 X-Received: by 2002:a50:9729:: with SMTP id c38mr102498577edb.283.1564466022502; Mon, 29 Jul 2019 22:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466022; cv=none; d=google.com; s=arc-20160816; b=bDInWtKWZTsUkj6DqZa4Z373rP0/BSYrd62urlgr5Z/Yq/Kh234XrxWNWxhZGTagV9 j8PR4B01SZ1myVja7ScLoUhvhv0ujWYaFjZBjPzi40mhb8DUxMv5ADdU4RAUWY7A4ceB AvgmMU0eKzOzH+xAMJaW84c8q7Mvs4ocgSnaljk5x8kymA6/r2f4BUKdt8tAQlk9LyLc qGew8KVi1On7Xs1H/PhMeeikttHm6T/XqfNjFtJWYzNEGS3PZtHpKSNF6zRuLvG3BAci 8rc2dJYr86NZ5JzQSq7dbmTm5IF8PMUa2p4V5LTWs5FoqofKNHvumU0vbAmzjO0nONs1 T3fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=LklZI+jjNy9P/Vf1oDAlKWfBdOZ3w4ODTtcULXIYH+w=; b=NRIhCxdCfgznOQbfMfuUqGPjR8BbdhIV4tKMyj/0Z8cwN59mJo/mPLRAz41g5+9r8v Pls61ASAgKq7x04rZQQtodTub0Ve4Om2LTzI7tG37vKqwB/ksO8K+rE1L89RhZnv7HSD t/S8rKbiQClsyZxFLG+RCca7V+WOHa39k0zbinjB0rot/ScN2wzs43psO3JDfLmyq4CC D33iVUwsWpu/8imkEeYUQ8YJHz+KuqFjXho7klSa2eU6wbSSuz377lVpaNMi4jNfhAYm l4S++NJOL6ckorxLqdiZ84/xw3xxCjW8W7oiFUpUUmszBW6OghBkkQWHy7mDmLe0Sijs d7hw== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net. [217.70.183.200]) by mx.google.com with ESMTPS id l8si18237170eda.181.2019.07.29.22.53.42 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 22:53:42 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.200; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 8A9D220002; Tue, 30 Jul 2019 05:53:36 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH v5 02/14] arm64: Make use of is_compat_task instead of hardcoding this test Date: Tue, 30 Jul 2019 01:51:01 -0400 Message-Id: <20190730055113.23635-3-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Each architecture has its own way to determine if a task is a compat task, by using is_compat_task in arch_mmap_rnd, it allows more genericity and then it prepares its moving to mm/. Signed-off-by: Alexandre Ghiti Acked-by: Catalin Marinas Acked-by: Kees Cook Reviewed-by: Christoph Hellwig Reviewed-by: Luis Chamberlain --- arch/arm64/mm/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index b050641b5139..bb0140afed66 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -43,7 +43,7 @@ unsigned long arch_mmap_rnd(void) unsigned long rnd; #ifdef CONFIG_COMPAT - if (test_thread_flag(TIF_32BIT)) + if (is_compat_task()) rnd = get_random_long() & ((1UL << mmap_rnd_compat_bits) - 1); else #endif From patchwork Tue Jul 30 05:51:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11064967 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13DAC13A0 for ; Tue, 30 Jul 2019 05:54:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0656E2870F for ; Tue, 30 Jul 2019 05:54:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE16328716; Tue, 30 Jul 2019 05:54:49 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BDC228714 for ; Tue, 30 Jul 2019 05:54:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8FA18E0009; Tue, 30 Jul 2019 01:54:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D3FE08E0003; Tue, 30 Jul 2019 01:54:48 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C08BE8E0009; Tue, 30 Jul 2019 01:54:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id 758518E0003 for ; Tue, 30 Jul 2019 01:54:48 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id a5so39618548edx.12 for ; Mon, 29 Jul 2019 22:54:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=21mhY1F6D/bVN4FBUSB5kLGwxQH8yFVmkExK3y72E74=; b=jrqb7JGm92QXZ0alcG82OMeczFU1SULFWeK2DHnDIB11NzHmANiQASOEfwx4CAwlZr OxASE4GplSrqQM0VIY/BodH5cOvuPY7L3lZ3BTqItspEDAozI/6mWDr7/S2xzzls2eBI T64ulChBph0mTsX9wmkYIS8vNruUO/oOgRn8JZpST/rzdRuD79AzJy1muGwED2b09Kl/ K8tr0Xzr+l230gZJH+VprNlxWjR7mENKCJIudb1dd/dM34uSSZfHJ9619GySqljkh5Zm XysHsFQl6BbXLg+Kaa2SvwrkJ6OetV8uXgT2SntB1Q/50t4C4/rNGdA49xQA1rScrpq/ gJQw== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAXJcPz6HfrEvrHKL+esqE2sR67a9QMkd34Hc2WBFUkMBRR8j6F7 3xo3Ty2RgABDGqgbrQ9inKMhnxxs+bwU46RsQ7fXTfff+BEhiFdRsQqlj7jG2yhHuMp77mawirr dZj7hDqhqMzEDfw/VM4nYD3nqw/LP1hpYhcAqQcZL+4ccNTgbj6wAlhPAv7AMn+Y= X-Received: by 2002:a17:906:7f0f:: with SMTP id d15mr90416213ejr.39.1564466088034; Mon, 29 Jul 2019 22:54:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8Bm76AKSGnSrhiG6X5Zh2BLmVFl+/E4DDFTB9Y6uzZw3q14PZ2s1C62+pB93vN37k0PJj X-Received: by 2002:a17:906:7f0f:: with SMTP id d15mr90416170ejr.39.1564466087024; Mon, 29 Jul 2019 22:54:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466087; cv=none; d=google.com; s=arc-20160816; b=gww4FpjX+Bj+0bDVtTHnClfzpp5Llf/7tClIrj+IGbTGAZurKyw7GWw2UDK1evJJ+1 QOz4BfmvnzpOTvbs++zBDulry1UPzUSwX1fDDWzwLaDRJcjywVAJ2XHAMKcrSaticiw9 i8xzWQQVditYCR1Zz7v4/W8/Ty3ojmx9fSzCb8HNpjcyCCXE0pElZWHGG58fEbgbN37/ eWWceK8W7wORY/ftImw9R1EvujMZRgmrtLLpwOg0tWibUC6Xaf5FlLu4HtzJUHT4ViKv FM5L12WavcWm05bFSMeFSXewtsFK9RZE1T4IEpwA5sbHeaBQvuYIRFVorfnchoQEGJDh GR7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=21mhY1F6D/bVN4FBUSB5kLGwxQH8yFVmkExK3y72E74=; b=OYHxJE5k3jPcym6tbZYaCSu3mYiRkjl8FRaNJ+HmTCXFa4uQ3c1cEHt/V7CJmFz54S vsWbnI7pLnc9FMr+E1THuMfb4GkMVodhGYD7EmTD2pcuxnxUp+oBodWA+X1YeRxZuTC5 zfSy/bEpQGWuVxPXOjbdUHh1DXWYsPXQoEyRyw4/O1m46jXIaACx383aJWrVlI4opQzT yyMWrkCb7iRtfKSShHvOIw7Nh6XxeShP55Tkb8VY53SZ/HLbrEld/9A3KFTEgVziLeTA GQDlu3ygy4FsX6SauTlrnjkwmyvoJkCX18iMXmAW18QDmFS/Z847lxWEDQpc5h5N4mFY Mm1A== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net. [217.70.183.200]) by mx.google.com with ESMTPS id k34si19642635eda.241.2019.07.29.22.54.46 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 22:54:47 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.200; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id A580220003; Tue, 30 Jul 2019 05:54:42 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH v5 03/14] arm64: Consider stack randomization for mmap base only when necessary Date: Tue, 30 Jul 2019 01:51:02 -0400 Message-Id: <20190730055113.23635-4-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Do not offset mmap base address because of stack randomization if current task does not want randomization. Note that x86 already implements this behaviour. Signed-off-by: Alexandre Ghiti Acked-by: Catalin Marinas Acked-by: Kees Cook Reviewed-by: Christoph Hellwig Reviewed-by: Luis Chamberlain --- arch/arm64/mm/mmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index bb0140afed66..e4acaead67de 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -54,7 +54,11 @@ unsigned long arch_mmap_rnd(void) static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) { unsigned long gap = rlim_stack->rlim_cur; - unsigned long pad = (STACK_RND_MASK << PAGE_SHIFT) + stack_guard_gap; + unsigned long pad = stack_guard_gap; + + /* Account for stack randomization if necessary */ + if (current->flags & PF_RANDOMIZE) + pad += (STACK_RND_MASK << PAGE_SHIFT); /* Values close to RLIM_INFINITY can overflow. */ if (gap + pad > gap) From patchwork Tue Jul 30 05:51:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11064977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C2F813A4 for ; Tue, 30 Jul 2019 05:55:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C85128397 for ; Tue, 30 Jul 2019 05:55:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FF77284D2; Tue, 30 Jul 2019 05:55:56 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7328528397 for ; Tue, 30 Jul 2019 05:55:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5BB68E000A; Tue, 30 Jul 2019 01:55:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A0BD78E0003; Tue, 30 Jul 2019 01:55:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D29D8E000A; Tue, 30 Jul 2019 01:55:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 3DD878E0003 for ; Tue, 30 Jul 2019 01:55:53 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id b12so39627820eds.14 for ; Mon, 29 Jul 2019 22:55:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0msjGhHy7PXVB/gTGxgjo2uBrM3JZfSzGa6bY+9VkOw=; b=tchZqigU4dmg739jId+cHbYUs+2TWf8/sFZeng4KuNvynoZxSnvDOrwHtCOvqyoA6+ ve654BNV6qBxqvfkRFBMUoHdjvVzNnW2lm6wgojYib/gSfcS9ZAOx8WxYoInlcaEy9oB MkAzSRC1y0AxPE6Uxm5cbOguvSOWCbmiGiIgZ0R4/++wnDurQnkh0kWS09Ij4rPIvycF +3M9BAQFXcgiZQp+UU4u/cDHISm/RgB1rTilqMpIZ+4couuqgDhxIvMwVVCiO36fCWqA DIcZKa+Q5J9Q00mENU8WBTdw2j/a0OUIhXRcTQJ8WCzVUVZxfLm2i2OedqVfPk2fybQ6 PHFw== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAW0G1whc60Q4+z2sK6IuFXmtYWBWt1PsSwRd1HEpAfELPsaAXUy nE+IKpNf1Gw4o47L6oBfK60LAupwTwnol1hLNHJDf7aFWqs0plHSSMkLkab0T2uDw3r3YwsJo8J LgUoDFcM1S2APw9iMIS/M74HRkn50qI5ZWTl4irQokwQA9zUtoE/DnJJ7Xfx08W4= X-Received: by 2002:a17:906:69c4:: with SMTP id g4mr89672783ejs.9.1564466152784; Mon, 29 Jul 2019 22:55:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqySHahBnfzpcf6mPKvYW4RwmUE5dhhIuoz1uVdQpvebR4M2opllX4de8eyGcJanjaLdZO24 X-Received: by 2002:a17:906:69c4:: with SMTP id g4mr89672745ejs.9.1564466151789; Mon, 29 Jul 2019 22:55:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466151; cv=none; d=google.com; s=arc-20160816; b=rWIlhrHc8YkXrCmVaGXIT+AFwg6YNEJWFIFtv5ojvNmkAkqfZpZ8g+UURNYed/AicS 0NhCWTSFX/a6aRDM+TfZFJZAMBLLTSc6Mx7aylrUtaBygiQ2zS00nvgWtA2mXhZ92Wed X8qcvHWjjW8HS7y6YdA7HPKLMKwOd5bSrftHzpqiC6IkSNdfrRLvBw/tu2Hw1jhGCLXD cLgtqJ4uXr3dkgKv7h0yVx+wJaflIuony+JCtIFN5g7XXge8bjcdoX46ARsF70gs8qb2 nH2mHb06mxQ77kP3GlC9p3zu6hxqO+HcGQ7sEOIT3bK286JpL0Wxv83HNsj6qKD9EcAo F3Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=0msjGhHy7PXVB/gTGxgjo2uBrM3JZfSzGa6bY+9VkOw=; b=dNKq/NsVGvcEBmFyNhaFzRGldgn9jhYQVf1qgBu9i8utHczk7mOftVHJ6AJVjT0dsL A0cWGhZTM3fwkJeAK9K0tEs+Fu9PK4VA6zzhQ4l7WVx7Y6Mxv4K3W3f4SMF+Xyldo+yv LyRh9UA8iu0pckUEntkVRrEZqYOjyIPlwDSgNqoZ6sFyJL1pL9su2OFvaZc0WaFKyyx+ 3DPmp/h1V7w1TeCa8En3zSauGQzKAWuzLQcuuM/nSZPCjg/n6Sm0J3Bw7MjVdr8pU2xh h4GCk64Y79I/xECUXViB9VVU2T1KLDhsddL3rCpQ24/hgHwwkEVWts7ImwoU6OjY1z9j WDzA== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net. [217.70.183.200]) by mx.google.com with ESMTPS id qn18si16632572ejb.331.2019.07.29.22.55.51 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 22:55:51 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.200; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 2E51020006; Tue, 30 Jul 2019 05:55:47 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti , Christoph Hellwig Subject: [PATCH v5 04/14] arm64, mm: Move generic mmap layout functions to mm Date: Tue, 30 Jul 2019 01:51:03 -0400 Message-Id: <20190730055113.23635-5-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP arm64 handles top-down mmap layout in a way that can be easily reused by other architectures, so make it available in mm. It then introduces a new config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT that can be set by other architectures to benefit from those functions. Note that this new config depends on MMU being enabled, if selected without MMU support, a warning will be thrown. Suggested-by: Christoph Hellwig Signed-off-by: Alexandre Ghiti Acked-by: Catalin Marinas Acked-by: Kees Cook Reviewed-by: Christoph Hellwig Reviewed-by: Luis Chamberlain --- arch/Kconfig | 10 ++++ arch/arm64/Kconfig | 1 + arch/arm64/include/asm/processor.h | 2 - arch/arm64/mm/mmap.c | 76 ----------------------------- kernel/sysctl.c | 6 ++- mm/util.c | 78 +++++++++++++++++++++++++++++- 6 files changed, 92 insertions(+), 81 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index a7b57dd42c26..a0bb6fa4d381 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -696,6 +696,16 @@ config HAVE_ARCH_COMPAT_MMAP_BASES and vice-versa 32-bit applications to call 64-bit mmap(). Required for applications doing different bitness syscalls. +# This allows to use a set of generic functions to determine mmap base +# address by giving priority to top-down scheme only if the process +# is not in legacy mode (compat task, unlimited stack size or +# sysctl_legacy_va_layout). +# Architecture that selects this option can provide its own version of: +# - STACK_RND_MASK +config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT + bool + depends on MMU + config HAVE_COPY_THREAD_TLS bool help diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 3adcec05b1f6..14a194e63458 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -72,6 +72,7 @@ config ARM64 select ARCH_SUPPORTS_INT128 if GCC_VERSION >= 50000 || CC_IS_CLANG select ARCH_SUPPORTS_NUMA_BALANCING select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT + select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) select ARCH_HAS_UBSAN_SANITIZE_ALL diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index 844e2964b0f5..65e2de00913f 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -281,8 +281,6 @@ static inline void spin_lock_prefetch(const void *ptr) "nop") : : "p" (ptr)); } -#define HAVE_ARCH_PICK_MMAP_LAYOUT - #endif extern unsigned long __ro_after_init signal_minsigstksz; /* sigframe size */ diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c index e4acaead67de..3028bacbc4e9 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -20,82 +20,6 @@ #include -/* - * Leave enough space between the mmap area and the stack to honour ulimit in - * the face of randomisation. - */ -#define MIN_GAP (SZ_128M) -#define MAX_GAP (STACK_TOP/6*5) - -static int mmap_is_legacy(struct rlimit *rlim_stack) -{ - if (current->personality & ADDR_COMPAT_LAYOUT) - return 1; - - if (rlim_stack->rlim_cur == RLIM_INFINITY) - return 1; - - return sysctl_legacy_va_layout; -} - -unsigned long arch_mmap_rnd(void) -{ - unsigned long rnd; - -#ifdef CONFIG_COMPAT - if (is_compat_task()) - rnd = get_random_long() & ((1UL << mmap_rnd_compat_bits) - 1); - else -#endif - rnd = get_random_long() & ((1UL << mmap_rnd_bits) - 1); - return rnd << PAGE_SHIFT; -} - -static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) -{ - unsigned long gap = rlim_stack->rlim_cur; - unsigned long pad = stack_guard_gap; - - /* Account for stack randomization if necessary */ - if (current->flags & PF_RANDOMIZE) - pad += (STACK_RND_MASK << PAGE_SHIFT); - - /* Values close to RLIM_INFINITY can overflow. */ - if (gap + pad > gap) - gap += pad; - - if (gap < MIN_GAP) - gap = MIN_GAP; - else if (gap > MAX_GAP) - gap = MAX_GAP; - - return PAGE_ALIGN(STACK_TOP - gap - rnd); -} - -/* - * This function, called very early during the creation of a new process VM - * image, sets up which VM layout function to use: - */ -void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) -{ - unsigned long random_factor = 0UL; - - if (current->flags & PF_RANDOMIZE) - random_factor = arch_mmap_rnd(); - - /* - * Fall back to the standard layout if the personality bit is set, or - * if the expected stack growth is unlimited: - */ - if (mmap_is_legacy(rlim_stack)) { - mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; - mm->get_unmapped_area = arch_get_unmapped_area; - } else { - mm->mmap_base = mmap_base(random_factor, rlim_stack); - mm->get_unmapped_area = arch_get_unmapped_area_topdown; - } -} - /* * You really shouldn't be using read() or write() on /dev/mem. This might go * away in the future. diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 078950d9605b..00fcea236eba 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -264,7 +264,8 @@ extern struct ctl_table epoll_table[]; extern struct ctl_table firmware_config_table[]; #endif -#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT +#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ + defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) int sysctl_legacy_va_layout; #endif @@ -1573,7 +1574,8 @@ static struct ctl_table vm_table[] = { .proc_handler = proc_dointvec, .extra1 = SYSCTL_ZERO, }, -#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT +#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ + defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) { .procname = "legacy_va_layout", .data = &sysctl_legacy_va_layout, diff --git a/mm/util.c b/mm/util.c index 15a4fb0f5473..0781e5575cb3 100644 --- a/mm/util.c +++ b/mm/util.c @@ -17,7 +17,12 @@ #include #include #include +#include +#include #include +#include +#include +#include #include @@ -315,7 +320,78 @@ unsigned long randomize_stack_top(unsigned long stack_top) #endif } -#if defined(CONFIG_MMU) && !defined(HAVE_ARCH_PICK_MMAP_LAYOUT) +#ifdef CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT +#ifdef CONFIG_ARCH_HAS_ELF_RANDOMIZE +unsigned long arch_mmap_rnd(void) +{ + unsigned long rnd; + +#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS + if (is_compat_task()) + rnd = get_random_long() & ((1UL << mmap_rnd_compat_bits) - 1); + else +#endif /* CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS */ + rnd = get_random_long() & ((1UL << mmap_rnd_bits) - 1); + + return rnd << PAGE_SHIFT; +} +#endif /* CONFIG_ARCH_HAS_ELF_RANDOMIZE */ + +static int mmap_is_legacy(struct rlimit *rlim_stack) +{ + if (current->personality & ADDR_COMPAT_LAYOUT) + return 1; + + if (rlim_stack->rlim_cur == RLIM_INFINITY) + return 1; + + return sysctl_legacy_va_layout; +} + +/* + * Leave enough space between the mmap area and the stack to honour ulimit in + * the face of randomisation. + */ +#define MIN_GAP (SZ_128M) +#define MAX_GAP (STACK_TOP / 6 * 5) + +static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) +{ + unsigned long gap = rlim_stack->rlim_cur; + unsigned long pad = stack_guard_gap; + + /* Account for stack randomization if necessary */ + if (current->flags & PF_RANDOMIZE) + pad += (STACK_RND_MASK << PAGE_SHIFT); + + /* Values close to RLIM_INFINITY can overflow. */ + if (gap + pad > gap) + gap += pad; + + if (gap < MIN_GAP) + gap = MIN_GAP; + else if (gap > MAX_GAP) + gap = MAX_GAP; + + return PAGE_ALIGN(STACK_TOP - gap - rnd); +} + +void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) +{ + unsigned long random_factor = 0UL; + + if (current->flags & PF_RANDOMIZE) + random_factor = arch_mmap_rnd(); + + if (mmap_is_legacy(rlim_stack)) { + mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; + mm->get_unmapped_area = arch_get_unmapped_area; + } else { + mm->mmap_base = mmap_base(random_factor, rlim_stack); + mm->get_unmapped_area = arch_get_unmapped_area_topdown; + } +} +#elif defined(CONFIG_MMU) && !defined(HAVE_ARCH_PICK_MMAP_LAYOUT) void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) { mm->mmap_base = TASK_UNMAPPED_BASE; From patchwork Tue Jul 30 05:51:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11064985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8353713A4 for ; Tue, 30 Jul 2019 05:57:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72BE428704 for ; Tue, 30 Jul 2019 05:57:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64CDB28716; Tue, 30 Jul 2019 05:57:01 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7D8228704 for ; Tue, 30 Jul 2019 05:57:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 047878E0013; Tue, 30 Jul 2019 01:57:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F12738E0003; Tue, 30 Jul 2019 01:56:59 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB37D8E0013; Tue, 30 Jul 2019 01:56:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 8AA8B8E0003 for ; Tue, 30 Jul 2019 01:56:59 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id i9so39613559edr.13 for ; Mon, 29 Jul 2019 22:56:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=cBxJ1KxcGmfDIECI8Cra5LnZouD+2DUEmB1lShztgnM=; b=DEbh9anIjIBa3SM5QagnivogVJsbdz+/v4vrjooOCmjN2CPnBTBs4YxCtCRmiCQMjC rDJj7whKqHtSKdWBMB4EY3vvNugTSh7hql/f8U3mg22l+I5MuV36HvvhHFqm3rj8nKSw 3owwHOELewRijOIcXtOl+gp0EiGfRDW4LXCMJheWx6WYKmvA5lHQRFOfMPqZ3hScP/9y ZYeDFYRv6zJYw+Sm1NwI8zgWcIFe3/nzbyMWsrHNYhNIHrOG+4omEapMycJnD1SxSaEa Hy/zfLQsVazv6DQyCUddA3zHo0N2jT3+T3lOIIofV5KtCZbktWpgSUDHtHA35aJm4Kmm 04Yw== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.193 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAV3sb/WupfmcUtU7nzh67FyGKPmkCIaUh86m5u+srZT3C+lsDSS uOhFSIruZjztaPGGGwnJf5clPHZqA3ijxTBXtOJuwvC0G/Vux9DFea4KBDKSOWHDNAT5M4cs468 KsU2L0mtJLpsLD1S9FP5QBaCS1ASO+zRFv1/pmO5jkcRT8ZN0ivB/+Ppwml5o4SQ= X-Received: by 2002:a17:906:f198:: with SMTP id gs24mr86303456ejb.6.1564466219035; Mon, 29 Jul 2019 22:56:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8K9jMG0Yyt59DpVWg9X9O6Y12/0bPUwv/1veiu2UT+SCyiNGpOLFQ3g0UDZ6R31KoJYeR X-Received: by 2002:a17:906:f198:: with SMTP id gs24mr86303419ejb.6.1564466218152; Mon, 29 Jul 2019 22:56:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466218; cv=none; d=google.com; s=arc-20160816; b=aabw7XJ91rj0HB3lEq3Bh2rd+g4HmlRcv0XBUMIXZUVs4DSoFJgKCq51jqI6ZEig6L UHDjNU/yl+KtTpXkhf0yDR/Afn6mHXVPStP+ybvptL8M8mNl9ZrKj0spKOEMP39yweSV xcq/AYyZmEXrUWYlPg6JgXbAp89ynyAoVOClCYyunpX56Qbp00NwSRXuYZtXbxX4mUHV ZesEdpwkOOExiOfboMg053pgF2QpJSlwaVs/JyZIkAH9HpgtyU/u1Lq8Db55kUwgbW67 U/pXeNMvWGTw3rO8nzTU9W6FIKTFQ4VuJvQhwQdZhvexQoqRh6hydCZfrXyY/2JQaBxj ZdNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=cBxJ1KxcGmfDIECI8Cra5LnZouD+2DUEmB1lShztgnM=; b=exCZtUF10RoIceIfkc2BKkO4YM4eKRFNzYC7mq2wJvX7mUEnN+lvp/CyeEohEH+jEs HZvY07phKg8opz/mQkx4QAeZ/duO4yy6X/o/oNBkDeo4vr0vTJnnnyalanzPaj0Iaf3E AR4shjdvfj7mrf/QljN9AuOmKI6jqRJ1bMYOpEYYoNo/v+yboHZTpyUU9gcBgVZGo0Gv r5axdtBAdrlS4wS+VIVOOs1MD2nNQBcD2fDGfYQrKBEgTFaN7v7xWFxYzwsoL9PmUfyv Wgj1PoBCTMGRxfmp5+47+kWyWSXv95Oyu1HRU2fqR5fGm0u1/IMpq1ctw4Fk42rjRKGC LYww== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.193 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net. [217.70.183.193]) by mx.google.com with ESMTPS id j9si17327867edn.191.2019.07.29.22.56.57 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 22:56:58 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.193 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.193; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.193 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id ED0F7240009; Tue, 30 Jul 2019 05:56:51 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH v5 05/14] arm64, mm: Make randomization selected by generic topdown mmap layout Date: Tue, 30 Jul 2019 01:51:04 -0400 Message-Id: <20190730055113.23635-6-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This commits selects ARCH_HAS_ELF_RANDOMIZE when an arch uses the generic topdown mmap layout functions so that this security feature is on by default. Note that this commit also removes the possibility for arm64 to have elf randomization and no MMU: without MMU, the security added by randomization is worth nothing. Signed-off-by: Alexandre Ghiti Acked-by: Catalin Marinas Acked-by: Kees Cook Reviewed-by: Christoph Hellwig Reviewed-by: Luis Chamberlain --- arch/Kconfig | 1 + arch/arm64/Kconfig | 1 - arch/arm64/kernel/process.c | 8 -------- mm/util.c | 11 +++++++++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index a0bb6fa4d381..d4c1f0551dfe 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -705,6 +705,7 @@ config HAVE_ARCH_COMPAT_MMAP_BASES config ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT bool depends on MMU + select ARCH_HAS_ELF_RANDOMIZE config HAVE_COPY_THREAD_TLS bool diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 14a194e63458..399f595ef852 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -16,7 +16,6 @@ config ARM64 select ARCH_HAS_DMA_MMAP_PGPROT select ARCH_HAS_DMA_PREP_COHERENT select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI - select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_FAST_MULTIPLIER select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index f674f28df663..8ddc2471b054 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -548,14 +548,6 @@ unsigned long arch_align_stack(unsigned long sp) return sp & ~0xf; } -unsigned long arch_randomize_brk(struct mm_struct *mm) -{ - if (is_compat_task()) - return randomize_page(mm->brk, SZ_32M); - else - return randomize_page(mm->brk, SZ_1G); -} - /* * Called from setup_new_exec() after (COMPAT_)SET_PERSONALITY. */ diff --git a/mm/util.c b/mm/util.c index 0781e5575cb3..16f1e56e2996 100644 --- a/mm/util.c +++ b/mm/util.c @@ -321,7 +321,15 @@ unsigned long randomize_stack_top(unsigned long stack_top) } #ifdef CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT -#ifdef CONFIG_ARCH_HAS_ELF_RANDOMIZE +unsigned long arch_randomize_brk(struct mm_struct *mm) +{ + /* Is the current task 32bit ? */ + if (!IS_ENABLED(CONFIG_64BIT) || is_compat_task()) + return randomize_page(mm->brk, SZ_32M); + + return randomize_page(mm->brk, SZ_1G); +} + unsigned long arch_mmap_rnd(void) { unsigned long rnd; @@ -335,7 +343,6 @@ unsigned long arch_mmap_rnd(void) return rnd << PAGE_SHIFT; } -#endif /* CONFIG_ARCH_HAS_ELF_RANDOMIZE */ static int mmap_is_legacy(struct rlimit *rlim_stack) { From patchwork Tue Jul 30 05:51:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11065005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C2D813A0 for ; Tue, 30 Jul 2019 05:59:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67F8C28704 for ; Tue, 30 Jul 2019 05:59:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B86428716; Tue, 30 Jul 2019 05:59:11 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0230228704 for ; Tue, 30 Jul 2019 05:59:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 241518E0007; Tue, 30 Jul 2019 01:59:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1F2D38E0003; Tue, 30 Jul 2019 01:59:10 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BA758E0007; Tue, 30 Jul 2019 01:59:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id B24B48E0003 for ; Tue, 30 Jul 2019 01:59:09 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id a5so39623916edx.12 for ; Mon, 29 Jul 2019 22:59:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WYZFBi/mDjw2AHO/7J+UsrC2CAAthlR5mqmiph32kXg=; b=BGCfhbweHiJT01yGaec2i7T0VHrVVApnqQ7au3jU5hvr3B7tmQyZ+iXampfJBBxWF4 1Q+54KZ/xAPkqnGGOY27FTcEtfSMgwhOXXiqke9TqZ6UTcaYFNiUjpROiuZP8WvdUF+0 W8ey6eGIaXd11EEY9AxUs3Cd0n+9tkYV5xiSFgw0/4h0T2fznmxeErE2Lo+KCzVRFPFO loK/fBDgybM/WBTS6gtIgUrNSqb9kIxXV4xTjCQweSKcEsn/DGFW3xzrj9jvWFbjpPyA +1Y9JwW9TJoN0LyiZgbeEd+/HHor+OzVTn2KrHzZchzbWTRKgqemVJ18SjV8AcQ14vnp 7Fdw== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.193 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAVkgCrwfgc23DKVnJim2oSxcubI98U5krWhCTvTz+vowbIRcrzr w0TLgG3h5gDcSNNy260WiITqUgS0Kll6E7ycEiAti+sUUnLbxQI3Gy9e8s0LF65X7YJsmwYeLyb +sfNJMz8DQxG93/rl0StGdJpo/4h6twjalbteh2mDzfhBqTIt4WsJ0704UvnxGPQ= X-Received: by 2002:a17:906:bcd6:: with SMTP id lw22mr88739426ejb.68.1564466349306; Mon, 29 Jul 2019 22:59:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/BzKvIyetov07il2Kg1v6FLrQ8sh/qMqY0/NLKJ/VvhigsqW6JL4RMg4fJBZalCx6s8O/ X-Received: by 2002:a17:906:bcd6:: with SMTP id lw22mr88739384ejb.68.1564466348378; Mon, 29 Jul 2019 22:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466348; cv=none; d=google.com; s=arc-20160816; b=pA0zuqLD2rTpS/dkeeRtZXHO0Fw9QKuZ1XX+nt6LPXC3nVJ47UfmLYE8WIA75UUZ9B XT/pT22sa67GUAKTttVBSzjLtBL+9lVAvZzr6LFJSCeeNiPfNblKrgykgQvuxu+X+IGw lAcXRTdI+67+WYHKafxSIcQiBXDgdGUyUyHopdaUd+Xk16DlApfsO8w6tLBncm0dPJs4 Z7epOb63E+lyXzvmNxHWkkN0GBQUHd/x+XkmaYp2cFQFeIn0Bv5vp+mBTDa4pwFw3KkJ cCAP7LGd4ub5ZMpLtXJlt7oGPuQMG3ANb+B15k5yrbcj9l1c2DAvFJXXlrovL7wEg4qR eXpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=WYZFBi/mDjw2AHO/7J+UsrC2CAAthlR5mqmiph32kXg=; b=QMXH91/gIE7Rze4UqJUD/Y8RAZ7v8ta+CtOihusOXYgSaz4Eb4D7Cn2TOslbWUz66l dzqkesJnkCNt7VlCcN58Lu9FdBnspVcYDpRLyf/K9FqwHIBxHG0+7McPH6Zl2NkRwHSu MSpCblth1hLBVmuv64c5Vco+rak/cwWFQJz5WWFeoEPK/PrFYRJrA9MzPhsEfhAg8yWg RCNjWGCg6R8d1xtgRBAvWIuJk4O8QHcIt9D7uxnVAKyBhISYVI/yUUlrC5I80/GPmrGm 5PMX+5/Dkaq5VuKmT55yZHP2AVJUs6/pUuELRhqXQ7VMLCfFimsnYdz0P9G3qm2ADRnJ A0jw== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.193 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net. [217.70.183.193]) by mx.google.com with ESMTPS id d24si16507465ejt.166.2019.07.29.22.59.08 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 22:59:08 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.193 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.193; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.193 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id E90EC240007; Tue, 30 Jul 2019 05:59:02 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH v5 07/14] arm: Use STACK_TOP when computing mmap base address Date: Tue, 30 Jul 2019 01:51:06 -0400 Message-Id: <20190730055113.23635-8-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP mmap base address must be computed wrt stack top address, using TASK_SIZE is wrong since STACK_TOP and TASK_SIZE are not equivalent. Signed-off-by: Alexandre Ghiti Acked-by: Kees Cook Reviewed-by: Luis Chamberlain --- arch/arm/mm/mmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index bff3d00bda5b..0b94b674aa91 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c @@ -19,7 +19,7 @@ /* gap between mmap and stack */ #define MIN_GAP (128*1024*1024UL) -#define MAX_GAP ((TASK_SIZE)/6*5) +#define MAX_GAP ((STACK_TOP)/6*5) #define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT - 12)) static int mmap_is_legacy(struct rlimit *rlim_stack) @@ -51,7 +51,7 @@ static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) else if (gap > MAX_GAP) gap = MAX_GAP; - return PAGE_ALIGN(TASK_SIZE - gap - rnd); + return PAGE_ALIGN(STACK_TOP - gap - rnd); } /* From patchwork Tue Jul 30 05:51:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11065015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D037713A0 for ; Tue, 30 Jul 2019 06:00:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B661928714 for ; Tue, 30 Jul 2019 06:00:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAC372871A; Tue, 30 Jul 2019 06:00:16 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C71B28716 for ; Tue, 30 Jul 2019 06:00:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5753C8E0014; Tue, 30 Jul 2019 02:00:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 525788E0003; Tue, 30 Jul 2019 02:00:15 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 414AD8E0014; Tue, 30 Jul 2019 02:00:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id E8B348E0003 for ; Tue, 30 Jul 2019 02:00:14 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id m23so39595423edr.7 for ; Mon, 29 Jul 2019 23:00:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LQVvrRrr/swGRphV/257WvSOGOZvl4ebHt8qhO/ifFg=; b=fJ0cY9fORYYp5FAn7Y9rcOohj9wZQF3z1JKm+reufimb1fP/wvZmRaa/o0Z0pdNpEf E9dne/I3j1m9+8A9tTi/Yvk/jSjqqgVnfikFzA4UR1k81rY6p5FHAcEouHj42PWiRZhC 2onj9OX3v+uo+84tJEesK/LslX5cLJx6QcN+Ky9a5+m/UfRFsCpC5gvktyXA9QN9CISz 7Rvdnd7bnqwJc07EoVo4jJ76sJAms88GGDrHdn+zGb28IUwl/UHZ+QKeAtEK9exXORM6 7U2Qctmur6I+vGeiN/1NM4vXlGrTi+Rbohiu/8H30Lzl3G8yPL2WuXddTFRdNovT+l7R 7u7A== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAWmijecEKIo94nXyhPu+VKzNND6CBVyGKdkLkkNo+jE/ZvLdVjN nC+cDAjQprdr5Mq9yrxbkxyOTkmM2bfaNiB48HhG8KE+tVBvyE7PW7WnlHH+ZftAClZirh0pWpL wdY1Fwj5tQhFaDrICKKbTi+Rt8zdPy0x/PpxtVzOZUtFdsikVenDZPriwaSrRqWQ= X-Received: by 2002:aa7:c559:: with SMTP id s25mr1204168edr.117.1564466414510; Mon, 29 Jul 2019 23:00:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyRROlYMxex2kYvWOpKFvdVQuEOIkE+Ys4aWs3afgTRn3q0WSpJUc8ns2CunvrxNcSq9lnr X-Received: by 2002:aa7:c559:: with SMTP id s25mr1204044edr.117.1564466413144; Mon, 29 Jul 2019 23:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466413; cv=none; d=google.com; s=arc-20160816; b=zQjYagj5npcaWeu2cDdlk8wu888tfe5jRBYnlNAN7xW0OIXCTNB2CJzCioGu1rZqeL eJlfA/MeGHZz5EwFnCOLREhE5qiHQcjCvfeV7dvcV60n2OE0B0ebppzg1zxFWlWHGZao ir3Lz5yQKQ/fTg7qpZdHiwnve0XhpRa5HmIr/TCsu7h1BRBWXB7ADLKzyLOYOGOBbg2B e00EcsXxRQg5S1hBpxbLe3GyxyP9YHz0HOHtDBBrLG6m7FpX4p7Utq5XBNTvyRUC3wkE ZwEwx7OdAau9pXGg5xg356pkQL+VPPK+G5sMjI7HYw02SQ7E4T4E46yrOsyxSjTLHpJf QROA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=LQVvrRrr/swGRphV/257WvSOGOZvl4ebHt8qhO/ifFg=; b=TQ5xQ7597yPy7O3HonzPANjJLPTWpB3Ai+9yZLmpJqfvYr0UwNYZBM7n6OfgvpRkz/ Pg8kf2muMWEkDMUgZUlXLTeToDJ27Bd/cINqHRz4sO8H0SoP8Beqd0FtL7OwGLFv71B0 Vuh41gYLFAU7RaURX4ee2Am+85Z3envZALLr6LZVHrIFyUo5owyjnoriZxNtjnAURXpm Tx6+O0MPIPtmoLzyDSPwj0iJQBNw0DGw3w+8ML/DomPgDwyMrYAJsviNxko+Qykl8aKi ggegGmGXnrGv6GLVD0kuYK24ijunOZ+o61GYuiNA5PCRqYqLJQqrFwhXRqFzfABbPnps qEkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net. [217.70.183.201]) by mx.google.com with ESMTPS id x15si15988325ejv.41.2019.07.29.23.00.12 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 23:00:13 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.201; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 558AF1BF211; Tue, 30 Jul 2019 06:00:08 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH v5 08/14] arm: Use generic mmap top-down layout and brk randomization Date: Tue, 30 Jul 2019 01:51:07 -0400 Message-Id: <20190730055113.23635-9-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP arm uses a top-down mmap layout by default that exactly fits the generic functions, so get rid of arch specific code and use the generic version by selecting ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT. As ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT selects ARCH_HAS_ELF_RANDOMIZE, use the generic version of arch_randomize_brk since it also fits. Note that this commit also removes the possibility for arm to have elf randomization and no MMU: without MMU, the security added by randomization is worth nothing. Note that it is safe to remove STACK_RND_MASK since it matches the default value. Signed-off-by: Alexandre Ghiti Acked-by: Kees Cook Reviewed-by: Luis Chamberlain --- arch/arm/Kconfig | 2 +- arch/arm/include/asm/processor.h | 2 -- arch/arm/kernel/process.c | 5 --- arch/arm/mm/mmap.c | 62 -------------------------------- 4 files changed, 1 insertion(+), 70 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 33b00579beff..81b08b027e4e 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -7,7 +7,6 @@ config ARM select ARCH_HAS_BINFMT_FLAT select ARCH_HAS_DEBUG_VIRTUAL if MMU select ARCH_HAS_DEVMEM_IS_ALLOWED - select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_KEEPINITRD select ARCH_HAS_KCOV @@ -30,6 +29,7 @@ config ARM select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF + select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU select ARCH_WANT_IPC_PARSE_VERSION select BINFMT_FLAT_ARGVP_ENVP_ON_STACK select BUILDTIME_EXTABLE_SORT if MMU diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h index 20c2f42454b8..614bf829e454 100644 --- a/arch/arm/include/asm/processor.h +++ b/arch/arm/include/asm/processor.h @@ -140,8 +140,6 @@ static inline void prefetchw(const void *ptr) #endif #endif -#define HAVE_ARCH_PICK_MMAP_LAYOUT - #endif #endif /* __ASM_ARM_PROCESSOR_H */ diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c index f934a6739fc0..9485acc520a4 100644 --- a/arch/arm/kernel/process.c +++ b/arch/arm/kernel/process.c @@ -319,11 +319,6 @@ unsigned long get_wchan(struct task_struct *p) return 0; } -unsigned long arch_randomize_brk(struct mm_struct *mm) -{ - return randomize_page(mm->brk, 0x02000000); -} - #ifdef CONFIG_MMU #ifdef CONFIG_KUSER_HELPERS /* diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index 0b94b674aa91..b8d912ac9e61 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c @@ -17,43 +17,6 @@ ((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \ (((pgoff)<> (PAGE_SHIFT - 12)) - -static int mmap_is_legacy(struct rlimit *rlim_stack) -{ - if (current->personality & ADDR_COMPAT_LAYOUT) - return 1; - - if (rlim_stack->rlim_cur == RLIM_INFINITY) - return 1; - - return sysctl_legacy_va_layout; -} - -static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) -{ - unsigned long gap = rlim_stack->rlim_cur; - unsigned long pad = stack_guard_gap; - - /* Account for stack randomization if necessary */ - if (current->flags & PF_RANDOMIZE) - pad += (STACK_RND_MASK << PAGE_SHIFT); - - /* Values close to RLIM_INFINITY can overflow. */ - if (gap + pad > gap) - gap += pad; - - if (gap < MIN_GAP) - gap = MIN_GAP; - else if (gap > MAX_GAP) - gap = MAX_GAP; - - return PAGE_ALIGN(STACK_TOP - gap - rnd); -} - /* * We need to ensure that shared mappings are correctly aligned to * avoid aliasing issues with VIPT caches. We need to ensure that @@ -181,31 +144,6 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, return addr; } -unsigned long arch_mmap_rnd(void) -{ - unsigned long rnd; - - rnd = get_random_long() & ((1UL << mmap_rnd_bits) - 1); - - return rnd << PAGE_SHIFT; -} - -void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) -{ - unsigned long random_factor = 0UL; - - if (current->flags & PF_RANDOMIZE) - random_factor = arch_mmap_rnd(); - - if (mmap_is_legacy(rlim_stack)) { - mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; - mm->get_unmapped_area = arch_get_unmapped_area; - } else { - mm->mmap_base = mmap_base(random_factor, rlim_stack); - mm->get_unmapped_area = arch_get_unmapped_area_topdown; - } -} - /* * You really shouldn't be using read() or write() on /dev/mem. This * might go away in the future. From patchwork Tue Jul 30 05:51:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11065035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A5E2746 for ; Tue, 30 Jul 2019 06:02:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BED528704 for ; Tue, 30 Jul 2019 06:02:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F78D28716; Tue, 30 Jul 2019 06:02:25 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF0FB28704 for ; Tue, 30 Jul 2019 06:02:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D62A48E0015; Tue, 30 Jul 2019 02:02:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D12728E0003; Tue, 30 Jul 2019 02:02:23 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDAF28E0015; Tue, 30 Jul 2019 02:02:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id 735568E0003 for ; Tue, 30 Jul 2019 02:02:23 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id b12so39585991ede.23 for ; Mon, 29 Jul 2019 23:02:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=CozSP8ClhxqYRnTVyauC5EuB32xQZZhYjVFYo6YFdyo=; b=TwYyWJxDrqc/01Mpkq6pTB3wiVAqFLo71D6f7EAwgBiYVxw62+vM0QLjct2YNWWAih 4meA2sm8vpKwvwJvLhYDRUrGsF7HCN5lOun8ChwcTwguXh+tTyPbcMOd7su7PraCMvGI PbSAYX3QBrEeNb0uePLRkzzUCppMRwj86hl3d5PAePSMqTGYb0SeB2/dmdxm85i+0zib GnzEJdRWHPgQoT+68rX2Khx1ls1IsF3OJQLeaOiTYJnwoAl3c8N/XW08sCt2ku147ZRf 2gR5KRHplkJyakaV4CewDZa1C6mli1aQSAqFzyQa3ZJGe+EuESBh0g3rgIpDC/B6rlG0 8VRw== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAXKJIcxQOkdZV0iWikQZqMKoqLRjcWlgykxREd6Z8/F0UEWcZWD 6c5XKF8Z67fGvP0v6j6nZ5ajA6EJiMX2Xb3XA4b5CTANGWbsIS0V+hNRJW3186uu+ZTsQ1pmQbs tOOLQhjoeZOax9jPkQHyzvEnKDqs/NiEwrFo+77+T8mPIo8/bVbINYqIOXfan4Kg= X-Received: by 2002:a17:906:b211:: with SMTP id p17mr87462398ejz.11.1564466543047; Mon, 29 Jul 2019 23:02:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwVEW+5o53c3BLVdgf9ypjCSCVnd0/UnWcCWsDOL/0TOmCxXA9a1FCK3meTa8e8cRtEqDxm X-Received: by 2002:a17:906:b211:: with SMTP id p17mr87462325ejz.11.1564466541880; Mon, 29 Jul 2019 23:02:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466541; cv=none; d=google.com; s=arc-20160816; b=Rrwgh706Zrxr0Uhr5Oy6M9UncGsy4WHNfN08Gjl3nypkh578jgMQPuT+6fRaHQjzen 5KzXAmnJS5yqYdrDyDj60c7p6gFgnMUPKm7vlmdPCKpfQHpKFnamUEcplbg+3BY7KAah H/E4rpMu9BATiSVY4GWvTSsXbyoui3IZgBtZS4rZ2sqQTgoslI4ItIRHatMSDLUlbye8 VPQrHatDvlNiTwjbtDf5onGihr+nYhjgMIOVS+905pABO1ViexvB9DymyqOZbj8IcmoZ 8mZCPg6krENOWLR3gjaZ6H64o6amVcXnJOWMIqHbHI7SnCzSMn+Q9au3Lg+bs8MhpN54 /4jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=CozSP8ClhxqYRnTVyauC5EuB32xQZZhYjVFYo6YFdyo=; b=Lshu+1YzMnjVlD9n1EYGPHHw6RVuHNQUJEFIfQ4XeprYb3Q0TcveD9q63LM1Ng2yN9 IG9AkyCIGE4jqsJ9hvYS7qAAsAwCl2TGitPgXbHkVjIT6yAnDNOAQKBzaOLF8J4I53xJ IeVfTolQn8qjh7VPCCVLyU3uS+DWiqJAMcX7frViCphas8MM5AYn55e/Vl/m5cvgG92p YGOLq+logOSDgPQRAf5rHWeKc6QYUPV9FvQ0iHE4YmgKPB6dbYstGnUCpCqxU3ke8Oz0 J5phoJKduQqZL8FdZSc2r3p91W4Gv943KnukvAhBobit7fWKCud65+mtlRKQrW2vQ+li QV7g== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net. [217.70.183.201]) by mx.google.com with ESMTPS id z3si17199149edc.389.2019.07.29.23.02.21 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 23:02:21 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.201; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.201 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 925B41BF20E; Tue, 30 Jul 2019 06:02:17 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH v5 10/14] mips: Use STACK_TOP when computing mmap base address Date: Tue, 30 Jul 2019 01:51:09 -0400 Message-Id: <20190730055113.23635-11-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP mmap base address must be computed wrt stack top address, using TASK_SIZE is wrong since STACK_TOP and TASK_SIZE are not equivalent. Signed-off-by: Alexandre Ghiti Acked-by: Kees Cook Acked-by: Paul Burton Reviewed-by: Luis Chamberlain --- arch/mips/mm/mmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index f5c778113384..a7e84b2e71d7 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -22,7 +22,7 @@ EXPORT_SYMBOL(shm_align_mask); /* gap between mmap and stack */ #define MIN_GAP (128*1024*1024UL) -#define MAX_GAP ((TASK_SIZE)/6*5) +#define MAX_GAP ((STACK_TOP)/6*5) #define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT - 12)) static int mmap_is_legacy(struct rlimit *rlim_stack) @@ -54,7 +54,7 @@ static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) else if (gap > MAX_GAP) gap = MAX_GAP; - return PAGE_ALIGN(TASK_SIZE - gap - rnd); + return PAGE_ALIGN(STACK_TOP - gap - rnd); } #define COLOUR_ALIGN(addr, pgoff) \ From patchwork Tue Jul 30 05:51:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11065043 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4753D1399 for ; Tue, 30 Jul 2019 06:03:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3727B28704 for ; Tue, 30 Jul 2019 06:03:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B44228716; Tue, 30 Jul 2019 06:03:29 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC06228704 for ; Tue, 30 Jul 2019 06:03:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC0DE8E0016; Tue, 30 Jul 2019 02:03:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E71568E0003; Tue, 30 Jul 2019 02:03:27 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D399D8E0016; Tue, 30 Jul 2019 02:03:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 888778E0003 for ; Tue, 30 Jul 2019 02:03:27 -0400 (EDT) Received: by mail-ed1-f70.google.com with SMTP id b33so39619004edc.17 for ; Mon, 29 Jul 2019 23:03:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=PQ9i7jzea9mGKNH8KcMLWsVLtL6mR1QxNOrNNbBorkI=; b=GB5R0+cByM4MXNC5N3Ckpf/2RgnCyVTWkynUbX0yYJWUQmU/OsUtAiquNUTheSOFFy 6eKMx5+93Ar5JUb3/9gA0QSso9o7DTMtSlhCdM8GmO5a01Fz1sgzX36N0T9ASR37VqwW 6VLQFsOZY3Mck2iaEHyYm3dQNhaDDbO5THcAFos4gghsNowNpd/KASvQ/lGIMn7SxTA8 5HnGh17rUFoRLXo/0yVb8gPw5KtOtza5CTsuth2bZEZmrXI1NUX5fewYoMPk6xhs6G2Y dS6amMyo583Cb3HS+V++K9U50g0wp96vSqyUNPko0MI8EBeQ6V4a8bngD3oFGysmPPhE 1E3Q== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAVK2Y8uxEYwkknE1bgCopAoeW5CZfSNndSzhYb2HABmj2AcGtc3 T19AhC1E9D8MIAe2FwIuuTS0J0aXbEKGGXoaA5XUci+senEeU1lhZFFx0xvMjK7vqz8iWl7iSlJ M+8U2cm5Um1dniRukgGnjwK/r1HL+fNWP1k/npJvQ7Bj3zl1Vu7p5rNG7cUkHb5g= X-Received: by 2002:a17:906:499a:: with SMTP id p26mr24695845eju.308.1564466607149; Mon, 29 Jul 2019 23:03:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpF/32RijyaRi0dIwnYXE9qLtNwG8dJbZ6vbEuu0UbbKPIFsndmLRB08pS5huoFr14qQeE X-Received: by 2002:a17:906:499a:: with SMTP id p26mr24695806eju.308.1564466606416; Mon, 29 Jul 2019 23:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466606; cv=none; d=google.com; s=arc-20160816; b=iADCxsc5vstvf2uwvuVU+2Gzxb7/zt77WXITEQDQ80fLuvSbr5mCFRhlDrAv+iBezL XziBQqnoX9ItqKkhA2e/C5J9c/RhCkmdkEyiLdsbGwvXrHQb37jFjF0mluWnEmFXVpm4 JQpMuwmk3R9vaApvfpfZAk4qtr7S7r1ZmWFP1cyShQOl9iLLpquvcdeFei24FmDDrQP1 U6RVHtbKQk4WUXm4qU3UgHAr6CZucdbnsRLlaFw0TbMa8guX2wYod5SQm7819bY3ETxW bTUi6EGrOE5XSteSu1J8BgeffFluhM1u/MLUG/3PYIqGYez8IfsggXWtq5sNuQ8X0U7b fD1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=PQ9i7jzea9mGKNH8KcMLWsVLtL6mR1QxNOrNNbBorkI=; b=eodWfswH6TOu5BXdDp5tRb7Ipv3NYvaq4KSCzwuF8hx6FgmBvdDVZ1mDcWx8nzaNce eE4T0RinU/Sek4NUeZs3VFEddWbiLMMLz0pVPp50slVK4SgvfYi24mkU9brcV7oIfx46 CdzktzpCsbU0RkaADnk+Y50bUdXVOJTsTNOjZp+DPPbixBJTmYyDJ9NUcSBkaCJqX4G4 T+OGaUAolUIDCyBykWhVOKIrirMSp2A9rhSlbHqTqQzTC3czMj6LFppZY8rPqkup8L2C NnJb2pUTz4/Wqj3DjF0V1VbywEAFiG/Tm+b2cyfqz66WHT6baZpt8hNNpVEoLCaIm2z7 1KmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net. [217.70.183.200]) by mx.google.com with ESMTPS id q17si16760223eja.24.2019.07.29.23.03.26 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 23:03:26 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.200; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.200 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 0BBC320006; Tue, 30 Jul 2019 06:03:21 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH v5 11/14] mips: Adjust brk randomization offset to fit generic version Date: Tue, 30 Jul 2019 01:51:10 -0400 Message-Id: <20190730055113.23635-12-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This commit simply bumps up to 32MB and 1GB the random offset of brk, compared to 8MB and 256MB, for 32bit and 64bit respectively. Suggested-by: Kees Cook Signed-off-by: Alexandre Ghiti Acked-by: Paul Burton Reviewed-by: Kees Cook Reviewed-by: Luis Chamberlain --- arch/mips/mm/mmap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index a7e84b2e71d7..ff6ab87e9c56 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -16,6 +16,7 @@ #include #include #include +#include unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */ EXPORT_SYMBOL(shm_align_mask); @@ -189,11 +190,11 @@ static inline unsigned long brk_rnd(void) unsigned long rnd = get_random_long(); rnd = rnd << PAGE_SHIFT; - /* 8MB for 32bit, 256MB for 64bit */ + /* 32MB for 32bit, 1GB for 64bit */ if (TASK_IS_32BIT_ADDR) - rnd = rnd & 0x7ffffful; + rnd = rnd & (SZ_32M - 1); else - rnd = rnd & 0xffffffful; + rnd = rnd & (SZ_1G - 1); return rnd; } From patchwork Tue Jul 30 05:51:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11065055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D92071823 for ; Tue, 30 Jul 2019 06:04:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAB2A28704 for ; Tue, 30 Jul 2019 06:04:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE07C28716; Tue, 30 Jul 2019 06:04:34 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6961F28714 for ; Tue, 30 Jul 2019 06:04:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91AEE8E0018; Tue, 30 Jul 2019 02:04:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8CB0C8E0003; Tue, 30 Jul 2019 02:04:33 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 793AA8E0018; Tue, 30 Jul 2019 02:04:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 2D2A18E0003 for ; Tue, 30 Jul 2019 02:04:33 -0400 (EDT) Received: by mail-ed1-f70.google.com with SMTP id b12so39640388eds.14 for ; Mon, 29 Jul 2019 23:04:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=juJS37x5CM43D+6DWMHhdR9jUChuu/SEXc2RnrYUv1M=; b=oHNlbyq1gAzkw7JHoRfmzJuJ5RLcTcPd3gLl/ihJ5246HAwkncaEscD+foyj/L416X oHf/GOA550JrI1VRpvYPHKZtlOvlpwXJLvcdq0VGNPjNO5Qi8jJP1//ljnEtJav+jc8L 2dSjw39T2u+SnLPrLkA+gpp3xljKbNYD1azVTyIjFhy0lddKGII8IYRb0JQ45+v9hicP HlWfR1KUKXy2TSRJkhhaqpmf9oOdV1bpSx294bbyd7AFmC293K1wRNCy6bHcDGBudekv x3vAcGtc+5Mt9OSFAvr5xazbnVo/xMXfM3t0jhj6M2/8bmhb8vocAdA/wGBrgeZu/d+3 CkQA== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAWmgpH41T6NfZtRAM/O+IIKIElyLiqgKouO0ibnn/5raOi90rK2 JugrFgvD9Y7RnhR5aOlngGQd7NAT5940ZBW5r6AyF4tI8dLlEeph4KtWBL7yioiVcWXKNEC9bil 02ruMxLy0b4D+xujz9phIIN/iDc/OVBI7R9ggAcQEZE+TgWGgScqGTZa1YLgI3Mc= X-Received: by 2002:a17:906:3f87:: with SMTP id b7mr86029243ejj.164.1564466672769; Mon, 29 Jul 2019 23:04:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqykgwUdWoOkMMckGUufP50sRByCnf38dgCxOM1AI5H6tK/36MvMDX1zvTs+mh8U519xN7hk X-Received: by 2002:a17:906:3f87:: with SMTP id b7mr86029188ejj.164.1564466671974; Mon, 29 Jul 2019 23:04:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466671; cv=none; d=google.com; s=arc-20160816; b=IwLtFFJvPalaFOrl+rbqnKXEGfWt0OtGfOQEq/SgAO6TARtOw5Jj1ndnODy5zJ0tWe mfcxeHf+Y5S9jYObo6oMMK6hE8TnWyRwG5tlb+DqTsjYFDCjnbF/54W+iWEmwakq6E/V x/pUc5nBZEY3mVFnyOk9N+yb9XQE4zdGrxKuhyrT+S54wXeEMJ6n9VHu0GbiyrtmrHla ZAIJ5BEfiMpsTw1hpAtQHlH4OVzro9MtIKJhAokfoMFmsbCcSBk71dLpVs9zAYL2Sq9h fePuN3R704KRVJ/AxwQlFyQq40eW534MR6YPCMUS1TecW4GW2OJHIU6WyMbHxLw8UvzX 4hQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=juJS37x5CM43D+6DWMHhdR9jUChuu/SEXc2RnrYUv1M=; b=nfmhMKrgJAi+FsFA+vWuFyYijP/IULmnk4a3+CcLtcXoYx5huppjjmfCVAL/AbjTwG zanGaUu2tcFfWmiZrixQ9TQdpSFoDLLHAHQFnVxzshQNLEBAacs01NWOOiT/XBWuYW4N lg5zjRgrBWRFvksF3wyVusEkz9QdjTnZ/x2+myBEjye5+5AGh4I8C8qKBijjxeI+1ybe ZPhT7oSO/MN2JqEqPSQn1o77qv3y22PAG0EI5M1PoKnCPpQqAcCGp8CWxsYju+Waj5sg 3jWAnd+ma2JT8fci2idGHCLMtO+4MI6R+45kmNVljyWNfPJPf/yrWve26z3CEKcZuF0C iTsg== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net. [217.70.183.196]) by mx.google.com with ESMTPS id m17si15753741ejz.352.2019.07.29.23.04.31 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 23:04:31 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.196; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 94A64E0005; Tue, 30 Jul 2019 06:04:26 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH v5 12/14] mips: Replace arch specific way to determine 32bit task with generic version Date: Tue, 30 Jul 2019 01:51:11 -0400 Message-Id: <20190730055113.23635-13-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Mips uses TASK_IS_32BIT_ADDR to determine if a task is 32bit, but this define is mips specific and other arches do not have it: instead, use !IS_ENABLED(CONFIG_64BIT) || is_compat_task() condition. Signed-off-by: Alexandre Ghiti Acked-by: Paul Burton Reviewed-by: Kees Cook Reviewed-by: Luis Chamberlain --- arch/mips/mm/mmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index ff6ab87e9c56..d5106c26ac6a 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -17,6 +17,7 @@ #include #include #include +#include unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */ EXPORT_SYMBOL(shm_align_mask); @@ -191,7 +192,7 @@ static inline unsigned long brk_rnd(void) rnd = rnd << PAGE_SHIFT; /* 32MB for 32bit, 1GB for 64bit */ - if (TASK_IS_32BIT_ADDR) + if (!IS_ENABLED(CONFIG_64BIT) || is_compat_task()) rnd = rnd & (SZ_32M - 1); else rnd = rnd & (SZ_1G - 1); From patchwork Tue Jul 30 05:51:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11065065 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 118471823 for ; Tue, 30 Jul 2019 06:05:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01FCF28517 for ; Tue, 30 Jul 2019 06:05:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8E232857E; Tue, 30 Jul 2019 06:05:39 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5951628565 for ; Tue, 30 Jul 2019 06:05:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 941AB8E0019; Tue, 30 Jul 2019 02:05:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8CACD8E0003; Tue, 30 Jul 2019 02:05:38 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76BD08E0019; Tue, 30 Jul 2019 02:05:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 241548E0003 for ; Tue, 30 Jul 2019 02:05:38 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id r21so39652006edc.6 for ; Mon, 29 Jul 2019 23:05:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=B3VegeOhL+k8hWxAR+QQjfphQk03GqtZuzVPPfLXv/o=; b=UOTPHiallnHIRVoASurhIgrGvfsGnjs3jMh//4DVOWyt2wwhdw6lJFG5l0dkfVtd6Z r+iiR9lMXdAjA4Qm/V8UElyiFMfLBUA1uisMmSpQGcH+pffnb2u8Le4w7tLwu/j9iYrY JZ7jrRZBRw6f/AR/NIKztcO2wDjJWOWvEbnzwGQ1jOY+Y6ZKqTnPOizbic1wFWvyZo53 Uk+7oj0xMnP0qkFRE2eNzn9m1YutX3mqzKtJB5vkc+4Nn8la0vFJrGhQ/gGGW+nmUEay 6goLLXXrJtabxm3QTiskew+vVCsQacnJu9zE0OjAJXDMpGLuFLoK/jYCzvQJQKw6+OTW 3hOA== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAXZrTJXMg4tzZ8FSmOrj2CoOOwg7IJOlqANiao0UoAaJVvV1Zg/ LwmIYJFGx5TIIdJ2OAqmqGwmILYVkmx8i5ZzK0tZYTQBKT5CcMyRcg9NlqTnC0j64c1T3rVXHB+ Bp3IdAJ5sNS9aGjqERmgw3rValdVit1Nup64y0YRSRzjZ6grkJXaxSEjH24hqSjw= X-Received: by 2002:a05:6402:145a:: with SMTP id d26mr99488742edx.10.1564466737704; Mon, 29 Jul 2019 23:05:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUB387WOrYE+XLWvqRM+rqCiemi/z5BU8vngGQWexrvsXj0Ee2GboIvzFcEi7GSHx3V3Vf X-Received: by 2002:a05:6402:145a:: with SMTP id d26mr99488673edx.10.1564466736461; Mon, 29 Jul 2019 23:05:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466736; cv=none; d=google.com; s=arc-20160816; b=c7De30y8rMPgi/FCM9IXqwDHjQ6XwWMRULpnE7cZnaqE4a4osFjFdOkpFIZ25RTOLk x0qn+Fm6FWwcPZwm98Pmc0Wyg8dyqmOn9KdD+Y9fizi7yxQMEf2mI3GqXwqNSJnaQurJ iJfCQblr8B4kWNJ+vCnlIIeobc1cG+UW3JCtBO4qup66vzSQxbsPmTY+Z2AAfU1BxxXZ LliH/qF+o0ijKMrPAR1RXwW7Aefc+x4kF/RgNYQNI4mQ6Ru7ib16NUE5N6wgF/0gISbO kqr+m45DLaR34R8gfXP/OExH1+XGEkVDwpJbYQ7wT8SAS4D6dA+DhYtWpgwWB41jjjcE bGJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=B3VegeOhL+k8hWxAR+QQjfphQk03GqtZuzVPPfLXv/o=; b=mAN/bB2ynHHiYlJ/TukqZacD7iMHVevLqcRChx+JzJlaLSpnufAqSc+2Ps+ds3FDKt GrTMW/g6g9O2qicBP2rLQJEM9E6dT8laMReVhgONwCv6SX74IMdDNxHQJwyxpivs0qZw N/ym5pw7B9i30P8eRvxuBpxIEUQeY8hhcqQX2Plzg89KOWXqToqJnwnACCNMdVOBh+ta fCpbx5L+7egqFp2S7WqUXN3uOJWRoh78RY/Uf8eufPeGs3XvSNmZHwIESZuJ8TwpAdQc +UT2cWsElDD/tp/e5dMCEk9if/8vVb6uc3b/f3Nqzu+ouyG/s+LdjF/KaNNaJ4Fcv1EY oQNg== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net. [217.70.183.196]) by mx.google.com with ESMTPS id 47si20219725edu.294.2019.07.29.23.05.36 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 23:05:36 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.196; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 148D9E0005; Tue, 30 Jul 2019 06:05:31 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH v5 13/14] mips: Use generic mmap top-down layout and brk randomization Date: Tue, 30 Jul 2019 01:51:12 -0400 Message-Id: <20190730055113.23635-14-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP mips uses a top-down layout by default that exactly fits the generic functions, so get rid of arch specific code and use the generic version by selecting ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT. As ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT selects ARCH_HAS_ELF_RANDOMIZE, use the generic version of arch_randomize_brk since it also fits. Note that this commit also removes the possibility for mips to have elf randomization and no MMU: without MMU, the security added by randomization is worth nothing. Signed-off-by: Alexandre Ghiti Acked-by: Paul Burton Reviewed-by: Kees Cook Reviewed-by: Luis Chamberlain --- arch/mips/Kconfig | 2 +- arch/mips/include/asm/processor.h | 5 -- arch/mips/mm/mmap.c | 96 ------------------------------- 3 files changed, 1 insertion(+), 102 deletions(-) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index d50fafd7bf3a..4e85d7d2cf1a 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -5,7 +5,6 @@ config MIPS select ARCH_32BIT_OFF_T if !64BIT select ARCH_BINFMT_ELF_STATE if MIPS_FP_SUPPORT select ARCH_CLOCKSOURCE_DATA - select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_SUPPORTS_UPROBES @@ -13,6 +12,7 @@ config MIPS select ARCH_USE_CMPXCHG_LOCKREF if 64BIT select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS + select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_EXTABLE_SORT select CLONE_BACKWARDS diff --git a/arch/mips/include/asm/processor.h b/arch/mips/include/asm/processor.h index aca909bd7841..fba18d4a9190 100644 --- a/arch/mips/include/asm/processor.h +++ b/arch/mips/include/asm/processor.h @@ -29,11 +29,6 @@ extern unsigned int vced_count, vcei_count; -/* - * MIPS does have an arch_pick_mmap_layout() - */ -#define HAVE_ARCH_PICK_MMAP_LAYOUT 1 - #ifdef CONFIG_32BIT #ifdef CONFIG_KVM_GUEST /* User space process size is limited to 1GB in KVM Guest Mode */ diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index d5106c26ac6a..00fe90c6db3e 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -16,49 +16,10 @@ #include #include #include -#include -#include unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */ EXPORT_SYMBOL(shm_align_mask); -/* gap between mmap and stack */ -#define MIN_GAP (128*1024*1024UL) -#define MAX_GAP ((STACK_TOP)/6*5) -#define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT - 12)) - -static int mmap_is_legacy(struct rlimit *rlim_stack) -{ - if (current->personality & ADDR_COMPAT_LAYOUT) - return 1; - - if (rlim_stack->rlim_cur == RLIM_INFINITY) - return 1; - - return sysctl_legacy_va_layout; -} - -static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) -{ - unsigned long gap = rlim_stack->rlim_cur; - unsigned long pad = stack_guard_gap; - - /* Account for stack randomization if necessary */ - if (current->flags & PF_RANDOMIZE) - pad += (STACK_RND_MASK << PAGE_SHIFT); - - /* Values close to RLIM_INFINITY can overflow. */ - if (gap + pad > gap) - gap += pad; - - if (gap < MIN_GAP) - gap = MIN_GAP; - else if (gap > MAX_GAP) - gap = MAX_GAP; - - return PAGE_ALIGN(STACK_TOP - gap - rnd); -} - #define COLOUR_ALIGN(addr, pgoff) \ ((((addr) + shm_align_mask) & ~shm_align_mask) + \ (((pgoff) << PAGE_SHIFT) & shm_align_mask)) @@ -156,63 +117,6 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, addr0, len, pgoff, flags, DOWN); } -unsigned long arch_mmap_rnd(void) -{ - unsigned long rnd; - -#ifdef CONFIG_COMPAT - if (TASK_IS_32BIT_ADDR) - rnd = get_random_long() & ((1UL << mmap_rnd_compat_bits) - 1); - else -#endif /* CONFIG_COMPAT */ - rnd = get_random_long() & ((1UL << mmap_rnd_bits) - 1); - - return rnd << PAGE_SHIFT; -} - -void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) -{ - unsigned long random_factor = 0UL; - - if (current->flags & PF_RANDOMIZE) - random_factor = arch_mmap_rnd(); - - if (mmap_is_legacy(rlim_stack)) { - mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; - mm->get_unmapped_area = arch_get_unmapped_area; - } else { - mm->mmap_base = mmap_base(random_factor, rlim_stack); - mm->get_unmapped_area = arch_get_unmapped_area_topdown; - } -} - -static inline unsigned long brk_rnd(void) -{ - unsigned long rnd = get_random_long(); - - rnd = rnd << PAGE_SHIFT; - /* 32MB for 32bit, 1GB for 64bit */ - if (!IS_ENABLED(CONFIG_64BIT) || is_compat_task()) - rnd = rnd & (SZ_32M - 1); - else - rnd = rnd & (SZ_1G - 1); - - return rnd; -} - -unsigned long arch_randomize_brk(struct mm_struct *mm) -{ - unsigned long base = mm->brk; - unsigned long ret; - - ret = PAGE_ALIGN(base + brk_rnd()); - - if (ret < mm->brk) - return mm->brk; - - return ret; -} - bool __virt_addr_valid(const volatile void *kaddr) { unsigned long vaddr = (unsigned long)kaddr; From patchwork Tue Jul 30 05:51:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11065075 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E3DE1823 for ; Tue, 30 Jul 2019 06:06:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C8A428714 for ; Tue, 30 Jul 2019 06:06:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E3D828725; Tue, 30 Jul 2019 06:06:48 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA77328623 for ; Tue, 30 Jul 2019 06:06:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1036F8E001A; Tue, 30 Jul 2019 02:06:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 08CD88E0003; Tue, 30 Jul 2019 02:06:43 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBECC8E001A; Tue, 30 Jul 2019 02:06:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 9A4AA8E0003 for ; Tue, 30 Jul 2019 02:06:42 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id o13so39653743edt.4 for ; Mon, 29 Jul 2019 23:06:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=9RuQF310S86wrHSQrr0Pr/NRSfRDai7GSr6TTvA6MPE=; b=X2aQXjL/pW0Rp4AxLIE1lfuf3jJmblhxT0MIiJM0C/hjOaR/auC4UL9RNQeHbW+kjP C6XfgptBAkn1tQ+GtqAR/oJkwxhrqW/k3ychxX2jclmh6tUkJucMcLe1ve9PxOznfwS/ RwEpeMpsOWwgWLUtR2d8oJd5SKnnBcl+/TdCJ6aL/gKmHGKYV+P998jJzm5QTaDyc9Fv C0CXi70uOVQ98hHYjYLZWTF7xVmA8p+H+v6FCaIMNFZE1LDSXGSyChfykhjKGs2OYd9e 1Lifa0rnmvOnFs9oB77M337UkNMuz09KyWewUNFNEBACH9FHL/ivsFGTHMhDoGfdDCHv QnLg== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAUKrMRA21C8QUzj0lEmYC8oH+l+Ht0ViqngxUNkGPh/orqw0HXt 6wTu/EttIrBKl35U+s0MfCOSDBfP4Z+ZX/y1ZsJNeY6Cado4bk9aCfyYUdCTRUxfpnc95Ybg1uZ h22BXt73tdrILP3m5s7OidOsrmYuFfupYOIjnDzuNpv49Nv9VaiQsoFAr01jJNOA= X-Received: by 2002:aa7:d6d3:: with SMTP id x19mr99181007edr.119.1564466802197; Mon, 29 Jul 2019 23:06:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvpjs4arJj1/zeoOrmbAT0Iv2ZP9u0zUOTmRO/EAToz1EFrc9Tqax0yiAmgP47voJANjs8 X-Received: by 2002:aa7:d6d3:: with SMTP id x19mr99180943edr.119.1564466800978; Mon, 29 Jul 2019 23:06:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564466800; cv=none; d=google.com; s=arc-20160816; b=pMvhyejkZrhVun7pqus9rF0FbQW7A3elVCC8amwqJoMdqMlsVp68SXu4ax4GvIhn07 HYuTotJzu2WzdQFJOD8Axe2JOUde2AmKiG2VB92kACCquJxGXgVitMlHSKC97TQT01Iu EH+gr1vBvFBN2tSdtDRay8nmKnoMbb+e2fH7OliQEzni5tP8+FFic2ZOjVLGJC9KXrWs bTva+ccxKECwXo8pUdP0xDL0Q92tChGu17AoAj4M22VvpF7/FD+PmsDBx9rOn5UZGeoJ sVww+CsRLBgle634fubsP6789ZSyvsWz8zvDjWUezqgQogi7r/5w9thbfSyyPVmsPHpX STJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=9RuQF310S86wrHSQrr0Pr/NRSfRDai7GSr6TTvA6MPE=; b=cxFClOcZ0m/awK2fj64P6ful8mL6EMvn2cnAdp0ld/m7sWgmrIpk5MHtY8EVVpSzfw S8YXPbeIexffSfTcVUek1RrVkIj7mDRQByd6UfFQ7e8FJCV4F5w/Fr4mxCteD/lWEOBa M3oZhoLFfgS8h9Jwfa1MwTyNmaF5XHNtyr6fgRP8y4Iv21iT6WQjsX2NbJZpAKnNTZ4E hjLL2Uj+HjBbFOAyBLPUrqkSIZVWm+UJmO4tPTox6+Y3DS18pFfy+yVWLUWNEAl9z4TR siz+KDfmy3qPFgrIbjBgtE2HVZc6FyXTg4bbsw177xtRLae/27vK8Cqv04H8QbUoKpdc Pnsg== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net. [217.70.183.196]) by mx.google.com with ESMTPS id p50si6565736eda.338.2019.07.29.23.06.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2019 23:06:40 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.196; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.196 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Originating-IP: 79.86.19.127 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 9A460E0009; Tue, 30 Jul 2019 06:06:36 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Luis Chamberlain , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Kees Cook , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti Subject: [PATCH v5 14/14] riscv: Make mmap allocation top-down by default Date: Tue, 30 Jul 2019 01:51:13 -0400 Message-Id: <20190730055113.23635-15-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190730055113.23635-1-alex@ghiti.fr> References: <20190730055113.23635-1-alex@ghiti.fr> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In order to avoid wasting user address space by using bottom-up mmap allocation scheme, prefer top-down scheme when possible. Before: root@qemuriscv64:~# cat /proc/self/maps 00010000-00016000 r-xp 00000000 fe:00 6389 /bin/cat.coreutils 00016000-00017000 r--p 00005000 fe:00 6389 /bin/cat.coreutils 00017000-00018000 rw-p 00006000 fe:00 6389 /bin/cat.coreutils 00018000-00039000 rw-p 00000000 00:00 0 [heap] 1555556000-155556d000 r-xp 00000000 fe:00 7193 /lib/ld-2.28.so 155556d000-155556e000 r--p 00016000 fe:00 7193 /lib/ld-2.28.so 155556e000-155556f000 rw-p 00017000 fe:00 7193 /lib/ld-2.28.so 155556f000-1555570000 rw-p 00000000 00:00 0 1555570000-1555572000 r-xp 00000000 00:00 0 [vdso] 1555574000-1555576000 rw-p 00000000 00:00 0 1555576000-1555674000 r-xp 00000000 fe:00 7187 /lib/libc-2.28.so 1555674000-1555678000 r--p 000fd000 fe:00 7187 /lib/libc-2.28.so 1555678000-155567a000 rw-p 00101000 fe:00 7187 /lib/libc-2.28.so 155567a000-15556a0000 rw-p 00000000 00:00 0 3fffb90000-3fffbb1000 rw-p 00000000 00:00 0 [stack] After: root@qemuriscv64:~# cat /proc/self/maps 00010000-00016000 r-xp 00000000 fe:00 6389 /bin/cat.coreutils 00016000-00017000 r--p 00005000 fe:00 6389 /bin/cat.coreutils 00017000-00018000 rw-p 00006000 fe:00 6389 /bin/cat.coreutils 2de81000-2dea2000 rw-p 00000000 00:00 0 [heap] 3ff7eb6000-3ff7ed8000 rw-p 00000000 00:00 0 3ff7ed8000-3ff7fd6000 r-xp 00000000 fe:00 7187 /lib/libc-2.28.so 3ff7fd6000-3ff7fda000 r--p 000fd000 fe:00 7187 /lib/libc-2.28.so 3ff7fda000-3ff7fdc000 rw-p 00101000 fe:00 7187 /lib/libc-2.28.so 3ff7fdc000-3ff7fe2000 rw-p 00000000 00:00 0 3ff7fe4000-3ff7fe6000 r-xp 00000000 00:00 0 [vdso] 3ff7fe6000-3ff7ffd000 r-xp 00000000 fe:00 7193 /lib/ld-2.28.so 3ff7ffd000-3ff7ffe000 r--p 00016000 fe:00 7193 /lib/ld-2.28.so 3ff7ffe000-3ff7fff000 rw-p 00017000 fe:00 7193 /lib/ld-2.28.so 3ff7fff000-3ff8000000 rw-p 00000000 00:00 0 3fff888000-3fff8a9000 rw-p 00000000 00:00 0 [stack] Signed-off-by: Alexandre Ghiti Reviewed-by: Christoph Hellwig Reviewed-by: Kees Cook Reviewed-by: Luis Chamberlain Acked-by: Paul Walmsley # for arch/riscv --- arch/riscv/Kconfig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 8ef64fe2c2b3..8d0d8af1a744 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -54,6 +54,19 @@ config RISCV select EDAC_SUPPORT select ARCH_HAS_GIGANTIC_PAGE select ARCH_WANT_HUGE_PMD_SHARE if 64BIT + select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU + select HAVE_ARCH_MMAP_RND_BITS + +config ARCH_MMAP_RND_BITS_MIN + default 18 if 64BIT + default 8 + +# max bits determined by the following formula: +# VA_BITS - PAGE_SHIFT - 3 +config ARCH_MMAP_RND_BITS_MAX + default 33 if RISCV_VM_SV48 + default 24 if RISCV_VM_SV39 + default 17 if RISCV_VM_SV32 config MMU def_bool y