Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3858735yba; Tue, 16 Apr 2019 22:29:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqzNfDN4fsLWUxPo0ke2UyCWsbm5KyJzR6+4sizcUH0F/k2PLT4Mmu+oUTY0GLYGnQhFe7X6 X-Received: by 2002:a65:4846:: with SMTP id i6mr82628590pgs.132.1555478987912; Tue, 16 Apr 2019 22:29:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555478987; cv=none; d=google.com; s=arc-20160816; b=TAZjPejpjcOx+FEperR8PQmy6vEkp8ykvGNNtLlLjf9/wb+2bJafN1OFFhZSmmBi/m k7MODwxfYd9wO9321eO9zT/WrUl/Vj16SWTrjjhWtBWFZazoFqnd9J5RW5Gn1fVHbJar ItPyLzhbLRIJRoPKKZiY7Nj6isuGbOjwavffZTWF0VRFWARahaqkgEhGgGzZeDaVg47t MPY8dbbI+Sq56KawXI97GYorwlt8Ri88UoHVb3b75SaxgHjnEsuAXLNYnVUUFcZdYj41 tr/iSnlSSquwG+UKN4BCLcV+HqoGq+54ChaxJVHT4Y7R1t35YorijBotRkU7ouC5gKRP 0lQw== 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=akQS/yG8sPhImfKfbdP4IgmJO6rV8gx2SpQpdbx2UzQ=; b=qCqKHCJYmo1KK+3Q8k5tq4xUelfCEexWg59NIoyNyftPB4yG1Z0szex/0tEFF3cx1j 5jYvx9LOf6BVdJ4UWGr2tap9THTyb8fHx7BDiYgg4lRwVAuRf9AYf6rad2B4/zaYmArF SAvwjPNyRKC9Cd6/qPxm4WOJNWddDvhPmvRWj5n6nIzOcbnrUY6WHKvl5pFXYPdFnhTg bn8TRx/gYNymZPgRz0s7Fz4CXrb1kkqxibCm0mskjbNXKwSRfFT5lnBnu4G/8HF3XISE K8JwlT7Qo33BFbftEn4+EMH9KFmY3ztyF9QAvZgDKLsvYO/VRRHbGZywxvbDZsW+zAAR Qn3w== 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 z127si51993324pfb.254.2019.04.16.22.29.32; Tue, 16 Apr 2019 22:29:47 -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 S1730326AbfDQF20 (ORCPT + 99 others); Wed, 17 Apr 2019 01:28:26 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:58113 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727340AbfDQF20 (ORCPT ); Wed, 17 Apr 2019 01:28:26 -0400 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 3A2E6200008; Wed, 17 Apr 2019 05:28:18 +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 v3 05/11] arm: Properly account for stack randomization and stack guard gap Date: Wed, 17 Apr 2019 01:22:41 -0400 Message-Id: <20190417052247.17809-6-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190417052247.17809-1-alex@ghiti.fr> References: <20190417052247.17809-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://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1429066.html 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)<> (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