Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752833AbdLMMWb (ORCPT ); Wed, 13 Dec 2017 07:22:31 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:51293 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751853AbdLMMWa (ORCPT ); Wed, 13 Dec 2017 07:22:30 -0500 Date: Wed, 13 Dec 2017 13:22:11 +0100 From: Peter Zijlstra To: Andy Lutomirski Cc: Thomas Gleixner , LKML , X86 ML , Linus Torvalds , Dave Hansen , Borislav Petkov , Greg KH , Kees Cook , Hugh Dickins , Brian Gerst , Josh Poimboeuf , Denys Vlasenko , Boris Ostrovsky , Juergen Gross , David Laight , Eduardo Valentin , aliguori@amazon.com, Will Deacon , "linux-mm@kvack.org" , kirill.shutemov@linux.intel.com, aneesh.kumar@linux.vnet.ibm.com Subject: Re: [patch 05/16] mm: Allow special mappings with user access cleared Message-ID: <20171213122211.bxcb7xjdwla2bqol@hirez.programming.kicks-ass.net> References: <20171212173221.496222173@linutronix.de> <20171212173333.669577588@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1513 Lines: 42 On Tue, Dec 12, 2017 at 10:00:08AM -0800, Andy Lutomirski wrote: > On Tue, Dec 12, 2017 at 9:32 AM, Thomas Gleixner wrote: > > From: Peter Zijstra > > > > In order to create VMAs that are not accessible to userspace create a new > > VM_NOUSER flag. This can be used in conjunction with > > install_special_mapping() to inject 'kernel' data into the userspace map. > > > > Similar to how arch_vm_get_page_prot() allows adding _PAGE_flags to > > pgprot_t, introduce arch_vm_get_page_prot_excl() which masks > > _PAGE_flags from pgprot_t and use this to implement VM_NOUSER for x86. > > How does this interact with get_user_pages(), etc? So I went through that code and I think I found a bug related to this. get_user_pages_fast() will ultimately end up doing pte_access_permitted() before getting the page, follow_page OTOH does not do this, which makes for a curious difference between the two. So I'm thinking we want the below irrespective of the VM_NOUSER patch, but with VM_NOUSER it would mean write(2) will no longer be able to access the page. diff --git a/mm/gup.c b/mm/gup.c index dfcde13f289a..b852f37a2b0c 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -153,6 +153,11 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, } if (flags & FOLL_GET) { + if (!pte_access_permitted(pte, !!(flags & FOLL_WRITE))) { + page = ERR_PTR(-EFAULT); + goto out; + } + get_page(page); /* drop the pgmap reference now that we hold the page */