Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp192030yba; Wed, 17 Apr 2019 22:50:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxyWG35+294mulVDd5d52/WA4FGsnOlgC2Nzgzsp5dtmTrgv8JkqjAir9lkFLr1dZhwQRAv X-Received: by 2002:a65:5682:: with SMTP id v2mr88080298pgs.100.1555566605199; Wed, 17 Apr 2019 22:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555566605; cv=none; d=google.com; s=arc-20160816; b=QbAqQs72gPZ1bXPGpILCDrU7gvd3gJIy60/Mii8SAjn16UFz1y4AnPCFUkOxyjQk3G cg2c7LJYOs34ys3lhvmNKwsVj9kDbjQtRZZAGCZwsysRd1dRJpzu6Py1k8iqyyiUVjc0 JKFzv6EXMHjjjXee/lzeRaLL5fxhUoi6Alo+3tmC4y/PbcDVEEpGM9b1rP9LRC36+hh3 xaEWdor+jWV7xKTkpPvQno8asuhVuOpTvBVQVAIemt9gAaE/V9BMXAfQvORCje3yXwCP nnlHiCLzoplUAwKEw4eyWbhci0pIGVrv4MHAfdWDIi3+Fw3AcFPNZCNFqSUO3KiQlYKL Lq1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=QVoqbwyN443Uxffv4ADeYKBc3zmgcqP5SCaKkpPU0Ag=; b=rIcaAUdTujsXKSdNxobCjZIZZ0TH6QpH/b5Fl1COLLIXlt0DiKE2JXK/XF3zVVE2FT oeqTrq1UPhuU+gAacXxZcEy/eEZ9HSB/4LV/ybGzeuGK+SyNBN9hGUQxa0cTsavYMCVt UqpQfalL56tF+R53CsLnk+/6Pkzos5uXuhvnQecd715QDTLYVXR525avcLx7gL9ywsiW yTD60dspF4kozncWlwcs1yaLvKBjcVBEa7ej6wO1SszDmQAmPoxmgsu5GEopGHZ8ZEHd 6JK6oIQAQXURsrMnAq7Ws/xmT9zwjXAQG81X/OoWwWSMgDJ3NGTMwBh5pQ0CfQpxaGgM KlXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JlYc5LnY; 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 h8si967372pgp.446.2019.04.17.22.49.48; Wed, 17 Apr 2019 22:50: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=JlYc5LnY; 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 S1730285AbfDRFsx (ORCPT + 99 others); Thu, 18 Apr 2019 01:48:53 -0400 Received: from mail-vk1-f194.google.com ([209.85.221.194]:44603 "EHLO mail-vk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbfDRFsx (ORCPT ); Thu, 18 Apr 2019 01:48:53 -0400 Received: by mail-vk1-f194.google.com with SMTP id q189so213314vkq.11 for ; Wed, 17 Apr 2019 22:48:52 -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=QVoqbwyN443Uxffv4ADeYKBc3zmgcqP5SCaKkpPU0Ag=; b=JlYc5LnYPCwWgX5oqj7ynsTkg9HwSCKe5lZ5zN605L7Uvo1glCbNDCtQfk8GyTRI13 ROZ9wJjLihPw49RRrvvr1sPQAGB3Bk/uVz5KXlTfPr4zLd1Qk3TnxysN1P6IizUWSim9 CZommiTKB0IOC+Nf2V/4WJTnJI7JYYMqf0DOY= 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=QVoqbwyN443Uxffv4ADeYKBc3zmgcqP5SCaKkpPU0Ag=; b=ClxACI+zlfQc+yy6y0l8RtibqyVvwvCK6BMENyP33Rz0bqX0nlfQ0Ows7JtVeEhWyq clhPSiX7hdUWjXvICJe4nOMw5MCBqDNtsy3lb3nh1jGPA5TKBSOvLP5+PtX1c4YEy7+Z v8z5dkYBw5qekGRVGzsvQQZndyHGaFi6ydhubny+mYmmNmwlxUeseRf9KVUzeGrZACX4 zDRc/m7XMs/cYrLJVAX7OOL0slaMgbrwklqvGGlnjwc9RMS1mFO5LRoohxBTcvpUdb2B xvZ2p39vLyGTxHKsIQqsmf8IKRJ9yKx1CP5SSySdgtCdPq697JjRbgMlf9KLjxmfs86w MNHA== X-Gm-Message-State: APjAAAUfbHUdMnJcy6z3hNX6XZIGaqjiwHlfSMi/maqnWB74uP0zpCqF 7W9nAXAVo6CMs8J7P6Ao8NcXzJ7yS0s= X-Received: by 2002:a1f:a0d2:: with SMTP id j201mr51053656vke.37.1555566531894; Wed, 17 Apr 2019 22:48:51 -0700 (PDT) Received: from mail-vs1-f42.google.com (mail-vs1-f42.google.com. [209.85.217.42]) by smtp.gmail.com with ESMTPSA id q203sm337455vkq.43.2019.04.17.22.48.51 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 22:48:51 -0700 (PDT) Received: by mail-vs1-f42.google.com with SMTP id f15so518367vsk.9 for ; Wed, 17 Apr 2019 22:48:51 -0700 (PDT) X-Received: by 2002:a67:eecb:: with SMTP id o11mr50384241vsp.66.1555565182826; Wed, 17 Apr 2019 22:26:22 -0700 (PDT) MIME-Version: 1.0 References: <20190417052247.17809-1-alex@ghiti.fr> <20190417052247.17809-6-alex@ghiti.fr> In-Reply-To: <20190417052247.17809-6-alex@ghiti.fr> From: Kees Cook Date: Thu, 18 Apr 2019 00:26:11 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 05/11] arm: Properly account for stack randomization and stack guard gap 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 17, 2019 at 12:28 AM Alexandre Ghiti wrote: > > 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://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1429066.html Please use the official archive instead. This includes headers, linked patches, etc: https://lkml.kernel.org/r/20170622200033.25714-1-riel@redhat.com > Signed-off-by: Alexandre Ghiti > --- > 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)< > /* gap between mmap and stack */ > -#define MIN_GAP (128*1024*1024UL) > -#define MAX_GAP ((TASK_SIZE)/6*5) > +#define MIN_GAP (128*1024*1024UL) Might as well fix this up as SIZE_128M > +#define MAX_GAP ((TASK_SIZE)/6*5) > +#define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT - 12)) STACK_RND_MASK is already defined so you don't need to add it here, yes? > 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; > -- > 2.20.1 > But otherwise, yes: Acked-by: Kees Cook -- Kees Cook