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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED 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 57D20C282DF for ; Fri, 19 Apr 2019 19:01:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F5B320643 for ; Fri, 19 Apr 2019 19:01:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728841AbfDSTBL (ORCPT ); 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 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=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED 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 B0525C282DA for ; Fri, 19 Apr 2019 07:21:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 83DEA21736 for ; Fri, 19 Apr 2019 07:21:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="F15Vlq4k" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83DEA21736 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+infradead-linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:References: To:Subject:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GzPZExCpgvsoGffgE9aRYoe+Ozd+CI5ys9ngtkxilv4=; b=F15Vlq4kyToQq5B9cctZjlR8Q /rlv2hdqvwY2hJYSsjI6PUpXcwvVya2nA8QfuQ3oUNNeGUOzqBVa+Wo4gCwdsGM9OA5fwig8q6RD3 nMf7kz5RlEy/aEjejSrGq/OGk5igydmQt57cPyJiIyfmOq8fxFBKTS3auvYHUyty9z9A/3gvLG1cj NYOyb6A26/wTri+k1KhiPSa5XXB9QJuPyYawIjaYcPKuyFNHia4voS+XmbH9CEwxZrtEJ0N8AhPD2 pyUyV3hrD5F9179Ohb4QM9Uvon32Wvuob6NKf9CTnyV0gg+rY6jEgUgCtmVhlu0ZTHXYDQrUeV0lF jBGM5TZvA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hHNqA-0006Yk-AG; Fri, 19 Apr 2019 07:21:42 +0000 Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hHNq2-0006Sq-6v; Fri, 19 Apr 2019 07:21:36 +0000 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 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-Language: fr X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190419_002134_404394_2282432D X-CRM114-Status: GOOD ( 18.79 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 , Alexander Viro , James Hogan , "linux-fsdevel@vger.kernel.org" , "linux-riscv@lists.infradead.org" , "linux-mips@vger.kernel.org" , Christoph Hellwig , Andrew Morton , "linux-arm-kernel@lists.infradead.org" Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+infradead-linux-riscv=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 2E7B4C282DA for ; Fri, 19 Apr 2019 07:21:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E11802183F for ; Fri, 19 Apr 2019 07:21:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E11802183F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5B2896B0269; Fri, 19 Apr 2019 03:21:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5633A6B026A; Fri, 19 Apr 2019 03:21:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42BFA6B026B; Fri, 19 Apr 2019 03:21:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id E44F56B0269 for ; Fri, 19 Apr 2019 03:21:24 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id o8so2466838edh.12 for ; Fri, 19 Apr 2019 00:21:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:subject :to:cc:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=bnQSy0WtCB7Cu0qsokQqvclK8aEJwCrIiNI51qlDWjY=; b=dZ1S8yi+9x0ZRJFW2BNZE7mv9X34CYhyloJpmyQMY3IdvZrlRpeQ4IU/iggeou3Tsi RZ4SQYIlEDX4+0sNSY7pXpvLeBM9Sb07+GIcJhJ+lUfhZh+D4j/syafSm0o1p7JmEbln axam2d42jzFkc1/1lLctNiVn2+vR3CLiLDH7MPh36ysKZFp5Wu3cKUHdW71Z1JGbuuIz rQvfQHA38Bp8iFMukMbcLJ3oh0gEJf31t3XKRhH/HxHuCpfnFQDZEaBlvDSIUfbvyKe6 hvqqkXpd747w7IzGGpbICZErSRIi/s0njHq0Lp7Rul+OABO8Qk8e9ffE+PbyHV1Uj2av liQA== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr X-Gm-Message-State: APjAAAVhZquw63mFSNWksq5kWpGIoDfl/GepOnuLtimERuKC1d/EpE7p jDBO1GaXoh2zJwSm7Z1dC7rAccMXmtldBivZqBsz7Mv3V7pv2Pv79k2/KKvG+GUFtoUlFT8EYhH /92eeKYvBs0WLg39MLvqCUU5xYLybIoNehrNmCW2jSwMca/3DlDyA5bsn5thKICk= X-Received: by 2002:a50:cc89:: with SMTP id q9mr1382853edi.257.1555658484505; Fri, 19 Apr 2019 00:21:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsAsjmzgjOQg0YaBq6UxXn9hAOmMEMYnMnWYwP1KJSVc/AMyFYqc3NL7NskiXWf1qZdUtn X-Received: by 2002:a50:cc89:: with SMTP id q9mr1382809edi.257.1555658483551; Fri, 19 Apr 2019 00:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555658483; cv=none; d=google.com; s=arc-20160816; b=aDjuMughCquqr1Tsj2Nbq7Vfj8u0faNJyNZa22+2KgSQVwr6T4IY3FjZk+e12gKOtF L36SpsocD82PZp4ghpuWRSP5EvIj8dG5Tv7K8Ao6G1e/ermj791/XpyCEhCrxTaIVc59 A9h0QrPJx5CwFu6PHKZQ1xRIVkVzS+PmeMDFpbCGd/gYEdPKznG9woJoMZE++Eb4gGKE BiCGUFy3sfp6ZO/s4KqLvAXiV1qRpg37RyGZAuyabNbizp00PBxtKrvBlr13x6YT+f69 a1uN+mx7KFEN5fmoif1zYVNTon7AtqMUZC868Oiq9out9Pcb91y/dZXwfOyHY8sSmyl8 XVyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:subject:from; bh=bnQSy0WtCB7Cu0qsokQqvclK8aEJwCrIiNI51qlDWjY=; b=XXilWec61hiPqZh5GbW7KlJgdgUNqHc1/fPRdyPr4U0QyUnN94/Tj6IF+k0BQnTNG8 kroqUp1nFOx3gC1ifd3YgigwfzUfAvDayA4hYnluTB8UZPbQ5aas5KG8cNOfb11v+ZLP H++08NN0icPqofZJoYIoFqUrmjZRXhxio0jSUzrRNwkrMDAYP9KmuvQSX2MUAyyyZRHB BspLa0SScBQxCTmSOH3xsIBM7xUNaXLrzL8lA5Oc9A6yMm0SsnSkRMrXKGANmOYzy6zY I62mkQYxTWh6IR0Oj4Me/KRWEgUZSBLoaqAUH7blOQ6f1GeKbk1ydvhkBRKAmzIZD0hc j5tQ== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net. [217.70.183.195]) by mx.google.com with ESMTPS id c44si2033896ede.368.2019.04.19.00.21.23 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Apr 2019 00:21:23 -0700 (PDT) Received-SPF: neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) client-ip=217.70.183.195; Authentication-Results: mx.google.com; spf=neutral (google.com: 217.70.183.195 is neither permitted nor denied by best guess record for domain of alex@ghiti.fr) smtp.mailfrom=alex@ghiti.fr 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 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=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED 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 F2F28C282DA for ; Fri, 19 Apr 2019 07:21:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C487021736 for ; Fri, 19 Apr 2019 07:21:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FCtj/SSh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C487021736 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:References: To:Subject:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LpCu+Bhsv5y655GrxeOFSavITKIkcxv6+UsQgf3n8WQ=; b=FCtj/SShrj7JVgTDLQS+4LVJB eV7Vy3XChlgl1GmkhN2BqW4bkNOvNassUQW1Td9/M+oVCteoIoZqKQ3Jq87XxUmY0tZM3guNAXQKc b5s/Ow5g1DxGBgA4vQsUQCynwHOBzrkUc0B7FNm9blf7SLIvjj/m642/6blkdO7bPQl6BNQ6/aCwi 9JS8ii1vE+uKogAnsEALlMv2HYe6LMV8dpESB0tkW7uVP9ODyoMv14TTLa+xE103v7dTw987iC2Cg Qq1oyuJz57HAjp8SLeOTz8pQmzIrYdESnXCRRyR25gQRAGc6ukbKgksVdIXSOpmEC04WAhg4UqcQ1 JSxvHWTdQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hHNq5-0006TX-VC; Fri, 19 Apr 2019 07:21:37 +0000 Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hHNq2-0006Sq-6v; Fri, 19 Apr 2019 07:21:36 +0000 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 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-Language: fr X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190419_002134_404394_2282432D X-CRM114-Status: GOOD ( 18.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 , Alexander Viro , James Hogan , "linux-fsdevel@vger.kernel.org" , "linux-riscv@lists.infradead.org" , "linux-mips@vger.kernel.org" , Christoph Hellwig , Andrew Morton , "linux-arm-kernel@lists.infradead.org" Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel