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=-17.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 F306DC433EF for ; Thu, 16 Sep 2021 13:30:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 704AF61241 for ; Thu, 16 Sep 2021 13:30:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 704AF61241 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 05EC06B0071; Thu, 16 Sep 2021 09:30:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00F28900002; Thu, 16 Sep 2021 09:30:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E18826B0073; Thu, 16 Sep 2021 09:30:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id D3CB46B0071 for ; Thu, 16 Sep 2021 09:30:42 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 854B7181D303C for ; Thu, 16 Sep 2021 13:30:42 +0000 (UTC) X-FDA: 78593521524.29.8EF01FD Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf05.hostedemail.com (Postfix) with ESMTP id 9EF9B505C66F for ; Thu, 16 Sep 2021 13:30:41 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 6146E60555; Thu, 16 Sep 2021 13:30:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631799040; bh=SnqLVt+EJ1bHNkv2hdNN4FVTS5b7LZ1LwuXCb4PcRGk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MIOB7bFP2CbmttTqr5DCx0WbVlqgMeI5Unl5ebLD/NwtWpAAvAZCD4lNSBa8enCAA GGJGzhkht2XLNC5F8H+0nGLiL2KTRe82wH6DV2zB4eT7pBYk6ap13OCekWLn51jagT oyhQRe2po1TKuA9Xv5Dg+oOpbb8M2++GbRJHaZadMBjxJlv3BHy8TrdZd3p45qfbNU cFtkTpj7owzNRYVhC2mQdNeyWyAYte9VD1CBQW3g1uiquy0pdh+cVKpOnTLSV84fE/ zW0WKA1sKZSWVenXuqzidhm/MsqfyPib+UV0iznhsUM24EcNDbG8PHtpf3AHBLxwK7 oNMrectuEEsdA== Date: Thu, 16 Sep 2021 14:30:36 +0100 From: Will Deacon To: Peter Zijlstra Cc: Andrew Morton , Christoph Hellwig , andreyknvl@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Mel Gorman , keescook@chromium.org Subject: Re: [PATCH] mm/vmalloc: Don't allow VM_NO_GUARD on vmap() Message-ID: <20210916133035.GA8888@willie-the-truck> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=MIOB7bFP; spf=pass (imf05.hostedemail.com: domain of will@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=will@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9EF9B505C66F X-Stat-Signature: yjpu8haymjg16zf37x7k87u8rf4akqye X-HE-Tag: 1631799041-817842 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 Thu, Sep 16, 2021 at 12:41:56PM +0200, Peter Zijlstra wrote: > > The vmalloc guard pages are added on top of each allocation, thereby > isolating any two allocations from one another. The top guard of the > lower allocation is the bottom guard guard of the higher allocation > etc. > > Therefore VM_NO_GUARD is dangerous; it breaks the basic premise of > isolating separate allocations. > > There are only two in-tree users of this flag, neither of which use it > through the exported interface. Ensure it stays this way. > > Signed-off-by: Peter Zijlstra (Intel) > --- > include/linux/vmalloc.h | 2 +- > mm/vmalloc.c | 7 +++++++ > 2 files changed, 8 insertions(+), 1 deletion(-) > > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h > index 671d402c3778..10e9571ff0b2 100644 > --- a/include/linux/vmalloc.h > +++ b/include/linux/vmalloc.h > @@ -22,7 +22,7 @@ struct notifier_block; /* in notifier.h */ > #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */ > #define VM_DMA_COHERENT 0x00000010 /* dma_alloc_coherent */ > #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */ > -#define VM_NO_GUARD 0x00000040 /* don't add guard page */ > +#define VM_NO_GUARD 0x00000040 /* ***DANGEROUS*** don't add guard page */ > #define VM_KASAN 0x00000080 /* has allocated kasan shadow memory */ > #define VM_FLUSH_RESET_PERMS 0x00000100 /* reset direct map and flush TLB on unmap, can't be freed in atomic context */ > #define VM_MAP_PUT_PAGES 0x00000200 /* put pages and free array in vfree */ > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index d77830ff604c..01927ebea267 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -2743,6 +2743,13 @@ void *vmap(struct page **pages, unsigned int count, > > might_sleep(); > > + /* > + * Your top guard is someone else's bottom guard. Not having a top > + * guard compromises someone else's mappings too. > + */ > + if (WARN_ON_ONCE(flags & VM_NO_GUARD)) > + flags &= ~VM_NO_GUARD; > + > if (count > totalram_pages()) > return NULL; Acked-by: Will Deacon Thanks! Will