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.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 EB9A5C433FF for ; Thu, 8 Aug 2019 09:17:16 +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 A402D2171F for ; Thu, 8 Aug 2019 09:17:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HvE8wf3S"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cogentembedded-com.20150623.gappssmtp.com header.i=@cogentembedded-com.20150623.gappssmtp.com header.b="Z1XISyDm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A402D2171F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cogentembedded.com 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:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JWFJaqmQyEK1gBWT677xJjh++Gk4UwxI2PS9zWm3UCw=; b=HvE8wf3SJO0ioaLWVZDnis5MV +mcfOP2zaytPgI5EiAAk+Q9pYU5RtHnz9Gq+ZjAY6nL/2lko0fZePvJzIZASc2EfgByFD+1gOtO1V yZ9PfOYiu2udZwR+CYoKU+wncDMnqSx6MBLOYo/Ow7XSuIE01Is51YTHFcEcS44CV1LWv0lEnKOYz kLOrijnggdse8bYwlvrdcnYXzkYb5zzFm7+BVoOPKUyPSWAW7wZjNiP1A32/deTn9nW7hhA4CtgO8 H7wsmu/dGNeCDGp76DDd/AnZtG79SEH1ywgmq0LX7WtyngA0Ja4J5lZJFw+ILhi0SqUXzIVBKpLO0 wIfgmmAlQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hveXs-0006ER-3A; Thu, 08 Aug 2019 09:17:16 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hveX0-0005q9-CW for linux-arm-kernel@lists.infradead.org; Thu, 08 Aug 2019 09:16:25 +0000 Received: by mail-lf1-x142.google.com with SMTP id x3so66386050lfc.0 for ; Thu, 08 Aug 2019 02:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=M0Lkp7TI/1lX0PjPf1h84OWxjj1q7OPrwwtMkQUMB80=; b=Z1XISyDmNMrKzhH5jpoXRm+UDpftCfPHsXSHiMp386hpt6qzA47mI+MZCjhh8/Zeyw jokbLjILXaPIhi16o8/c61dqditvR/MIYHeLbkQyQnW1HIi9UnftiHokpg6qK507fm7J Af4qYSS1b0OGvvXKHezXLIVBZAA22zNmMLXIgrCO7kd7HL9v99JBKOfmG2a8I4SKpTHT bYqs+AyT4ajWAbpBYl2QGZEPQO6YYKHDcpVDFpxR617xywNAkq8MTsHvEe09qcGQm0N/ Q2SBZWzsoeIcTUgNNHs8jSQHhyhyqyNLDF5nH869msJXyFVwIVvvUIWwVSw8UZZBa3BW /xHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=M0Lkp7TI/1lX0PjPf1h84OWxjj1q7OPrwwtMkQUMB80=; b=d0WLKzj7yLv7FC5OcRTALLLcYRtAWGWryvDfaVpvNnC33kfM1uj9+XTWHTDhOxYax2 rojpWv/KnjaRQ04h/9lyAkQXAkieDROKvyAGQ9UE4U6winW8U3vuKMoEbUorBxgteNJ6 8wT6J2LEttuMj5a5iDFdI9oWGhdtacXsP3rYF+KXa1WL+jTLW4jxqmfO7M9zwOxWsvt0 bt7swjamta70hdn/EKbimaSMLcYT143bd3+rJ3SBYms9fwMLID2RvGiCZrIFw/eGXSVO YQBG4b1LME9UUsizMmUQOk6i0UaaW65g5qVv5Y7d/yXjSy49NCIj3yL6L64yumFUE08o voPw== X-Gm-Message-State: APjAAAUvaB7DgG+wKRkAVqAKKoZIC5oJB5EtkL4EONaJ1lvo8x6CtZ1m 0v9g1r/9275C/koioeQEeuX3Vw== X-Google-Smtp-Source: APXvYqwAZY8WXCeiGX2n+XECYEd8x3LcF9hNec57wPu9uZBuLdOygGHP8AmFYhQOUjDhlaSnPEqcXw== X-Received: by 2002:a19:c711:: with SMTP id x17mr8605646lff.147.1565255778647; Thu, 08 Aug 2019 02:16:18 -0700 (PDT) Received: from ?IPv6:2a00:1fa0:8c7:ada9:25b2:24d8:3973:eb87? ([2a00:1fa0:8c7:ada9:25b2:24d8:3973:eb87]) by smtp.gmail.com with ESMTPSA id f23sm406561lfc.25.2019.08.08.02.16.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 02:16:17 -0700 (PDT) Subject: Re: [PATCH v6 09/14] mips: Properly account for stack randomization and stack guard gap To: Alexandre Ghiti , Andrew Morton References: <20190808061756.19712-1-alex@ghiti.fr> <20190808061756.19712-10-alex@ghiti.fr> From: Sergei Shtylyov Message-ID: Date: Thu, 8 Aug 2019 12:16:04 +0300 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190808061756.19712-10-alex@ghiti.fr> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190808_021622_990145_3C0144C7 X-CRM114-Status: GOOD ( 18.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 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 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... > +#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. > + > + /* Values close to RLIM_INFINITY can overflow. */ > + if (gap + pad > gap) > + gap += pad; > > if (gap < MIN_GAP) > gap = MIN_GAP; > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel