From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F112BC10F0B for ; Thu, 18 Apr 2019 05:21:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B17FF21479 for ; Thu, 18 Apr 2019 05:21:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ZOmVLE2k" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725847AbfDRFVA (ORCPT ); Thu, 18 Apr 2019 01:21:00 -0400 Received: from mail-vk1-f196.google.com ([209.85.221.196]:43884 "EHLO mail-vk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725710AbfDRFU7 (ORCPT ); Thu, 18 Apr 2019 01:20:59 -0400 Received: by mail-vk1-f196.google.com with SMTP id s63so204067vkg.10 for ; Wed, 17 Apr 2019 22:20:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IcA/uYI8DV5Uk3TdhA5fHXy0czTBgFSx6RCoxfz+//4=; b=ZOmVLE2kWQEfxAwJtqNT7fptm5m89yjN9pJ4hwhI4Z8f49vkIG1SsNzihNlPHXzko1 XXEV3xLUvXrMTYVGVNWYLrrCC0hIAZCueqmowWDl/0KTMFCsqx1U+m/G2nteU8eiooyN 6sDfWAdWlsvCPZQuCGxF8OqTfh2ZEPtoetyBA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IcA/uYI8DV5Uk3TdhA5fHXy0czTBgFSx6RCoxfz+//4=; b=F2Br1YgqMgVGwA7BoBdB3MkPV4YOLWdVbAFON0zirHODX3JI2Y985ic2NGK5QH4Hrc xih471EgKNZTNFsnNMH9WoMvB4taF/g1OGTDmpI3wk0vI26wHQhY3O3qvq7Y8sYTHAjr 9q2nF9VltKp96bEKl5Sg6x3ck/SLpFwzXmgs0p3Qp0dMZDPrvJLGI6HH04sbB7DhVqO+ E2uQtiisFs1p5ys2VlPHhV7calti0GDqpILkPT+KTPIfpNJ1JNoWtp0h7wGc1YYEfm+c hGMI2NeI4SicByPXy56R4R8Po4vQHKRVb2J3Bdm1DsZIPa2Az3GHqwMHg1RCy9sMrXJ8 OKyg== X-Gm-Message-State: APjAAAXjhIJywMbcU5Suw+GN++VS7yeys9CI7XQKHuHR1ZJKdUqGJKV0 uewrAZHGnLq8e1WsUHzoXcOZQyCClsM= X-Google-Smtp-Source: APXvYqw+gLaLa8Z7Ji6rxFx16bMT4mtJtmqMs6mPhjPbgKPU6hEunAnFYt1s6hzYKheOU1IFScALzA== X-Received: by 2002:a1f:1d06:: with SMTP id d6mr48792483vkd.82.1555564857811; Wed, 17 Apr 2019 22:20:57 -0700 (PDT) Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com. [209.85.222.53]) by smtp.gmail.com with ESMTPSA id t128sm483819vka.36.2019.04.17.22.20.56 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 22:20:56 -0700 (PDT) Received: by mail-ua1-f53.google.com with SMTP id t15so376532uao.5 for ; Wed, 17 Apr 2019 22:20:56 -0700 (PDT) X-Received: by 2002:a9f:3fce:: with SMTP id m14mr49582984uaj.96.1555564855818; Wed, 17 Apr 2019 22:20:55 -0700 (PDT) MIME-Version: 1.0 References: <20190417052247.17809-1-alex@ghiti.fr> <20190417052247.17809-2-alex@ghiti.fr> In-Reply-To: <20190417052247.17809-2-alex@ghiti.fr> From: Kees Cook Date: Thu, 18 Apr 2019 00:20:44 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 01/11] mm, fs: Move randomize_stack_top from fs to mm To: Alexandre Ghiti Cc: Andrew Morton , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , Kees Cook , LKML , linux-arm-kernel , linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, "linux-fsdevel@vger.kernel.org" , Linux-MM Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Wed, Apr 17, 2019 at 12:24 AM Alexandre Ghiti wrote: > > 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 > --- > 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 7d09d125f148..045f3b29d264 100644 > --- a/fs/binfmt_elf.c > +++ b/fs/binfmt_elf.c > @@ -662,26 +662,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 76769749b5a5..087824a5059f 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -2312,6 +2312,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 d559bde497a9..a54afb9b4faa 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -14,6 +14,8 @@ > #include > #include > #include > +#include > +#include > > #include > > @@ -291,6 +293,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 Oh right, here's the generic one... this should probably just copy arm64's version instead. Then x86 can be tweaked (it uses mmap_is_ia32() instead of is_compat_task() by default, but has a weird override..) Regardless, yes, this is a direct code move: Acked-by: Kees Cook -Kees > + > +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) > { > -- > 2.20.1 > -- Kees Cook