Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2735829ybi; Sun, 26 May 2019 06:56:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwx9lx6GAqzSL7vTIX2qgdzVy+ghamDzdO50kgtGNjQhXQwPw5a2hmH53imN7rcADbJ3mUP X-Received: by 2002:a63:5105:: with SMTP id f5mr103205612pgb.373.1558878977206; Sun, 26 May 2019 06:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558878977; cv=none; d=google.com; s=arc-20160816; b=tftw1wqDsLwxhtdaoGL8yi5Tm+f8U2c95s7PXj9qN+nY5ICin8KsfhQ2iVik/H2/gk 3qweSbCt7dmwLUPPbEgRwHzo3LK4IlhpuNniH8hQ76hC5deTrQLqI3FfrPF+5CEChXSz cPbo/2HgcfpJVLPC0+mnrwvaeVwcRgmvx9e7CalV8Zzhdh4MKINTnRdjortJOJ5dALnr QbQnqwhKeDbL4CmDXJuwhjiTrU3W/ADMdhoYmR1eeCjqERedkIunIpz+UT70PV6qdQwK HkZQOrbN9Qabt7sGpENtI0yPARUi1EcvV0XwZWiqHAIOOq6j/bwrgt9doZAEepjdhsPo hooA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eym0BMHdbArtu9uPr+EyfIeUu2p0S0z5kNpGctDciqY=; b=H9SPYdStbqShB7PSH1FI+I8ri3zlQAxLwF39D8NzMOvyEx5ON6IZESekGXV0VgG87X 9a4HYDAgZmn4ynvWHQo24NKEtF9EeUZy22aR5hTlpEWynsgJVk7/47ZGkHPWqBVvfF0e sCesHGUXbFq3vHwKgy6stgPrj0AaulEqCXnCOp+fJjEyMda2ZFcT5m8LZeQxcbGAukyW l2cRq+hMqalNr2QhHCfG2wrziMvaxuQfLlyr1psQ+pezozScoKDljwYiEtg015E46JFO 4JAsBP/MvCLRpOIdoQ3Egyu2vlojR3YGXpH+TrlRPt9sGGv0NDIcFL8xdH6sG7FnEOFW RQlw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si9751211pgl.298.2019.05.26.06.56.02; Sun, 26 May 2019 06:56:17 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727865AbfEZNy6 (ORCPT + 99 others); Sun, 26 May 2019 09:54:58 -0400 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:47361 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726995AbfEZNy6 (ORCPT ); Sun, 26 May 2019 09:54:58 -0400 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 3D31BFF805; Sun, 26 May 2019 13:54:47 +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 v4 06/14] arm: Properly account for stack randomization and stack guard gap Date: Sun, 26 May 2019 09:47:38 -0400 Message-Id: <20190526134746.9315-7-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190526134746.9315-1-alex@ghiti.fr> References: <20190526134746.9315-1-alex@ghiti.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.20.1