Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2095494yba; Fri, 19 Apr 2019 12:02:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqyXJyu8soFNEJiqJowNEplJzcps172haWxq9AcgTpUwRseIX7Zbe/fBK2CA9ov3INEqhE4R X-Received: by 2002:a63:7d0a:: with SMTP id y10mr5347792pgc.292.1555700569784; Fri, 19 Apr 2019 12:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555700569; cv=none; d=google.com; s=arc-20160816; b=A0FqSWZBOvqGWnvDpq6HdnHpGE20zBU3h43s+yN3owXUf0a1dHFVdRVYYIKw5iPgX5 /CxEHsf/fPcCRb75Dp9ZbPw8Kh4Iu9wAf+CrQ8TiQwANIRpUEDsSUm6H6zWwexzuz5Jk 9sf7Spo2oD9tLIbBA8c3hKEbvPmFnbeAPhf4dMZ/icuc2Y7NIAmP89eSII6WfnuLIitN 0AXROQSXxMk1AFiQyqJ/mi4Gwhg65RzJRj2oLyaNqdyHYPbyaE5Ua5RDscnl6lk0wYm1 hTLRmJoldUks9Oe3frJ5UDXmSFUTHRLCQaasFGDjWVXWutUxk75JUfstGSRxBrVodWl7 b/pA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from; bh=bnQSy0WtCB7Cu0qsokQqvclK8aEJwCrIiNI51qlDWjY=; b=k17AUUKHBIbelvwHctp0jj4vN6EvCHHxHdsn5HfsV9HNXrICNP7QaqB9/JAGb+aR19 l7QzSXT2NkKtwrhP+/yCECFR+sZBpu9xlX4zAgFhnZcxaRJzL1XLMa/G88legVYA4ta6 QB7LLNC6iUNkZmhYBM2i2BJ2E6eR53zV7N1CaX3VjKY0v7Ac9SHLYUISpMPmYMiz9Oet O7wxgojPWxaTpxe4haRC7HhN/JMwswaj6t2hLiAWSjFTSnJeruZAK747TZGYaxUyarVP 0+Sucb3xXukqCGb+MbZ8pZrIQH1ACMw0HQgUlDLwINYMoWbRg9IMTTjOPiJEGn4CFnZM GY8A== 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 s22si470067plr.89.2019.04.19.12.02.34; Fri, 19 Apr 2019 12:02:49 -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 S1728835AbfDSTBL (ORCPT + 99 others); Fri, 19 Apr 2019 15:01:11 -0400 Received: from mslow2.mail.gandi.net ([217.70.178.242]:38222 "EHLO mslow2.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727676AbfDSTBK (ORCPT ); Fri, 19 Apr 2019 15:01:10 -0400 X-Greylist: delayed 825 seconds by postgrey-1.27 at vger.kernel.org; Fri, 19 Apr 2019 15:01:08 EDT Received: from relay3-d.mail.gandi.net (unknown [217.70.183.195]) by mslow2.mail.gandi.net (Postfix) with ESMTP id 6DE5E3A913B; Fri, 19 Apr 2019 07:21:23 +0000 (UTC) X-Originating-IP: 81.250.144.103 Received: from [10.30.1.20] (lneuilly-657-1-5-103.w81-250.abo.wanadoo.fr [81.250.144.103]) (Authenticated sender: alex@ghiti.fr) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 78D2F6000E; Fri, 19 Apr 2019 07:21:16 +0000 (UTC) From: Alex Ghiti Subject: Re: [PATCH v3 08/11] mips: Properly account for stack randomization and stack guard gap To: Paul Burton Cc: Albert Ou , Kees Cook , Catalin Marinas , Palmer Dabbelt , Will Deacon , Russell King , Ralf Baechle , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , Luis Chamberlain , "linux-riscv@lists.infradead.org" , Alexander Viro , James Hogan , "linux-fsdevel@vger.kernel.org" , Andrew Morton , "linux-mips@vger.kernel.org" , Christoph Hellwig , "linux-arm-kernel@lists.infradead.org" References: <20190417052247.17809-1-alex@ghiti.fr> <20190417052247.17809-9-alex@ghiti.fr> <20190418212701.dpymnwuki3g7rox2@pburton-laptop> Message-ID: Date: Fri, 19 Apr 2019 09:20:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20190418212701.dpymnwuki3g7rox2@pburton-laptop> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: fr Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/18/19 5:27 PM, Paul Burton wrote: > Hi Alexandre, > > On Wed, Apr 17, 2019 at 01:22:44AM -0400, 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 mips here: >> https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1429066.html >> >> Signed-off-by: Alexandre Ghiti > For patches 8-10: > > Acked-by: Paul Burton > > Thanks for improving this, Thank you for your time, Alex > Paul > >> --- >> arch/mips/mm/mmap.c | 14 ++++++++++++-- >> 1 file changed, 12 insertions(+), 2 deletions(-) >> >> diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c >> index 2f616ebeb7e0..3ff82c6f7e24 100644 >> --- a/arch/mips/mm/mmap.c >> +++ b/arch/mips/mm/mmap.c >> @@ -21,8 +21,9 @@ unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */ >> EXPORT_SYMBOL(shm_align_mask); >> >> /* gap between mmap and stack */ >> -#define MIN_GAP (128*1024*1024UL) >> -#define MAX_GAP ((TASK_SIZE)/6*5) >> +#define MIN_GAP (128*1024*1024UL) >> +#define MAX_GAP ((TASK_SIZE)/6*5) >> +#define STACK_RND_MASK (0x7ff >> (PAGE_SHIFT - 12)) >> >> static int mmap_is_legacy(struct rlimit *rlim_stack) >> { >> @@ -38,6 +39,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 >> > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv