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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 8A56DC32756 for ; Fri, 9 Aug 2019 09:44:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6CD0A2171F for ; Fri, 9 Aug 2019 09:44:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405888AbfHIJoq (ORCPT ); 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-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@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