Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6789489ybi; Wed, 29 May 2019 13:13:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqybFlRcQtk5ZV55UphkgBiRyGLfswqOSV3xhaZCA9w/o49nqlN/K86ZGrB17XMfvP5YQT7s X-Received: by 2002:a17:902:3183:: with SMTP id x3mr40498301plb.321.1559160785457; Wed, 29 May 2019 13:13:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559160785; cv=none; d=google.com; s=arc-20160816; b=ZPyfO7TW8NQYzKiN6tdHFWp3t/fgNNfA6I5kf+TD1pRHkwvAUOfDeFGtC8BfYkpg7P t53pnZpvaPcCXJeRnwqy0gPOPdJ7IbQ9Chp6ybF/gcEAxzDWvwTDTUJEywcw6+p0GZ0I NZEAVkhB0amWb/qcdF6Jya60CW95iI1eKKrdOTMQ3ZHuK+b0yOGxEQobedRMaRGmzHCs eAkfikiv9MqOJE/u3x1hrc0b5viTugEWIFPmWkFu1ROkdWpLqfYrqyQlod0DYiHSQ0iY U1VInG1Gg6N9AnorFYFtC3h1Mz6QPLdBgnUiZ5aFJYIIYd+h45O2XFhsJTlC5k8ah43e KJPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=l4laiGZ+6EAxTzYgyOLxq6AQ0ebW5F8MPaRp0yaenB4=; b=ulsQXkk5s3S/u4jcb+SOJ0+xT8e6IOA15hyQ8pcYsnkTjdxAWUjMSaHcdHJwVaAdQ2 hxgw7zAVnquMJuLQqi0P0HdFhIZlW5+ylh9pry9IrwRutCE62fmY9DPxhindBny5j9Jz N6uEczQJQYFj1wTYe3CCQ3YLiZe2Fucpf7yMhFLMAe1lprMOoif91oxoin3e/Jfl150J mAhJxncu7bHXdDCEvzCz7hL0BHCmb29Uj7Mgeoquf7DQUkEAZheyWKK54oAiJ+2f2oak 6/0eoE/dDaE9AQEp+QTLPsMEdwZMtiUoQVfIfuXfUfdpO3LY0KIHrs5m/ZnCCXb1QM1V g9/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=T+S4dzKk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c9si746578pgp.39.2019.05.29.13.12.44; Wed, 29 May 2019 13:13:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=T+S4dzKk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726470AbfE2UKx (ORCPT + 99 others); Wed, 29 May 2019 16:10:53 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45436 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726224AbfE2UKx (ORCPT ); Wed, 29 May 2019 16:10:53 -0400 Received: by mail-pf1-f196.google.com with SMTP id s11so2321142pfm.12 for ; Wed, 29 May 2019 13:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=l4laiGZ+6EAxTzYgyOLxq6AQ0ebW5F8MPaRp0yaenB4=; b=T+S4dzKkP0QeUP0gvmQYme6HE9FvwMG4qznuFtH/nyALnyYufIZl5Zude490BxgiIt TM/MxYm5xSz69G1obZoGJM1LDIeY9X8HJLMu8K1/UHH+gmEEyXz0iVgKFgUxlRbExavm GdYNYHEiXPSCZWG+4ftE4ubEET85V+Ow68jzY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=l4laiGZ+6EAxTzYgyOLxq6AQ0ebW5F8MPaRp0yaenB4=; b=Dv3IEKC/VLbHTd2olrX6eYG8LAKLUnOu6pQ0578IhFA7tnBzgas09HKe1Fp8HT7WV5 wOmXhzkLKmrfaTOW8PxVrmJ3G1VO7ZnUeBYeofpObvl1iWA7gInQeQoREMyi4r2/bRuL LMKp2EZWt6ky1D/5XoalNguaskg37YDbQYKnNr9qmbKCf2I25W4IVtg9ga1Bx1OnIFtv FXgLMfOb2Fi/Eo1UC+pinTqEaBxU/yQpRyjszyAFvcPYVzp1KP7rTYWqg9yEn94TTbGI o5fFQQznf6PN1h/siIJYpQKTGnMd4Izj9a4+2i2g3hdD4ti/04UJXk+kjUISdk4/BuUT KlCw== X-Gm-Message-State: APjAAAUihI794XrsTOMYYFLczadzTiFwAosaEH4yyEexeW7MqiYtYpR6 s3mXR0QtZhBdcgYDV72PVJyRNQ== X-Received: by 2002:a63:6c83:: with SMTP id h125mr92843035pgc.86.1559160652464; Wed, 29 May 2019 13:10:52 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id o2sm216631pgq.50.2019.05.29.13.10.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 May 2019 13:10:51 -0700 (PDT) Date: Wed, 29 May 2019 13:10:50 -0700 From: Kees Cook 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 , 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 Subject: Re: [PATCH v4 05/14] arm64, mm: Make randomization selected by generic topdown mmap layout Message-ID: <201905291310.E27265DACF@keescook> References: <20190526134746.9315-1-alex@ghiti.fr> <20190526134746.9315-6-alex@ghiti.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190526134746.9315-6-alex@ghiti.fr> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 26, 2019 at 09:47:37AM -0400, Alexandre Ghiti wrote: > 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: Kees Cook -Kees > --- > 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 df3ab04270fa..3732654446cc 100644 > --- a/arch/Kconfig > +++ b/arch/Kconfig > @@ -710,6 +710,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 3d754c19c11e..403bd3fffdbc 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -15,7 +15,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 3767fb21a5b8..3f85f8f2d665 100644 > --- a/arch/arm64/kernel/process.c > +++ b/arch/arm64/kernel/process.c > @@ -535,14 +535,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 717f5d75c16e..8a38126edc74 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -319,7 +319,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; > @@ -333,7 +341,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) > { > -- > 2.20.1 > -- Kees Cook