Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3394474ybp; Sun, 6 Oct 2019 10:59:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNgEU0mfG6V/qLcgNiI9OSFZHYDnZ+hbSV32Xb3o3LihviS4eoEtgwn+ER9pNcglJ5l9rg X-Received: by 2002:a05:6402:1549:: with SMTP id p9mr25737037edx.221.1570384786572; Sun, 06 Oct 2019 10:59:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570384786; cv=none; d=google.com; s=arc-20160816; b=CHkAgB5WGJOIVc3AZf26wOIOm+1fB6BAf30xS8v3vwh/S6p38a1M6UYdv4/IbFR2rg RmxQghFUWIaOF3QVAJ3KcACVDKXPbzJDm/mHxdlGdYejC5tpMzCb4rDIlpPOPQAWdllH GaK+UYuWvCAIkdgyWs3WmgUdFVThHDW1hjWQCTPrwrM8meArqzmK5NJsxeOYJLgb6fbp Cp+A9EVd7IdrmX2Ej4loN7e0DWbyo0yhY9jUzepXe17RVI/tTDooCvxNtzZagnF3+xRx 1WfoMvRCpEBm2XmLkF3kcItAPUlKu1gfT2OBMXaBE31cnLnkHTDkFCx7pjU/sn+0L/mw TqkQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=T3pvMjIa/0H4Ku6SteXDYFQ41SOYNPYilS5M3I9r+MM=; b=IA/1bm05EpkvweviacZqU9U0FiqQhdaN1oTXwRmCsWZ0edCS3bIXBHmt/L+EVxOZ0I mlDpKT64/aZU8Ur1AY3a6UlbDpyzl/Z07c2Cuznkl1oZu6t4XKmD8nIAYOe4cA5p/UWU UigqHoXFKEqXuCzCsV+dsMZJqK98sTwEtcpMeh2gCqvQf2ui/dcRG9RExcAH/9qR+vDP USKDEU35peiuaz6XuwBqJhLTBUCbwDwtL6buq6PRrX2RrbOnqO4peuJ6Xl2es8B445hx r26dDWG6hn8vFZ5KkZKj/D93CsnY0MUkbIJFfR2PukSuawL+DDoG2S9MdN1P1rRMkzJo KVfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xFtwYTWR; 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 b33si7641496edc.265.2019.10.06.10.59.23; Sun, 06 Oct 2019 10:59:46 -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=@kernel.org header.s=default header.b=xFtwYTWR; 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 S1727952AbfJFR7H (ORCPT + 99 others); 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