From patchwork Wed Jul 24 05:58:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11055981 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 E05961398 for ; Wed, 24 Jul 2019 06:00:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1F1B2864E for ; Wed, 24 Jul 2019 06:00:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C53C12873F; Wed, 24 Jul 2019 06:00:13 +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 4E6042864E for ; Wed, 24 Jul 2019 06:00:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19DBE6B0005; Wed, 24 Jul 2019 02:00:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 14F456B0006; Wed, 24 Jul 2019 02:00:12 -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 0173D8E0002; Wed, 24 Jul 2019 02:00:11 -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 A86766B0005 for ; Wed, 24 Jul 2019 02:00:11 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id z20so29569088edr.15 for ; Tue, 23 Jul 2019 23:00:11 -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=gvN/fSOr7Hy5zoK13x0Kq5Khp3Q9djXH0o1Y6qWZBJs=; b=qxgPLOPqPV45o1yFafhxytkQCgiGW97E0O1/OK8iL4QH/jdxfBqB+XbRew3qmiF4He 2+n/TcvUEWWtr6G0LGWbSJHa7gw9K0tGqHo0cajgQ+Y+Br/tJft6b43g2N1LWveRGXqZ VbIk9mwbYPMfrQ9dI+lFAJvA9tdpXGQHL/n4+SL3CwCnBV4JTezt7Q9LGMj6YERej663 SStCq4mEeWilPrdc9tcmJFTOb4tmhCgC/f75Nuu8KFRYoi45oBxkiS1WqW/gQGoD2UPc u9t8ISy739sBd/mS6NxQ/Z9yYs24lHGOprf1Bt/Bou+87JNse+2yt+ZxVyJ74ZDkKhqx 15jQ== 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: APjAAAVee6UUZ/g/ui/Kw7U6Q78CO0Cw6aGn+b+ZJi1CkL7+rlmu+I4C Rt4UVy7Z2bmgmn8Eme8qgH72LzgLgnjcpycl0DtosIWw+S26MIefuRDiLfaKQeuK0rT8sfvyRD3 p3KQOHZJbWtD3PMWYw8r52dAf0pBFptkOg5OVLGq45WZ6mwEeWcr6F0SjyETcea4= X-Received: by 2002:a17:906:4b13:: with SMTP id y19mr60973338eju.145.1563948011246; Tue, 23 Jul 2019 23:00:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyj8CX0o779jC7RkZEgybG0dZqCTKyCwMfMADzJs+gAFtziCb9rWRN0K+NsS+eVx3s6vCT/ X-Received: by 2002:a17:906:4b13:: with SMTP id y19mr60973226eju.145.1563948009836; Tue, 23 Jul 2019 23:00:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948009; cv=none; d=google.com; s=arc-20160816; b=f9PUKzXTSnYO+2NBTlWiqs16aZojgU66vCTWtCx+GGQ972tmJeBRkTN0C9mF30Wb2v 8/IisnVxFsP/0bJhl6GOG2Vfjwo3QPHC+mxiSh+0wV5c9dAthTOQm0s8YDGPiig0wWBE EvowwXUwRpxyYTJ5NRFuu0Lzqw06PanykEF3vQU461fY7hQJ9wr01ABU10Sy6v7I1Y24 eAcxx7/Hh8DwSD8NtuflkfLoS2bXp3eaER2IpAbXnizVIzXCr0iItrcZMLuGJw59yaVU /VTQjBgKFtT2FBcxq9a/Zi+Vfu1K+WVbDL6hKCEkZ6cdeJwWU7Rm2hBbLvh/YkQd/GoT Qe0Q== 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=gvN/fSOr7Hy5zoK13x0Kq5Khp3Q9djXH0o1Y6qWZBJs=; b=gaVOrI7BtdUwi+O1lqseuXabPHWV7t+bs3FwywjomxqS1rlw1PU5ofh9uor8rJbuU8 zI6z1inmbHH2A4gSsy90r7FK7wJOOqRm1DlNGIc2OL35tg2mCOjcqpBNgr4UzpxWipTW HLWgDHSstBbdbByYMCqJP8ggljLp3UcfUyJRdkQ5TbujYxB+pyOYJLL90MW/vvE/2vBW XJL3v1Kr09Eoo/1P8+C4x+bDmU+YPT/Hf1sg2Fb/be34mBYDXACf8glT6jnEi3WVbIby z25CrCL9NJKg9ZIxG1HsNIPq2gUwHwzl2S6uvMp95UcOuvQxxNIgI72JDIxxAjdBa9mM mWYA== 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 a22si8020757eda.167.2019.07.23.23.00.09 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:00:09 -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 85D61240009; Wed, 24 Jul 2019 06:00:01 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 01/14] mm, fs: Move randomize_stack_top from fs to mm Date: Wed, 24 Jul 2019 01:58:37 -0400 Message-Id: <20190724055850.6232-2-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 Reviewed-by: Christoph Hellwig Acked-by: Kees Cook --- 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 Wed Jul 24 05:58:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11055989 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 4B15D13B1 for ; Wed, 24 Jul 2019 06:01:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C5662875F for ; Wed, 24 Jul 2019 06:01:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FBF42876C; Wed, 24 Jul 2019 06:01:18 +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 D27EA2875F for ; Wed, 24 Jul 2019 06:01:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C5306B0007; Wed, 24 Jul 2019 02:01:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1748B6B0008; Wed, 24 Jul 2019 02:01:17 -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 08C538E0002; Wed, 24 Jul 2019 02:01:17 -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 AF59A6B0007 for ; Wed, 24 Jul 2019 02:01:16 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id e9so18424756edv.18 for ; Tue, 23 Jul 2019 23:01:16 -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=aZSsJFYvbjj8QOQUi6BNWizJJ333ywVv4QtORhWQawg=; b=q8k9wnQeAy0eWA9lfhqBrMCUZY+kmQzsCBTdILAYYV/GosF9CyxL5MzwgRJPKVuB8c 62n8go3ccIo2rAgc0kCsKS9ujDB2p1bvT5MTXf0mZYwR22OWj9OM7nAOwp4nLEHbOArL 3lNbtHj2Efi83y6HGSji+piVSgcumP2G08p9E5/tvLC0dflfojZKQN++szTRJLwDJVKr ot4PeR7q3kBLn3UtthO04D2w7zZe7e4XIN/RoJsMPbqic3iwXU1zwWTAAWSu5XITb6Xp iVaPdh8zrPhqLYvFqtWOkvcXFr6ZjDIi+MD+gODURduXWs2wRql6L6sQsvV6qlA7XEsp HoGw== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.198 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAUB4ZoYwqf7RZHDyRos7rECgkVdK9OaPSLr5NjIXSRG8/JVIgpG FH7u4ExaMWgYakFni917/1iPEXW8alcVA6+CNUNLLiCSzK/9gSZ8ZM/mM0wNuNvrK9rHcaR/hb5 oKlFZMi7t/PqLBxRzEurmCINDiDGUvwUXR4t68gKQYPnA+aFZEzgZ7f7aPwnJ+vA= X-Received: by 2002:a17:906:30d9:: with SMTP id b25mr58876697ejb.55.1563948076062; Tue, 23 Jul 2019 23:01:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzAYuNVYJla+HC460CqwdCtKBU3JH+w6qiHvVJ7vKCuZWZ/zkMp/UdNY9usaIp68/x0K7JZ X-Received: by 2002:a17:906:30d9:: with SMTP id b25mr58876642ejb.55.1563948075070; Tue, 23 Jul 2019 23:01:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948075; cv=none; d=google.com; s=arc-20160816; b=jgtJ2IeBBuoPOLmUgdNcho7gkEpIJGNWljIEWXDnREKgT8CZRTn4A9oGByeGj2KcEm nuWK7eaDUn6guzkO4Cgo0lFnTiuJe5LLxIPAUDUbyp2bX3tYQbMBK7I6X8D+rgpfU9zW xyEb735Z+p5vkjSFb2kIah6mz6ya8rlf7Fv24InWsyODMDnita0jchVBAsOvzIIg6f6K 8sJJ85seT2YsbxjEozI36v3Y+7I+c36v0ZClPJSCZlY+p0R905lkN+/dein7UCg3wvaA B4yvH7dGHZm9b7oi5FzNG6TjhiJhVyP6kTvs/R4/ngvepNN/nLoBOH9vZnFSfbdebdJy 5vZg== 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=aZSsJFYvbjj8QOQUi6BNWizJJ333ywVv4QtORhWQawg=; b=gSJRVBEfNjn+tqpU6sYmE5c3n8583XA6Ox2V39eC6KaLoZwGfxUCxBqOLv3gfMyELf cpUMXbBOvMmbguYzomo3TRkj+fUlwZh3rQL6i11SIauSt/7slT1KDLm+wAtzPm5QbI1P wgWRnfxTza/NxYEi7JuAfdAYxI1ls/eXcqhusMcd6DtHFcIU4KMk2IRnN3Hz8gJGdZYm jnQEARijJMdQ6kAxrXgiKAT/763nBmdKb0c94EGXqYGbbY2nuS3vnne8BSQU5SV8+lVE YMND7iYbIDSVj5TtwQvdKrXb94I2c3ovxXfCryYkHq/+SmRqq+STBSRvenJdHlvRl26d m4Cg== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.198 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net. [217.70.183.198]) by mx.google.com with ESMTPS id nq5si7000999ejb.124.2019.07.23.23.01.14 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:01:15 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.198 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.198; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.198 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 relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 05075C0002; Wed, 24 Jul 2019 06:01:09 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 02/14] arm64: Make use of is_compat_task instead of hardcoding this test Date: Wed, 24 Jul 2019 01:58:38 -0400 Message-Id: <20190724055850.6232-3-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 --- 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 Wed Jul 24 05:58:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11055999 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 0995F13B1 for ; Wed, 24 Jul 2019 06:02:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF3B12875F for ; Wed, 24 Jul 2019 06:02:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2D6A2876C; Wed, 24 Jul 2019 06:02:22 +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 8A9E22875F for ; Wed, 24 Jul 2019 06:02:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C70E26B0003; Wed, 24 Jul 2019 02:02:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C21B96B0008; Wed, 24 Jul 2019 02:02:21 -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 AE9B16B000A; Wed, 24 Jul 2019 02:02:21 -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 601CF6B0003 for ; Wed, 24 Jul 2019 02:02:21 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id z20so29572712edr.15 for ; Tue, 23 Jul 2019 23:02:21 -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=KhEHOzJH1XekHaEjlNvFqkjJE/BSWfvZ32hlPcMINEc=; b=bU+Xml5K6lM7zX6advWyD5kAENmnWGKcnq+BOMMy7v3Kwp31aYszXIVqMxoh/JeaBF dkGsmOxxBAUcIzq3V0pGzDtGhxdVD+gA/Nq+KWKUQgsqJMK0cGFv/4F4eCeIh0lVv6R9 h8lMuPc6+T6ujJDs1ZGJY8j68bCBpTk1/egIn4mdWTr5aDf5fPxNnC2GjsIpwxKa6z8h Ogr/lUc1qA6sbGuA0kfD/zO7ebV1Nhvacni/aBxuvH01yKK6uU8z8xqKSK3Lc7OwTc/c /U87RRleFkCel76dMnO93UtUt3/15iU1nLXfagpGW8wRtaqCUZOdf9jA1b0t1Mp7GVfV yJUQ== 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: APjAAAW1sg530/AdIapPKQmLux/S2B1Jcq0bnkd0Gi6og0yxB3LY+wMO SJJFpKdL4qK3/zl6vYL2bLgatvfNrmgHf2wrv69Rl6A1CL9sDG5iCBPZ3ibQRE1n3IAJyOWkci8 L13vxzwvR5pY5mHb8/hbmwvoSHb0IBvEvJEmji90Iqf/d8zmHwe7AawJ/NOu5c0w= X-Received: by 2002:aa7:c509:: with SMTP id o9mr32810121edq.164.1563948140981; Tue, 23 Jul 2019 23:02:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqw5FxIBKpfGvG4d/UHLCSgRYxNgtZPUP8N0+wby71AqshY79OtFUUaHstBgsuj3hkxAvNpo X-Received: by 2002:aa7:c509:: with SMTP id o9mr32810068edq.164.1563948140121; Tue, 23 Jul 2019 23:02:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948140; cv=none; d=google.com; s=arc-20160816; b=tOmX2zeYOYh1DjGot/NrgSJnLU0Pgvdk8p+pwlUpPVggMo5q+Z6ag0MECJHMfGdARk EQqTLXhUk2jrMD3KB61RA/U+Er17tzDjWCc3W2fVVDKk7N8ke0yuWoma0/BZLTEdcfWr pJFCDvcDgwRj9aNLcJJRHQPKBHcmNyGeyrv2jFs1NWJpaH9w5yP0Pq99pPrtjlCkdYuA rVFqFaRqdOtCuIOkPnRjvoh4wXGBOk8XWYSKkSrInSrpkvF3YPECpe0/ostEBcmKRfxz wrrQC+iG+aOWtzAVW6DzCMfrZtB/mSjppkjTihhNK/MoDvM5ytambnHk4K/2IRFI2rny MXxw== 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=KhEHOzJH1XekHaEjlNvFqkjJE/BSWfvZ32hlPcMINEc=; b=fB/2Kb/oBjpIhJEM+NiUQ7g0iRhHOEorZVIG/qGmIzXkg+oMfNl0FPB3xJ4rkJU6d2 0uS9DPFL5XiGYYzIlWb9Yh00ykC232CsDv706UXFQuu9hKayH0mmnvyGolMwphAwd4RE SV9xCmI+NtqBP99OdTYBkdMdZvSEFQANeSyNlD3XS0099YxCEGjyRCtMbHHFbVHyEh3V 8zf7UkuPp4cRuDoZjnP0bkdZXCEQoIA8XGCHW/mffxtmVCthlXp85CbdQ6haWZiyOnPI isi7WFh2jWiH5YfZ8rn2Y6YREgewpcZi2F1x7D6nCxbkcl73HDzWIhqzdUx+8tXVn8bz BfZw== 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 b2si7713510ede.451.2019.07.23.23.02.19 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:02:20 -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 AF3E124000A; Wed, 24 Jul 2019 06:02:15 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 03/14] arm64: Consider stack randomization for mmap base only when necessary Date: Wed, 24 Jul 2019 01:58:39 -0400 Message-Id: <20190724055850.6232-4-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 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 --- 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 Wed Jul 24 05:58:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11056009 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 68B59912 for ; Wed, 24 Jul 2019 06:03:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5961D2875F for ; Wed, 24 Jul 2019 06:03:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C6A32876C; Wed, 24 Jul 2019 06:03:32 +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 073AA28768 for ; Wed, 24 Jul 2019 06:03:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08AEF6B0003; Wed, 24 Jul 2019 02:03:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 039956B0008; Wed, 24 Jul 2019 02:03:28 -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 E6CCB8E0002; Wed, 24 Jul 2019 02:03:28 -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 9794B6B0003 for ; Wed, 24 Jul 2019 02:03:28 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id c31so29573030ede.5 for ; Tue, 23 Jul 2019 23:03:28 -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=0PoVlhP/B7SmAW4NwkDAl9x9/d/JAFrQTHRVEkNR7AM=; b=jCDDopKK3wzwYaO8XrWBWcLYQLBcm4hAmlBbypEC7y5veM8HCa4p88e/YzI68HctNF Po4D022kPb479R5G9UwX5q2kTz2gUO5Y2WHyzhAeDeTWMKYs8KBXJFd2yGamX8zqh7e3 2GPkP6izpFShETyuqVwl1drytUgDjyPK0S2wjelpKukss9w1s10rWXd1+qJj6BBl/Npz oEzLXI0zuCAp3Ya3A3sPvzGdAkTAlR2DfDVxUVvZjJZcXwDBoqrzgqM7nr6rVdlo9/99 gXOFrDei4MbdfUY5cJI23H7T1kKOPrdZBGFsv+pdLnUKqBdgrC54/VIZ/m7nw4XEcbzz JlpA== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.199 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAVNUT3w/0glzRmit6S3YwlcQGcvvEZzoA+37qAvxnlW8hOh2JGd 7YyWtutusVhDtoNsMztm4l+M0zlVu6svjCIKbNDz9GI5N3UzxwR4sLfbz22Ef/nnkD6qcHinYbI mr9S43wpWkS9/XkD+0ZhlxfxMCIGQDZRCw55Jm+1kSV3bSq+2FaK62RP+eCaO45o= X-Received: by 2002:a17:906:c802:: with SMTP id cx2mr51710127ejb.114.1563948208142; Tue, 23 Jul 2019 23:03:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqx9+R+71mT+WLdMNe+sOOgsV+bFLrsE8U+XHiTkeY5a0k91NVg7M4gu6YCvveaNiBXGRP82 X-Received: by 2002:a17:906:c802:: with SMTP id cx2mr51710043ejb.114.1563948206608; Tue, 23 Jul 2019 23:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948206; cv=none; d=google.com; s=arc-20160816; b=0lHjYRB5qFoVlDqkU7AuxLflARjhbQ5WET829kVcoOoYxCgK527qvTYFaTY1cGdDUT kNWhxlCGArzjQW0Swd8bmP85V0PONFZXwDtMNjL/YkZiks5Ti9SIjEvqAQhJj+5SvDha ccHZ+3PQV1p5geVXiYjbnjjw2LOYccwcRLdQM6s/83zu1SlWZwIHhgUDv5vEmcOBPQd9 KwPKw7zMdyULf2PWywvtpmke/5uWiBaOpDDqs4Yn7X496/sMJwQ+GBDUXTHRdmAqkyGv wS4zaMVkWHNHzjVP0nUmD6EizEUpzvP6e4dzMsN6Axyxnklp0NUWLrdt5QcQ1HS08zuY 5fDw== 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=0PoVlhP/B7SmAW4NwkDAl9x9/d/JAFrQTHRVEkNR7AM=; b=DIdTaZ2JB1lhz6XKTH4IxamglfN/0kjb1vAvghkXWkcTnUlC4w0boqBJtH2gWRhzC6 6TS/qZ1IlW/X/astA5SeAQzUl2wGq68hd9B+bD2fjjuht996YGiHjhDLAlA9wt5utcxP CgK3CfM17klFGx+fG4SE4KlCcVLUdTSzQi2HERNfe9DtbMFc1yH/PRf6yr51VUK0gCs2 DO8J0w2VlksP0h13D6RDUW8x66I1+RQmEgwrOJy5dJbaRws9hXpJy4TxWJSFH/W5L+OG iRdIFLR6Vr+MjthF1sGNwFouFZPMLYvDaeJmUoWHXqPj0ewHiudhmkjuzt69DdpV1dMG yofQ== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.199 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net. [217.70.183.199]) by mx.google.com with ESMTPS id m32si7816912edm.415.2019.07.23.23.03.26 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:03:26 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.199 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.199; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.199 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 relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 4F010FF808; Wed, 24 Jul 2019 06:03:20 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 04/14] arm64, mm: Move generic mmap layout functions to mm Date: Wed, 24 Jul 2019 01:58:40 -0400 Message-Id: <20190724055850.6232-5-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 --- 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 fd5b1a4efc70..7b8d448363f7 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -271,8 +271,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 Wed Jul 24 05:58:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11056017 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 6495F912 for ; Wed, 24 Jul 2019 06:04:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 538B12875F for ; Wed, 24 Jul 2019 06:04:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4558D2876C; Wed, 24 Jul 2019 06:04:35 +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 B59212875F for ; Wed, 24 Jul 2019 06:04:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6C2E6B0008; Wed, 24 Jul 2019 02:04:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E1DA48E0002; Wed, 24 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 CE5486B000C; Wed, 24 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-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 820306B0008 for ; Wed, 24 Jul 2019 02:04:33 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id n3so29535681edr.8 for ; Tue, 23 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=xUMIXSZ5nuvBFA60vBMZNUvU4VVEKzW7SPhwc++PAj4=; b=ZD9v3243JN/69F+GokzPUqiyeCH5WKe31vUxP8kxMrTowiA5Dpb85bPYuSJxtIxgyz FuyrGwRUDDbEDHvmC0wFS9oVrMhMVUNw7RT2c1iX/dZIa3iUp8uopr0bhn7QG6jSvrsA /h9Yn7QGmgIIWf8jXQ979VaxRDOR6mWmXB//Cko7QUTL1CsdeLaPB619H6uUMUETKqDd czja8qP6GTNpsNCeiXctMFvK/xPU23I+0YtKn3gih8VQ5hh1t827BKQuFteKlHlYXCK1 siGMToJWlPiIl30SlPoiBkDAAgqNH/9qpl7XPgbZyMfulvS0Xt+SyKuYTa+cusO1mdMD Qpng== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.178.232 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAXpWl0guTa9rYAzsKJH2YjwSU+nmHSrJUlQprBPqpdVXsocBDor DiFYA314e3MiwoQudtIierD9T9aVIAgoUjpKpsazKPy1NZ2OeWk0rjujwW3GvkeZtuJV7+f1oCI 6QhnVS5M4OnEkHpo0STmo7teSwLnD8ifnfiUV+QzSQpTJBpZkzjlgW2Cgzc1wRb0= X-Received: by 2002:a05:6402:683:: with SMTP id f3mr67885709edy.200.1563948273110; Tue, 23 Jul 2019 23:04:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpl4UoUS/PIgDmTxAzBFNEZ+7dkR8UbyPDwWbuwh7OrzXUva5qvVO5QCX7kFTaBf1u3FW/ X-Received: by 2002:a05:6402:683:: with SMTP id f3mr67885674edy.200.1563948272393; Tue, 23 Jul 2019 23:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948272; cv=none; d=google.com; s=arc-20160816; b=Dm245FNNOYNPhNPVTMyLDWXxiMy82BwRp4xze0zQQbTvDb4Gybz32IU3EqeEYSqeft 21JPhCEmyMelVWRVa3RzaHsvTqQfrpRJCszJi90jIac2q+8fBDh/RNq0EcPZ0qT0zkz7 rRiSk9ZMO/uxLzOERBrRXwoaFAXaByrhngqC7gSGDfAHe8JQWvBjgtut5nq0ZV3476wc PRlbe1nl7+NQBkXcXd16Gx1MnArNTIGE3iM4Oti7jwxIEuafHjpgL8qjnyTZA59HSyTo Lka/WplaVQrVVsXtaatvi7uzuWfyd6kPo95f5WbfKE5N5fglDuQZJWazGoyWqplnk51h AhPg== 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=xUMIXSZ5nuvBFA60vBMZNUvU4VVEKzW7SPhwc++PAj4=; b=SGTnnaV8OkWPFb0BngA4qvqtKf38abPU0tENzJgWJMOexDK6dC9KKdZod3OLqPCwH2 mJGM6f0tyx3yqhEt60d3YLAYMPrx7igQcHNY/81wN4ddd8XhIeI8nxTRrl4lQWfs8/iV HWx+1WVvZlDs7pknAuMbJJ4NDeDpPFX7aIVkXTHV5eCGIKYhbksiIsKjR4nQ7JW5xV+0 s6dhO39xvMdDJ6Hzs4/GC+EXqAnuqEd32B6fuujsfnZ3noDYs0uReFMZbIEqLpVQvLNe pNCyjkSTTZ8s1/oQuP/RoiQxoi/t5i56jpeHw86VqzsRykeEIRZrN4q1G49GJVT/lY71 qVKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.178.232 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay12.mail.gandi.net (relay12.mail.gandi.net. [217.70.178.232]) by mx.google.com with ESMTPS id m34si8328058edc.296.2019.07.23.23.04.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:04:32 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.178.232 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.178.232; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.178.232 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay12.mail.gandi.net (Postfix) with ESMTPSA id B5FF6200008; Wed, 24 Jul 2019 06:04:26 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 05/14] arm64, mm: Make randomization selected by generic topdown mmap layout Date: Wed, 24 Jul 2019 01:58:41 -0400 Message-Id: <20190724055850.6232-6-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 --- 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 6a869d9f304f..3f59d0d1632e 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -524,14 +524,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 Wed Jul 24 05:58:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11056039 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 C8539912 for ; Wed, 24 Jul 2019 06:05:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B531127D29 for ; Wed, 24 Jul 2019 06:05:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A74D928450; Wed, 24 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=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 40BA527D29 for ; Wed, 24 Jul 2019 06:05:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89E5D6B0008; Wed, 24 Jul 2019 02:05:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8506C6B000A; Wed, 24 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 765E26B000C; Wed, 24 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-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 2B3696B0008 for ; Wed, 24 Jul 2019 02:05:38 -0400 (EDT) Received: by mail-ed1-f70.google.com with SMTP id r21so29565233edc.6 for ; Tue, 23 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=eym0BMHdbArtu9uPr+EyfIeUu2p0S0z5kNpGctDciqY=; b=bYY1eLS1tY70alP+Qq1Ah98DmcWYIIs6svlsT/pPVy8nzHav+vJ6dFm8Je96iC3p0e Lmht3MslGp9ybtj0IhwEMtGr13DSOBrPfKa2+Fjw60K2LmTV+9DjNcT46rXK4N997vvU sPeaqkJQlqhglPTKoNYD1AaGOpW8krhqjvgIxENvlSuhVuFLRiJ4W5b7/jSudUUF7cDf +I+1fhLKZZ6skLaYolNzqeImzNep7dpdh3p7rN3kQZQIhffWQvCz8Nz9+btFnn6Z5L46 o8w2OMlNYeo7II0+N57bKhyM6Oo48+aMgsubAdN2TJUlajHW5blPaEY6yfc/dZg3xFMD j7dg== 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: APjAAAV2/tFTc0G7gWY17kVvfl4T6zkWqa7S7sIapThoxi1fnEX7O8Sx Lf6rvL/PiOYrbUf6mMZpPK4cfhdfEQuexBk1EltwsHV5sDQsNJlsLYcOLRIJS3USpb9tN6NzqYX PlsYDOnl8hLIwKiwzdjlewkMFWo0yH9mhpsifDj+SbrKkUPAYx8fPeIo91aQKRyc= X-Received: by 2002:aa7:c24b:: with SMTP id y11mr22204011edo.239.1563948337758; Tue, 23 Jul 2019 23:05:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwq6NK5jc9usFkBFIReU2EBq+O1KXGhpo7ov17FTC6zYzh4N2S3rdhsYQl6Yak0dAhf/Sl+ X-Received: by 2002:aa7:c24b:: with SMTP id y11mr22203969edo.239.1563948337041; Tue, 23 Jul 2019 23:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948337; cv=none; d=google.com; s=arc-20160816; b=RH1skHXfb6DiSX20fvrdcfqT61SM1R9EenpS0mfSejmNi59ILuxJhE2v4XtversLZC D9RloBw2qvbkK0lbLAkjqgO+EpW3OxSFvvIBAXgyn/BH5bWkF0phcWsHp2Qgajem9FG1 qv+/U1SoBUBmdwX0iIgvJV10KCypzqLgubjxq95ooejOb5AYFDzB99ReMpu3OMZEyFUc KHMjJJdveh/Q3nF+LDh7rxd4hpw8SDOIdi/7vwYzM4HPjR0/90BLHY7DK105703XdYej 33CKYzPI+bbCWTyLuXp5hS2NazG1f//QmcuFY9toln1urmxzPw9lXWZIBs3Ke9+fxrI7 51XA== 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=eym0BMHdbArtu9uPr+EyfIeUu2p0S0z5kNpGctDciqY=; b=pn0jgdNNw6jW6X5bOaI1oDwIP7UiKLnGTb9NCMriU+TF6DBpHKMnCQsp3ivJPjMBf/ 5BAB/PouT5K7yVwHXJyVeSMfzwZu3jWsFsGH4Bigsh1C1g43yXQG3seQnkMFwHrbGPC0 R+BBX1eWylKd6vUI5cIva/hjL7ElyjRaX+ogIXnnFrkzuNEYxAtAeuVtyk1aUV9o2zPt 8adfceDZnhIic2P86lbsc9zTTMY+8QvXgruFRZ5Chj9t2asuwJ6NKokTXonV/w/7OHYV Z4ofTWirhQXrXP3rdasleixARud9SzpTDfJqS+OIMYbCAcH3KdWHmSWYlZBhWh8+/4H7 zeGA== 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 oc23si6987058ejb.369.2019.07.23.23.05.36 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:05:37 -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 7E8472000C; Wed, 24 Jul 2019 06:05:32 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 06/14] arm: Properly account for stack randomization and stack guard gap Date: Wed, 24 Jul 2019 01:58:42 -0400 Message-Id: <20190724055850.6232-7-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 commit takes care of stack randomization and stack guard gap when computing mmap base address and checks if the task asked for randomization. This fixes the problem uncovered and not fixed for arm here: https://lkml.kernel.org/r/20170622200033.25714-1-riel@redhat.com Signed-off-by: Alexandre Ghiti Acked-by: Kees Cook --- arch/arm/mm/mmap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index f866870db749..bff3d00bda5b 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c @@ -18,8 +18,9 @@ (((pgoff)<> (PAGE_SHIFT - 12)) static int mmap_is_legacy(struct rlimit *rlim_stack) { @@ -35,6 +36,15 @@ static int mmap_is_legacy(struct rlimit *rlim_stack) 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; From patchwork Wed Jul 24 05:58:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11056049 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 F3EBA912 for ; Wed, 24 Jul 2019 06:06:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3C8F28768 for ; Wed, 24 Jul 2019 06:06:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D76D92876D; Wed, 24 Jul 2019 06:06: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 79FDD28768 for ; Wed, 24 Jul 2019 06:06:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC18C6B0008; Wed, 24 Jul 2019 02:06:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A71EA8E0003; Wed, 24 Jul 2019 02:06: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 960998E0002; Wed, 24 Jul 2019 02:06:44 -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 471996B0008 for ; Wed, 24 Jul 2019 02:06:44 -0400 (EDT) Received: by mail-ed1-f70.google.com with SMTP id y15so29563411edu.19 for ; Tue, 23 Jul 2019 23:06:44 -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=iEUnru/pgX+pWRywt03LhpHMFzmbntBrlVCKRjubFbE=; b=CSDukUiRH8jd5pm+VMzNMudVbz1LCorCiFnztKw6MgSLNZ5kJ2pqxU1Ax27yqZF4Gy wMeXZWNIMXSxlQccdnGhvVCIFZNOMz6Du4MhxzVMDjGRRsi98OYhzqtkNMUwnpmCQKQB vf9KVuuY9pAsSOdp36HKcOoxbkhUZypzKpBaxl5dkx3OvshnLRGK8De9K7GjUiAeqBPG z4GxtuZ2PwLjHxpfIB0/tjnbSFDNP5E3wb/3erlJkBPtUbqFD7teYM5BvvlN9j4iq7SM M+zgLcBM8wwxsKelgIx2/rU163G1rU4gxra7Ho9jHbbthNntxdPJWx16kVjJ0hI7yETK ivlg== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.197 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAXXcQj3y+s1MTyZeDwVc0r7/YDcl0yDt4ZynnWCO//qM940xbLx kPpBUIOtoBA6mjgTTxEC2mYB6/OhZdB7ofihWzhLmQuGYKJaHa11GPGWG7V3aMXSVJNEraeyai9 8pXo4P5XeBVPzHBdi175FUZkh8M/CHmwQVm8T3QNqb5vxH1QhXWsOKa7AErz7KYg= X-Received: by 2002:a50:fa42:: with SMTP id c2mr70613489edq.48.1563948403885; Tue, 23 Jul 2019 23:06:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8DeulJno0snU9aOB5b/d1qjyj/gYHs6KYgkzLN9Mgf2PHC76TGkTm5MAv3VLCjyqFcewI X-Received: by 2002:a50:fa42:: with SMTP id c2mr70613454edq.48.1563948403036; Tue, 23 Jul 2019 23:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948403; cv=none; d=google.com; s=arc-20160816; b=wQBcNqTcSXj+Fd53VmSQ881arBBN5rbK3E81wJ9WXXZ/3SFrWAOTc3BEqHyHseewQ0 UUECOhgJv6M2lYh5y76IQI79GAWNZLFxX7H01GL92rnTihYd51lciJjfy3EUJ8WYs+2J HNm+hvedWoMz9xyX9Q/bCJ8ZDxiIZI56Nx48lwSlHBIZeQPgBQ06G3OMrdJzuS+dE7Sn IAVKs+b9M07FAqWdimRnJeJ1VuX49TuYgXa05cGtOCjvtAON9geaIEH5idtuKNqwB7pt b/hEgRO9Dqp6go9eEzSC6VTJX0OUWPn4AY3J5xsOFMphHqKvOWDbGT+CZHHIHm3Fspd6 ZWjA== 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=iEUnru/pgX+pWRywt03LhpHMFzmbntBrlVCKRjubFbE=; b=IK4NdtS9ClA8mUBbnw30qU+kn9VMYmcbFBNfmQ2np/+oBsBgSbh/BU/mGyNah5mQ7B MaN0IsFr4mshm3yWQDL0nbW4IYZEvakZlBpZgq7P1t2qFLKT+G1DNtZ/KD2SZA0n9Xvs mCCswEptte/YIl0iCFgKyY+WIzCUQRqPKjUV9KiX8UyQ7S99j34+kDZ44Zpo+/wARM7a 2WYE2/6dcV9wknjEzc5QymSZEuqw27kCVoXk57D1jOK5L4FJhCZ+Tsiq09IdKpa7kcir DMPfeYb/Kc6vhIOByNlLHOq+pRNwA/dK39N0mYwdasDt3zMLAlGnuZurAteOnHdbizWW qh0g== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.197 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net. [217.70.183.197]) by mx.google.com with ESMTPS id bq3si7216163ejb.272.2019.07.23.23.06.42 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:06:43 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.197 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.197; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.197 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 relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 45F331C0007; Wed, 24 Jul 2019 06:06:36 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 07/14] arm: Use STACK_TOP when computing mmap base address Date: Wed, 24 Jul 2019 01:58:43 -0400 Message-Id: <20190724055850.6232-8-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 --- 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 Wed Jul 24 05:58:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11056061 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 28D37912 for ; Wed, 24 Jul 2019 06:07:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B19728768 for ; Wed, 24 Jul 2019 06:07:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EF4F2876D; Wed, 24 Jul 2019 06:07:52 +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 80C6828768 for ; Wed, 24 Jul 2019 06:07:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF94A6B0008; Wed, 24 Jul 2019 02:07:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B83058E0003; Wed, 24 Jul 2019 02:07:50 -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 A229F8E0002; Wed, 24 Jul 2019 02:07:50 -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 4F8C36B0008 for ; Wed, 24 Jul 2019 02:07:50 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id n3so29540116edr.8 for ; Tue, 23 Jul 2019 23:07:50 -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=pg2c2GGboO97HgSLIQoHM8sYbl0vdbpaZETgXWDAdW4=; b=UTMf1VbYWxx+KE22c4bkRQz+UugArtubFGrZI9cEb3c0eFhez0o4B9MaroQ8BenfVi RGjqhLG4RK64dVjEUJ2DKKwdfpnB/fwu5816G1RpkwyWtDyaS2u0CvRXcWDizbFu+uAH ZEm/Ct+xCeAfQjPLBdPZirkwbqjAK3JzrMC8DjaFySootROALyFmoSGfx1puGXmiDQDg 3K8761/MsTuP9azRlz+Sisfdj8slUrPvg82mIfBqKbdoiuB5gLhMWIwrSOY/2rhL7V1x Op0WslRW39Do0KdhzaZIyyKEjGfDSm75aPscSdN3a/2S7bEwAu/IpfAcsrYon3Iem0T4 Jv2Q== 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: APjAAAUo3DAKZJDrTwJIzhZVOFcs/qbMLk9QzjMeeTnRuCtsiOAISCZl YHuTz/n9bryV+S7ZlS+yDQOF5DesaQP9zhpgLTG8W+pgax4nMrzeoSflCj653C83CKH7DTIrHHx dMUYLpYphS5BbOP0vKVcGUsVVBbgHdexDPHrnq4tYhfa866Up9vvc9+ULWFqOGOY= X-Received: by 2002:a17:906:94ce:: with SMTP id d14mr62584514ejy.251.1563948469877; Tue, 23 Jul 2019 23:07:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6qoHA7gelOe68yU1ghsrRoHKyRUeADjy7QN1AOKPOY76gPIj+p6xpHh4tHv+DMKBbQNaO X-Received: by 2002:a17:906:94ce:: with SMTP id d14mr62584434ejy.251.1563948468193; Tue, 23 Jul 2019 23:07:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948468; cv=none; d=google.com; s=arc-20160816; b=Cmj8NlwI3l+48Y65jO3usZxXV0m07q/UZzlEvf19sSJr3g+Ix4lEAUSLOPDEqqy7SP pTMbyZ+rYSL62AwhpBJjMjjJmFPvvaf9tylMwPvz1wqAy2ztVrUzrxIV7WOYBSJ/Ink1 qdmBoGhcQKRfV4f5On1xEqaFVm/NQPRj56QmtisxAFvPEejGumFMC0w9xtKSHYAkdRgf RBtfUXkt60SdeAxqDg5nng/OJvGWsbt1d+10slLsEbW2SaKYaxtpXWq9Jkqzvg5Jz2Bz K1rqKddyrqL88laGUzqyodZCR5pVBWDlp9l7HeX5fzuAolcivdRUfZQDfyK3R+uRCv/0 epZg== 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=pg2c2GGboO97HgSLIQoHM8sYbl0vdbpaZETgXWDAdW4=; b=M3QDQpKACAfD3vYKQj4Zayg2dIcVJDeF6L1g/JQGCrTUrbXyy8UbLnFlfpa+mK4jWL QzH6y+J5EACUdL+BhPbUgg6FwZRhQakArT/E8WO5tDMlR7opBVhmcl+2YuNwRJGYjHAe D21X7PxHIN6iDNbochdCmZhPKC4YNCxdXytoX10ESnDRKZxYhzS2/XogA1QAf+qgzkHT sZXKXuG2lhdrkI6KtpFwrWDB9JICiw5CeRBLkwO/mvrQZ2tEcD8ycae1KQs54avE6TNa XDuWtWoyc9RF2z46fzBdsMx/7ylLkhf4I/62l9QolleBW4dkZ7RF1ba3mGQodLf61iW7 Vz8w== 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 hh20si7037670ejb.240.2019.07.23.23.07.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:07:48 -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 389EFE0007; Wed, 24 Jul 2019 06:07:43 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 08/14] arm: Use generic mmap top-down layout and brk randomization Date: Wed, 24 Jul 2019 01:58:44 -0400 Message-Id: <20190724055850.6232-9-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 --- 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 Wed Jul 24 05:58:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11056071 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 E104E13B1 for ; Wed, 24 Jul 2019 06:08:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2B9128768 for ; Wed, 24 Jul 2019 06:08:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5F632876D; Wed, 24 Jul 2019 06:08:55 +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 6EEFC28768 for ; Wed, 24 Jul 2019 06:08:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABF086B0003; Wed, 24 Jul 2019 02:08:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A6FE38E0003; Wed, 24 Jul 2019 02:08:54 -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 960A18E0002; Wed, 24 Jul 2019 02:08:54 -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 469426B0003 for ; Wed, 24 Jul 2019 02:08:54 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id y24so29606688edb.1 for ; Tue, 23 Jul 2019 23:08:54 -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=yu1rRm8vVlWs2k5HxuFICi9Y4uSbUPRh8t0lFYmfJhM=; b=VgNs4g5H+1wTZFIi2kvu+Kfm6Ec5V9lWBCW4D0NqfWieQEG+iIWJfeWVLXTj5055w4 Tr/+w+HQbb5ntC/UjO0HJm0mN7Ziuu8TczwHIVXm6f+1Z8Fts+765DNBAhxZhamMZz18 18rq4jABnbbf/njSU/UBweoW1A3g/lhFmOleAL+9X1VxHzMf+9EhE5rILdskvmv7/S+V 9B/2TLn1vnYTvNy1vXJXodqi1/33TK5x7xkhBoItUPOyfF7+EbRXwCOJMiPEhliRZc65 8NzDTvgyNZNgSeHQq7gu1BUCrAZisBKukhqLLaFa4vapqEyPbTb+MNdD7YZ+0Km38xPG 0c5w== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAUe/oe+O/abh4f40agp689BsYZKRkF6WQTJKZKeJ2XtuQIuLgbL ATK3dzLPTJtWKWdNOEGc/G9Zbm40x482peoy38IxgtsRPMyVl+P6rU3I13tk35hAEt41tAbjXay PTxNe2X43k5CTdAiSBLB1HoQ/mO9Kn6bwRq8/CZgEoNblL3nClshpObvxC1MSCx8= X-Received: by 2002:a17:906:4b13:: with SMTP id y19mr61001484eju.145.1563948533871; Tue, 23 Jul 2019 23:08:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhRscGGM/7WKzsJ5uP3AfYRfFtwPVF2r5uvhO9IiHfPNY0bojRsBKa82r8+v3Dh9JT/XBv X-Received: by 2002:a17:906:4b13:: with SMTP id y19mr61001447eju.145.1563948532976; Tue, 23 Jul 2019 23:08:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948532; cv=none; d=google.com; s=arc-20160816; b=Z5hcVAVT2nQDYzRg/8YDO5LctGIDw/B/ulqzGF0kgTkweN4rwnWLCoz2lqY3FCNczw j0UsDCJJR4Z+ncK7G6OToVphBMB3/LLs1jVq3wSoug6kSAjNOM63H3YfHTwNttY1yz0N F7XHmuaJSS9rIkNtP6cwQ9QHnskSiylDAReCSsSJtIDEBL6n0KnlGZ3R397UwG6NLAHV Ml4i8RFsver1Q7IsT9lN/NyzhJqlRWDR25T/09kRydKUe309Oqxv51nuOTP/F5YmTBdY m5KB9/KUiA/chDHNOGcTfd2ZtFZY38CcrgwqhWF9j4yAmy4/H3JuUA7vvBCqPVSC9T00 Ue0Q== 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=yu1rRm8vVlWs2k5HxuFICi9Y4uSbUPRh8t0lFYmfJhM=; b=HpLBMtValQoTWMHlJqOYBAczKcOaRX8mF+ZyNI+O4DSoWHq/scgvRe4XkkPOlcrLOD l/oS+ewXrPQTIYpY+0Wk3BceCH7hte5Dg/G/sQroHfj7rGK5OaGiv84HJbBginD3yaNh M31ch+68hhbh1s6cD+h2ssu9SE4QYyI3p+jKDcB0ie4JUhAjnslFiLT3pY2c6/l8kRo0 VvUILLpnTLVdvwqEGpzibeZZi3rgKCOAndMHXLQo2v0skSwPeubpjoNs+VBCZMA4cddc s6uM/gSRlWUY08CdbZrYu7Ba4fT+XwYBZQBp2fW+8TXbFHAcVxfBKXeb7TCAlEQfLOQq oCIA== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net. [217.70.183.195]) by mx.google.com with ESMTPS id q44si7634788eda.375.2019.07.23.23.08.52 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:08:52 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.195; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.195 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 relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 59E6560008; Wed, 24 Jul 2019 06:08:48 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 09/14] mips: Properly account for stack randomization and stack guard gap Date: Wed, 24 Jul 2019 01:58:45 -0400 Message-Id: <20190724055850.6232-10-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 commit takes care of stack randomization and stack guard gap when computing mmap base address and checks if the task asked for randomization. This fixes the problem uncovered and not fixed for arm here: https://lkml.kernel.org/r/20170622200033.25714-1-riel@redhat.com Signed-off-by: Alexandre Ghiti Acked-by: Kees Cook Acked-by: Paul Burton --- arch/mips/mm/mmap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index d79f2b432318..f5c778113384 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -21,8 +21,9 @@ 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 ((TASK_SIZE)/6*5) +#define MIN_GAP (128*1024*1024UL) +#define MAX_GAP ((TASK_SIZE)/6*5) +#define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT - 12)) static int mmap_is_legacy(struct rlimit *rlim_stack) { @@ -38,6 +39,15 @@ static int mmap_is_legacy(struct rlimit *rlim_stack) 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; From patchwork Wed Jul 24 05:58:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11056081 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 E481813B1 for ; Wed, 24 Jul 2019 06:09:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6DA12876C for ; Wed, 24 Jul 2019 06:09:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAC1928770; Wed, 24 Jul 2019 06:09:59 +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 7925D2876C for ; Wed, 24 Jul 2019 06:09:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABE686B0003; Wed, 24 Jul 2019 02:09:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A6F618E0003; Wed, 24 Jul 2019 02:09:58 -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 985918E0002; Wed, 24 Jul 2019 02:09:58 -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 4A3406B0003 for ; Wed, 24 Jul 2019 02:09:58 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id n3so29542686edr.8 for ; Tue, 23 Jul 2019 23:09:58 -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=LxxYxWqxNkL+rNpCPJA+2SpcBDfwJZpToQa21YnSig8=; b=JhRc2AY7Z9B0A6CK/ryBI9IpuapFYPOgZ4AC0bVVV7USsFMLXyV/RhHs6nbi7kjt6v svm0BzU94QtoK80jwPG1PtbI4fJpCvRTmDkp/NHXNYjc76z54k8TxxJvuIT4losuUirh gCjS0tObMf5mZuXwCwRtFKmeXJMOXiYAfQfBngx0K/GZNgWKWPtKFwr7Z+Bm4ykV9TMr Zoyt1SNIDZyXLaL7FXmkDwJdefhOHWFfBH7ogy6jwq7aOyaHCQrRSSfLTbFTUTa09o0K fThGDCQio4QwTZghiMPotvw5l935uw1YWEvF0Smd/GmuCRxvtZTQcmdNOtMDN0mpU24l 113Q== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAVnvVveX8PrTSc9Ku+4W00FgREWrCY+htwqjdDNY+6MEOZ3hMZC LaasM5wdxUlcXqVjzVx/hI04FWiiwmD3p5QTef0xO4SRO3ZMXpWEEYuA2MLiAS63TUlEztrGRnR 4KBcdv2SZewa5No3t9lVarsehG5BvQHtwq5vgKBLOAHEB2/SdwCmuQD03w8rVufE= X-Received: by 2002:aa7:cd17:: with SMTP id b23mr70146462edw.278.1563948597898; Tue, 23 Jul 2019 23:09:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJu+1BgmWhl+DtWybZigvpQLF3Pxdwwj/eKFurkL9URFzqqeZYNqjsfJ7KLCT/jeuWOMse X-Received: by 2002:aa7:cd17:: with SMTP id b23mr70146426edw.278.1563948597005; Tue, 23 Jul 2019 23:09:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948597; cv=none; d=google.com; s=arc-20160816; b=EjMFwcc+OG/Rj79652qs+2dUGT5E77oUVf9vxqGdhnaV/ZnSJ+8EMtz/TrcXWrjHHv Rdl7hJcPGn5psm7JJjC8NCPRykOuyAho8hmMcxvUslNVUsLZloMq0DQpbBGF4fKF0BXM OXERc6n4t5VcuUfOqirwrhEPaLEB/hlL7yWrnpqmRC1lYNDMhqiiAuOfxvJKXuFi+n6A eVvaRwPBXggc7YJoHLKeOmfJHWpk/ue9pTdvssINjMn0SbvN1sjPbQXe5Sc4583mDTpx PIk+JtNYw8UC0wEEjV2foZw3QOt9h6XWTcVAERszTOSDG38PTRwsyYUPG2lNxTOCGORZ 4SmQ== 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=LxxYxWqxNkL+rNpCPJA+2SpcBDfwJZpToQa21YnSig8=; b=wZU4cU3GGMYGJQFAA9shb8ybhd5buzUXWuWVDO40rdwh7PSx9b9mH1fUUtcgURxquT 64tScXpC//fzd9+g4razXIeTsG/+smTz4C8U9O7L/7IDrY74vzQO1gsgzSPed1fB3Slw dapf6MYxcejiLMWyzuMGdhcQkczUctU6gr8EBiN9QOnBJZbKh1Yg9utVRwK//I9r9tXX mSqfSJ8lO2wr7Z0p2qm7n/CQG4gHuHwdutuxHKEpyt3fLLQyORpszreyQ1j+jCqUcA17 RKRTpejIX138arENGTNOp0Cc7EXJkt2e3S2EAr2Hx6rEmZlY9orbpAEJyGOYuLk3YVeq oEeg== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net. [217.70.183.195]) by mx.google.com with ESMTPS id b36si8041886edd.79.2019.07.23.23.09.56 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:09:56 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.195; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.195 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 relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 226A060008; Wed, 24 Jul 2019 06:09:52 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 10/14] mips: Use STACK_TOP when computing mmap base address Date: Wed, 24 Jul 2019 01:58:46 -0400 Message-Id: <20190724055850.6232-11-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 --- 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 Wed Jul 24 05:58:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11056089 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 63016912 for ; Wed, 24 Jul 2019 06:11:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F0A31FEBA for ; Wed, 24 Jul 2019 06:11:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D6D22267B; Wed, 24 Jul 2019 06:11:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-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 C46841FEBA for ; Wed, 24 Jul 2019 06:11:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1215D6B000C; Wed, 24 Jul 2019 02:11:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0D1CB8E0003; Wed, 24 Jul 2019 02:11:03 -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 EDD178E0002; Wed, 24 Jul 2019 02:11:02 -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 9EF066B000C for ; Wed, 24 Jul 2019 02:11:02 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id r21so29572222edc.6 for ; Tue, 23 Jul 2019 23:11:02 -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=0C35ePTka3aILniTSobALrcos9kafZPeyeIsA3FK51o=; b=FDhvtyTLzuyUXdv9GdUxyembbHcZpNKdHcUm/JseES78XTw/IRYSG18XlfdntrswdU 73wIU7kvk/SoX3fQKbDN8r+HpeXTdGixsYsmru67dg2TqW8WX3/ZcFCCgB6DvDQvtXG2 5FozXlg1HiO+Wg6VOUkdRMcvJahxOVbb5ITHPEB0hQvYKbrgT3hS5sthjN+LlEI2XqcY XdKpVa/O2fCLcZgsUBJX/Vdavso6qozustMTuBIUtv0F7KvMJMmVokKtGtcWlfUimvtc w9tCYjX80JYZK5Z8GTVPkYR275urI7PhSs29B1OcL2fF6cmlcTgkIa8w9IqCrqIFNNkV 8tfw== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAVfu8HiVdfYmRuq7JIF2ia570MlGTdRbldxNWx2VFeq+3JzfcbW Dq6pGamedLo1Rd0iTVEcls/AAbSW6lDzHF9Kj+Q0w3Ibt5bG8bG5Keir6fytgbQH8GzyhZLhDSD lJwnT1sS+nPMzrdM2NhrssL80Awodv1lyXSxCxMFkFcZK/w1SuWJsu0BQMqs2zyQ= X-Received: by 2002:a50:f4dd:: with SMTP id v29mr69298808edm.246.1563948662230; Tue, 23 Jul 2019 23:11:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqy53MlVzhpHa8vhDGKto69ACey0n0D6t3TE774N3v7mzhlgt9MkYHUoYrSNy0lEqRjA9UNe X-Received: by 2002:a50:f4dd:: with SMTP id v29mr69298754edm.246.1563948661380; Tue, 23 Jul 2019 23:11:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948661; cv=none; d=google.com; s=arc-20160816; b=WkzPuVJvFWcHyOy7hlM3Y3nCJqGngbI//8rh2h7XIUVh79idZ4CkQq/wCMl7P1uP7g opRzhloxjeA9+5GF7f5FSnQSobFHaYFP34Nkolv6PMc/QPlq525JkcqcIxiRN5YA5tYu g2HXvZ0QxPWrZcdYDVYkhMUXvgPlRJmtJJYxXrK58j19RzuiMMjo8K7ZGcRCZmA0nyX1 MlbmFIpLM5uRjZgw6B1H0cLRb6q2DtsfpI+o5jMEs0zUHXWEyB8AySbQh258WJ3pFQd+ jNSLUOucOp9nnqcTSsaE5QX8bPhUgoWTALEtvzeI93DH7BgGiTtVSrzjsc38/ICCdZYF 1z3A== 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=0C35ePTka3aILniTSobALrcos9kafZPeyeIsA3FK51o=; b=VLS6CNuIeGplbPDE8WpveYoPPZthrFD3qqoaRKWUd1MhOh3BdP9xvzhyS0nm3gdsfJ FYBCTgE8Ur+U+mr59CYoF9g9sR4eRKAMn3L/ZmX+NlaDqPlHSMyfsunBQsRA2CbggmHa wXg3yAjqh1Sz3ycw12HhwWCV0RcdOaDyv92pdQ3fR7dvu528hsBpQRMpX+W62ZO3ViPr SqGB4TCjaySVRKtgM2Rga0jlHa5W1IM4i5BkFtesNrq9GTwlyUJ98wTRCNPJmc2UvhQ7 JDuwnbWJq+lgLVJ2WHtbdoWUDI2b4Af3JwmnoDvS0qaX9Xna+SsWOCUD3SdwNgNLWvlv 0kvA== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net. [217.70.183.195]) by mx.google.com with ESMTPS id j42si8419051ede.285.2019.07.23.23.11.01 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:11:01 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.195; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.195 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 relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 1BAEE60002; Wed, 24 Jul 2019 06:10:56 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 11/14] mips: Adjust brk randomization offset to fit generic version Date: Wed, 24 Jul 2019 01:58:47 -0400 Message-Id: <20190724055850.6232-12-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 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 Reviewed-by: Kees Cook --- 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..faa5aa615389 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; else - rnd = rnd & 0xffffffful; + rnd = rnd & SZ_1G; return rnd; } From patchwork Wed Jul 24 05:58:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11056101 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 64DC913B1 for ; Wed, 24 Jul 2019 06:12:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53C6B2876D for ; Wed, 24 Jul 2019 06:12:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45BDE28774; Wed, 24 Jul 2019 06:12:10 +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 EB3D72876D for ; Wed, 24 Jul 2019 06:12:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36B766B000D; Wed, 24 Jul 2019 02:12:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 31AD58E0003; Wed, 24 Jul 2019 02:12:09 -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 1E3EC8E0002; Wed, 24 Jul 2019 02:12:09 -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 C313D6B000D for ; Wed, 24 Jul 2019 02:12:08 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id y15so29570119edu.19 for ; Tue, 23 Jul 2019 23:12:08 -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=66FrIHCi/FwU5Qd+YH0GklxRIkE/On5h0rf1MXh1DUQ=; b=tBiSCOGmQAGEgxdB4jHKm35Wi5bD37D1GjQWJ1+Zr83RRSQzB6blClAxnCKI60RUG4 wOyWhxzmQCbmLePbANxOfpWuF/pH077z+XyKv6jvOjm9BF09Hh9zJLzgv2pMyTzyAcIE SnRj2uSbak7p6xQs4eKevI8yW2cLm2yNIWtBGqhHW7aWb+kbtn0JpmnYVxLipetCfxhw 6gFxe9XOl/WKVBNhdvgoCEn5wILEL6twgsVDBbuQHzPiQ9LacfcQYlQLhDxUdnX8V303 UZzGGsBsCWHlpk4MclKCuKfpJgyBBIWzt8IPjqSFZJz1L6Gavntu7yC+bpRDuDJoZh5O l5pQ== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.178.231 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAWEGpKuQ48zkQHAHt4TjvR3IWvCBCdBcIRkjbrrJuWH01LGdkgH cGPpJttaoV754++u8PsozrFZR9wNURWRT/L2Z/+ideINKAFmXSCqRaCG41KO9ABeN3iwmEfD31H Y5MxfkXRe2t2H8V/5Lh5gSSjqLpT53HFbPb+tlEWj1JmI7XgKqb7FiGP0HUT9li0= X-Received: by 2002:aa7:c515:: with SMTP id o21mr69490087edq.2.1563948728389; Tue, 23 Jul 2019 23:12:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVJVSKnQw6VwOkna3RuskGMDrKwh3llukNMuJwxBHGS8wOPgf4wAiTXgzuI2xTl4rs9/iX X-Received: by 2002:aa7:c515:: with SMTP id o21mr69490037edq.2.1563948727547; Tue, 23 Jul 2019 23:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948727; cv=none; d=google.com; s=arc-20160816; b=m2rg5F2nyfB6moGotAn2P0dfB6Z8gkDjUzrA3DugMfRn23D1MwL6ihzV8T/slVuOtD Afn/SXpK3r6Ru96zzmy+fO49IBvQ/AOVnlM0VKcqVKj229WnS+D8Tmrz6lklIs4P53jq XJ6Fm1jhB9LYQDoJmNTPpwcZdZ6Syq2OjUQaISvcBmRmwLxDg6EG1YOGEWIEBzD4s6dZ 7ZlusfVLbIaoRwNwy171fcvzlalFqCRxK+PXar/U93S/wn6diO6dbq6NfZ2Be33/HRXa Oe5DWQzBeEj/3o0ufEVj8muHqt2nDZ2uiZQ6HwcDi4NxJBY3sP2qTeJLX+ZGmUaiRrLZ nqXQ== 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=66FrIHCi/FwU5Qd+YH0GklxRIkE/On5h0rf1MXh1DUQ=; b=hv3wbdKxpSm9ztL39auxMc6uqDqFLHynE0+ROwqUoolzpYW+vZ1+b7QUjM5O3sYPPV eTd0ZPG7HkyKnlliDZcOn/UUBS1zjgpNvNBAQH5wjms+1UZGVMshzee0xFFrwb9nBtFU 5t4Z7iRvX9cjp4waMOUBT2N9bmwx3EGG88qnUmrZkjuRiMZBgr/dtSYb8+bf4uOSXlLl PxxnIMDIgp4AVb9PO0QZYRZZHcl4tdpA+pg5oPlNhbcpjUeQt9tqWl2KQKOPkzZsrNJU 3w273nnZHIwheFLwKgMyEhbsSMvJIFM8L7CADNU8uLSA357qHqGVrYFa07p1NS7x4pb6 YdeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.178.231 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay11.mail.gandi.net (relay11.mail.gandi.net. [217.70.178.231]) by mx.google.com with ESMTPS id o47si7916841edc.347.2019.07.23.23.12.07 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:12:07 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.178.231 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.178.231; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.178.231 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 8BB91100006; Wed, 24 Jul 2019 06:12:01 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 12/14] mips: Replace arch specific way to determine 32bit task with generic version Date: Wed, 24 Jul 2019 01:58:48 -0400 Message-Id: <20190724055850.6232-13-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 Reviewed-by: Kees Cook --- 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 faa5aa615389..d4eafbb82789 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; else rnd = rnd & SZ_1G; From patchwork Wed Jul 24 05:58:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11056111 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 0170B912 for ; Wed, 24 Jul 2019 06:13:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E73EA2876D for ; Wed, 24 Jul 2019 06:13:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB2C028774; Wed, 24 Jul 2019 06:13:18 +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 45CCC28770 for ; Wed, 24 Jul 2019 06:13:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FD788E0003; Wed, 24 Jul 2019 02:13:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7AD3F8E0002; Wed, 24 Jul 2019 02:13:16 -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 676728E0003; Wed, 24 Jul 2019 02:13:16 -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 184F58E0002 for ; Wed, 24 Jul 2019 02:13:16 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id l14so29575889edw.20 for ; Tue, 23 Jul 2019 23:13:16 -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=zyv+XJvJ1FwKHFRrkDLBBcNr7tq2Zz+12CeKSwBBCmo=; b=YuOLglvtm2+tGW0NLdyADX3SaR2UjZNLVQ4W2UbOpgPILsc0niUq1Gpa+2tlHinbnn Ce2vQJNYrxoAJWlSz+PBAy7707+4YGNl9qEaD5Dz/hBSC6SGjv0OAh2KOYStHBgSSr3H ZcYMsNYcsIRy58qvAZyXYjZ6xj0kna+YCnw1qXl4IvGEYD/XYzxMVPlThoObom46dO2x 8pDNWcDrGW34ERiZE+jhG68i8zGfpRpeCyx8zGvXFkuL27G51Ccr2n/O/UzOhw9olqkK 0HtyBKzt2hawaNjryjrAQ8bsLcZBleijXXjBAh499MKTMVhW9Gbgr7vPOcjThv517wNS f11A== 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: APjAAAWPuACbDfnWyc84yzThQUSQhwOSOFoOZyDpsOL2qznLgLdqSTEh BzwLllW+I6KmQTmgHoyvUtKGUJfX1mhnBShAx+ra2YEC+IEbIOYhnerbrBmS1aFxObyZHfv05x2 3vS6/uIhxVuaFIKRt/Ypb93/FUGAlKtyt3A/oWt1ujkraDg8Tih3Dt8OrAB0WvDs= X-Received: by 2002:a17:906:5c4e:: with SMTP id c14mr59356642ejr.73.1563948795656; Tue, 23 Jul 2019 23:13:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOHiWRrppU83y2cYkCeUVQjClO7A3AvFp1ji2VAwRd2pQwtMOtaJhucBqVUPw3Yl7UX1v0 X-Received: by 2002:a17:906:5c4e:: with SMTP id c14mr59356583ejr.73.1563948794330; Tue, 23 Jul 2019 23:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948794; cv=none; d=google.com; s=arc-20160816; b=a/CknjJIdUvgFMidH0gwVINzADxHeI9K2FvwwOBWUzGs7uqKwUGBW8giNJBcidUakZ FrFRqPOlG2Dtl3qFi8u0Jy52CIzi4irOiqUSrkqslmZd2uVM3buBo5d+VwadrRjNHp3a BckSvCnLxNdjQR9G9cMonPdhSQR0iMhvB0BrYVU7cPOlLGAlFtbPeeUnnXiIOIWLwWqF 9JCPESEI1oN2v9GWwbNXFO0cm2NpVSdfW4SFrVgqOyIw2qXGKmsKGQ7766WyGGggNgSV 0JGF7xbunfoFkMXDhdyL/XwPprffSfYtLPTETOcZ1xjKwxqMLop+eAsp5/nJKYgv68wE YX2A== 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=zyv+XJvJ1FwKHFRrkDLBBcNr7tq2Zz+12CeKSwBBCmo=; b=ZlNSbDjvXWWDEtJqT4toaKLF3Infn5xU+mn1unuKYqY0PSAunZg760m0xNowR+BwGx vJnelB1jQxPdb62jyGBOAchpPZZXcyQzQklcEykHodv/mpxOrlv0pehofLxHUFb6Bdzn dxt5Gw5HxN3GqT4t9y94H5MPe1Vks/fb96UdWOK32uEvpAqibKDAc93IZbVXA5qiyv4V 2fR7f/iOl/b5l2DzfF8D+Um0DtI4kMzfWD15Y0vxD0BAvhyMoitIDkkV9AzL+iI+suAa Fvc3iOn457+9EYeRB+ZUF7j88nB+dneLYzMy8+o0jEOcJNufCUNkIDg1BnSbt5ir9Hd4 XHMw== 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 x7si8247471edm.177.2019.07.23.23.13.14 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:13:14 -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 4285B20005; Wed, 24 Jul 2019 06:13:08 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 13/14] mips: Use generic mmap top-down layout and brk randomization Date: Wed, 24 Jul 2019 01:58:49 -0400 Message-Id: <20190724055850.6232-14-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 Reviewed-by: Kees Cook --- 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 d4eafbb82789..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; - else - rnd = rnd & SZ_1G; - - 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 Wed Jul 24 05:58:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 11056119 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 621111399 for ; Wed, 24 Jul 2019 06:14:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 509702876D for ; Wed, 24 Jul 2019 06:14:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40DA528774; Wed, 24 Jul 2019 06:14:22 +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 AA1502876D for ; Wed, 24 Jul 2019 06:14:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3FDA8E0005; Wed, 24 Jul 2019 02:14:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DEF528E0002; Wed, 24 Jul 2019 02:14:20 -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 CB7E78E0005; Wed, 24 Jul 2019 02:14:20 -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 7D0528E0002 for ; Wed, 24 Jul 2019 02:14:20 -0400 (EDT) Received: by mail-ed1-f70.google.com with SMTP id e9so18441693edv.18 for ; Tue, 23 Jul 2019 23:14:20 -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=KNvQCbzGXI/XoQciu2chauD/yJmJpreVXpqKbZidQGg=; b=RSq0cTMYPyzEap1TNK9LKlmUpSsWEggq5M97iLxTNzZECNMnwTvGv1QvxnWHDiq+my rl/YUef5N7qswiNbsgb2jKxRllvIWA3A2QKUSZ7VBs7EzeVt8eiRYS3q/jnHqFtM5+3Y 3Fpr0vPR7UZveByf5NeQTxIUk2qpFI2dmzm9DL4j9eZH1JQRkCl/wg1p3fMIr1DEC1BM 8PIoO9vdFSkYG5j9BFYWXPoHMzZn+DbE7lkoU4CoB0ohvnGjSiFT/JkBkTMEJ+QYEsCz OMbUaYGpPE1jNqhl629XX7ODL3GkW4UkN17cXY3T1fEsk3XMTGRnnnpQ5lu5RpQ6O+kb U7HQ== 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: APjAAAX0FO+0P4fwl/hfDc/sq/jbNVXfufCZ7XPhLucHPdM4PWtYy4bH 5gEXaOUG467ELN2LDfyEAi6eveYSFTiYVLh7svn2Vsj26STyzPpS76yEaZ7k5D91m+3wVrm2mGU eLgauKiwZfYWS8vrlT2vfd3LKQKqahwkWhPVZJlXq44ON/bUJY7GNz+Z43DEci7I= X-Received: by 2002:a17:906:27c7:: with SMTP id k7mr61522881ejc.91.1563948860086; Tue, 23 Jul 2019 23:14:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxfd64nXQ1CO5yoXY3vUD9KBPb/TzoX+cdrx09+RZ017StIg7uwLbPt1++OhE7+pZwHVIdi X-Received: by 2002:a17:906:27c7:: with SMTP id k7mr61522836ejc.91.1563948859203; Tue, 23 Jul 2019 23:14:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563948859; cv=none; d=google.com; s=arc-20160816; b=EOGkim58hskW0gje9yINcxamLy0oshpJm+NZaA0j7FLHyJD4AVAi5qcK/wzMOMh0pm m4ELDzd71CsYxrtKqh9fGmIcyfRxPlD+bjVcdJrVkIczZXnJrkSwWFPen6ejUHe+ubWH /pg4GabU7nqRNKIGvtY5p4RsRxuaLKvdo67m1sL1TGV2EGRxNVrwcS45yZSPa2atLq5P PMnUH5vyOg9LWUfO5bv4HAHBMJkhqDwDSTEAl7V4TrJpwMxsNMlcb5V64qjdcvhxkl+M DYR+tuXs4dzCKP7TW8p/Oc+X0ksOQYwQqwNtOdT0lgWH1LmaYeSpdWoXcyg0g+Rfvjxy whsw== 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=KNvQCbzGXI/XoQciu2chauD/yJmJpreVXpqKbZidQGg=; b=AoJzaeoGRkH6zAGeGDksNPbfLbbGlUL09/dapC+M3I1MhW8cZk2tbsFM+PYQ5XlCkP IA8c5GUmqTF3tcHvJifBJmXuJqa+0VgUrx4PJU1IYFwmEIXivMsvjc09U6nGexrnkTaS npR3Ot2GnuV1v5vWs8KKCGRipx2VIbf+y5iCpJFbucEw4PmkdvrpMsa7agoBhFVUtXx+ 0kYT8DDsz/lWFVLKWqvnV7I6k8yJWUZ0zjAXVSL1J837ovXkD64R+1JZCxI+XGYC9otW wQ1+ZGRC++KlDQ0qpDElb0TUftLqBesK1/1OE+NjpRtgwsaYoyJcBbNLdCXZYoMmIhAH xxHg== 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 z2si8764419edz.118.2019.07.23.23.14.19 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2019 23:14:19 -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 D50ADE0004; Wed, 24 Jul 2019 06:14:14 +0000 (UTC) From: Alexandre Ghiti To: Andrew Morton Cc: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , 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 REBASE v4 14/14] riscv: Make mmap allocation top-down by default Date: Wed, 24 Jul 2019 01:58:50 -0400 Message-Id: <20190724055850.6232-15-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724055850.6232-1-alex@ghiti.fr> References: <20190724055850.6232-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 --- arch/riscv/Kconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 59a4727ecd6c..6a63973873fd 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -54,6 +54,17 @@ 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 + +# max bits determined by the following formula: +# VA_BITS - PAGE_SHIFT - 3 +config ARCH_MMAP_RND_BITS_MAX + default 33 if 64BIT # SV48 based + default 18 config MMU def_bool y