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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 320D3C10F14 for ; Sun, 6 Oct 2019 17:59:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0871A20673 for ; Sun, 6 Oct 2019 17:59:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570384748; bh=YKuU+kYbU+qp3AoO0U64mMtZkgbjNXI03bOyU1hCA+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=azzAXAcNvPKCMzpNU2+Ciep2yAPKPNNIL/A/HVd4A+w0M5yKg0Qff9fgNmrPxuuzM xaApSxD+I4W1KuN1N6jkNC5dDGJvN02thNZZZvQ+v18yIwW2yGxpzC5N4kdfRVFY5p 18PDQGwjRUZoQaKV1wV1KDyAKzRlnfpCSOxlYoyM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728594AbfJFR7H (ORCPT ); Sun, 6 Oct 2019 13:59:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:57308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729365AbfJFRbK (ORCPT ); Sun, 6 Oct 2019 13:31:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 926B42080F; Sun, 6 Oct 2019 17:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383070; bh=YKuU+kYbU+qp3AoO0U64mMtZkgbjNXI03bOyU1hCA+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xFtwYTWR1xAbZjSczLRkSwbcvoWFj6p7H4rcxWRArL10wRAHx92p8bN+7ZtN/5fYT rBzRqSuzhgGnuqUclLV6PMOShk4tjf7WpvHFy3YA5932WlHEa7jtvCcw0y5iFixwW3 1TeTbJ2fIazId3y361UsjlKe5uZD/H1XNtAx1H9c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandre Ghiti , Catalin Marinas , Kees Cook , Christoph Hellwig , Luis Chamberlain , Albert Ou , Alexander Viro , Christoph Hellwig , James Hogan , Palmer Dabbelt , Paul Burton , Ralf Baechle , Russell King , Will Deacon , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 074/106] arm64: consider stack randomization for mmap base only when necessary Date: Sun, 6 Oct 2019 19:21:20 +0200 Message-Id: <20191006171155.088265734@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171124.641144086@linuxfoundation.org> References: <20191006171124.641144086@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexandre Ghiti [ Upstream commit e8d54b62c55ab6201de6d195fc2c276294c1f6ae ] Do not offset mmap base address because of stack randomization if current task does not want randomization. Note that x86 already implements this behaviour. Link: http://lkml.kernel.org/r/20190730055113.23635-4-alex@ghiti.fr Signed-off-by: Alexandre Ghiti Acked-by: Catalin Marinas Acked-by: Kees Cook Reviewed-by: Christoph Hellwig Reviewed-by: Luis Chamberlain Cc: Albert Ou Cc: Alexander Viro Cc: Christoph Hellwig Cc: James Hogan Cc: Palmer Dabbelt Cc: Paul Burton Cc: Ralf Baechle Cc: Russell King Cc: Will Deacon Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- 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 842c8a5fcd53c..157f2caa13516 100644 --- a/arch/arm64/mm/mmap.c +++ b/arch/arm64/mm/mmap.c @@ -65,7 +65,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) -- 2.20.1