Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp77506ybl; Fri, 9 Aug 2019 02:47:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqztW9lsDst+wDJe+fTcMzGT2aNQRmRqnWiyNHKOESfLRkh3JIE2ygpHqQOx1PNNwrCbutXn X-Received: by 2002:a65:44cc:: with SMTP id g12mr16478481pgs.409.1565344052642; Fri, 09 Aug 2019 02:47:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565344052; cv=none; d=google.com; s=arc-20160816; b=viTI49dUI2SMUnZ8sGazIKDcUQyzvTE0Mqrn4pbYX/GYB5YhJ+tJYiDHDgBbRqa61a dhPGti+ACxcMjLRG0VB0BHQfCnRSR4JT7ckalcw+lQDV2ms9VpQeOsOiX/oBRnGNl9y3 t+r6JCxTjMVzZR2pTGAE4J2dLi5k2ejKex2Cuu2V+Ds1iL9YzVYAfoIsyei75HAs+te+ qNb+nUkzYU3m34B2magpxCzGVaDcSD+5wGjqmUg1qEaQRTdaIba+QSWhrmdOeRox0c1G zl2iuBZl2KbjVMYFXjseoBSeLU1S5optBqc66eLWMDA1xorkbad1Ft+p0mzVSvNXGig5 gGxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=7Zz+dekQVz+t60cfPAWXHDt673zqelsbIxrG4v8rxXU=; b=ZBhNWbhpv+WeuBZsDzI1f7UVl2FmHdFGWuRITXuw2EjmzhXBloxM9mT4z5XQsVBwZU jKh3GWRFezjPslxjIPIg2vvGcJLjFfxKeu4VNjDZ/v687+OYwGDkZ/HAHyKBw1l6JvXr gIUuCP6GlOSR0Wb+HimaUg9taK0ArmfVWr4d/65IkFHAoWZ4g/z1FD6hwS7mH8RcNIIs BDbs1ql60VMtPW0T2COQrcqbvaapdHVpEBtAlZLZjJufBVhnh5ZSE+lneAClBn0AS0G1 +6uWkzN9bB5raWIu7t4kLDRDbd+YBP+r9QYfgvHiZejwqofNDhpwG5wNBzazrGr5BjwJ tbCw== 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 h65si57097960pfe.216.2019.08.09.02.47.16; Fri, 09 Aug 2019 02:47:32 -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 S2406077AbfHIJoq (ORCPT + 99 others); Fri, 9 Aug 2019 05:44:46 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:34063 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730233AbfHIJop (ORCPT ); Fri, 9 Aug 2019 05:44:45 -0400 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 5865C6000D; Fri, 9 Aug 2019 09:44:39 +0000 (UTC) Subject: Re: [PATCH v6 09/14] mips: Properly account for stack randomization and stack guard gap To: Sergei Shtylyov , Andrew Morton Cc: Albert Ou , Kees Cook , linux-mm@kvack.org, Catalin Marinas , Palmer Dabbelt , Will Deacon , Russell King , Ralf Baechle , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Luis Chamberlain , Paul Burton , Paul Walmsley , James Hogan , linux-riscv@lists.infradead.org, linux-mips@vger.kernel.org, Christoph Hellwig , linux-arm-kernel@lists.infradead.org, Alexander Viro References: <20190808061756.19712-1-alex@ghiti.fr> <20190808061756.19712-10-alex@ghiti.fr> From: Alexandre Ghiti Message-ID: <91e31484-b268-2c90-1dd1-98cec349af6c@ghiti.fr> Date: Fri, 9 Aug 2019 11:44:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: fr Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/8/19 11:16 AM, Sergei Shtylyov wrote: > Hello! > > On 08.08.2019 9:17, 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 arm here: >> https://lkml.kernel.org/r/20170622200033.25714-1-riel@redhat.com >> >> Signed-off-by: Alexandre Ghiti >> Acked-by: Kees Cook >> Acked-by: Paul Burton >> Reviewed-by: Luis Chamberlain >> --- >>   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 d79f2b432318..f5c778113384 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) > >    Could add spaces around *, while touching this anyway? And parens > around TASK_SIZE shouldn't be needed... > I did not fix checkpatch warnings here since this code gets removed afterwards. >> +#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); > >    Parens not needed here. Belt and braces approach here as I'm never sure about priorities. Thanks for your time, Alex > >> + >> +    /* Values close to RLIM_INFINITY can overflow. */ >> +    if (gap + pad > gap) >> +        gap += pad; >>         if (gap < MIN_GAP) >>           gap = MIN_GAP; >> > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv