lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210120170439.GP1106298@kernel.org>
Date:   Wed, 20 Jan 2021 19:04:39 +0200
From:   Mike Rapoport <rppt@...nel.org>
To:     Matthew Wilcox <willy@...radead.org>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        Alexander Viro <viro@...iv.linux.org.uk>,
        Andy Lutomirski <luto@...nel.org>,
        Arnd Bergmann <arnd@...db.de>, Borislav Petkov <bp@...en8.de>,
        Catalin Marinas <catalin.marinas@....com>,
        Christopher Lameter <cl@...ux.com>,
        Dan Williams <dan.j.williams@...el.com>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        David Hildenbrand <david@...hat.com>,
        Elena Reshetova <elena.reshetova@...el.com>,
        "H. Peter Anvin" <hpa@...or.com>, Ingo Molnar <mingo@...hat.com>,
        James Bottomley <jejb@...ux.ibm.com>,
        "Kirill A. Shutemov" <kirill@...temov.name>,
        Mark Rutland <mark.rutland@....com>,
        Mike Rapoport <rppt@...ux.ibm.com>,
        Michael Kerrisk <mtk.manpages@...il.com>,
        Palmer Dabbelt <palmer@...belt.com>,
        Paul Walmsley <paul.walmsley@...ive.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Rick Edgecombe <rick.p.edgecombe@...el.com>,
        Roman Gushchin <guro@...com>,
        Shakeel Butt <shakeelb@...gle.com>,
        Shuah Khan <shuah@...nel.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        Tycho Andersen <tycho@...ho.ws>, Will Deacon <will@...nel.org>,
        linux-api@...r.kernel.org, linux-arch@...r.kernel.org,
        linux-arm-kernel@...ts.infradead.org,
        linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
        linux-nvdimm@...ts.01.org, linux-riscv@...ts.infradead.org,
        x86@...nel.org, Hagen Paul Pfeifer <hagen@...u.net>
Subject: Re: [PATCH v14 05/10] mm: introduce memfd_secret system call to
 create "secret" memory areas

On Wed, Jan 20, 2021 at 04:02:10PM +0000, Matthew Wilcox wrote:
> On Wed, Jan 20, 2021 at 05:05:10PM +0200, Mike Rapoport wrote:
> > On Tue, Jan 19, 2021 at 08:22:13PM +0000, Matthew Wilcox wrote:
> > > On Thu, Dec 03, 2020 at 08:29:44AM +0200, Mike Rapoport wrote:
> > > > +static vm_fault_t secretmem_fault(struct vm_fault *vmf)
> > > > +{
> > > > +	struct address_space *mapping = vmf->vma->vm_file->f_mapping;
> > > > +	struct inode *inode = file_inode(vmf->vma->vm_file);
> > > > +	pgoff_t offset = vmf->pgoff;
> > > > +	vm_fault_t ret = 0;
> > > > +	unsigned long addr;
> > > > +	struct page *page;
> > > > +	int err;
> > > > +
> > > > +	if (((loff_t)vmf->pgoff << PAGE_SHIFT) >= i_size_read(inode))
> > > > +		return vmf_error(-EINVAL);
> > > > +
> > > > +	page = find_get_page(mapping, offset);
> > > > +	if (!page) {
> > > > +
> > > > +		page = secretmem_alloc_page(vmf->gfp_mask);
> > > > +		if (!page)
> > > > +			return vmf_error(-ENOMEM);
> > > 
> > > Just use VM_FAULT_OOM directly.
> >  
> > Ok.
> > 
> > > > +		err = add_to_page_cache(page, mapping, offset, vmf->gfp_mask);
> > > > +		if (unlikely(err))
> > > > +			goto err_put_page;
> > > 
> > > What if the error is EEXIST because somebody else raced with you to add
> > > a new page to the page cache?
> > 
> > Right, for -EEXIST I need a retry here, thanks.
> > 
> > > > +		err = set_direct_map_invalid_noflush(page, 1);
> > > > +		if (err)
> > > > +			goto err_del_page_cache;
> > > 
> > > Does this work correctly if somebody else has a reference to the page
> > > in the meantime?
> > 
> > Yes, it does. If somebody else won the race that page was dropped from the
> > direct map and this call would be essentially a nop. And anyway, the very
> > next patch changes the way pages are removed from the direct map ;-)
> 
> What I'm thinking is:
> 
> thread A page faults
> doesn't find page
> allocates page
> adds page to page cache
> 				thread B page faults
> 				does find page in page cache
> set direct map invalid fails
> deletes from page cache
> 				... ?

Hmm, this is not nice indeed...

-- 
Sincerely yours,
Mike.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ