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: <89ae59de-5b74-22b6-0076-c1a9a6fa62e7@redhat.com>
Date:   Wed, 9 Mar 2022 08:37:26 +0100
From:   David Hildenbrand <david@...hat.com>
To:     John Hubbard <jhubbard@...dia.com>,
        Jason Gunthorpe <jgg@...dia.com>
Cc:     linux-kernel@...r.kernel.org,
        Andrew Morton <akpm@...ux-foundation.org>,
        Hugh Dickins <hughd@...gle.com>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        David Rientjes <rientjes@...gle.com>,
        Shakeel Butt <shakeelb@...gle.com>,
        Mike Kravetz <mike.kravetz@...cle.com>,
        Mike Rapoport <rppt@...ux.ibm.com>,
        Yang Shi <shy828301@...il.com>,
        "Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
        Matthew Wilcox <willy@...radead.org>,
        Vlastimil Babka <vbabka@...e.cz>, Jann Horn <jannh@...gle.com>,
        Michal Hocko <mhocko@...nel.org>,
        Nadav Amit <namit@...are.com>, Rik van Riel <riel@...riel.com>,
        Roman Gushchin <guro@...com>,
        Andrea Arcangeli <aarcange@...hat.com>,
        Peter Xu <peterx@...hat.com>,
        Donald Dutile <ddutile@...hat.com>,
        Christoph Hellwig <hch@....de>,
        Oleg Nesterov <oleg@...hat.com>, Jan Kara <jack@...e.cz>,
        Liang Zhang <zhangliang5@...wei.com>,
        Pedro Gomes <pedrodemargomes@...il.com>,
        Oded Gabbay <oded.gabbay@...il.com>, linux-mm@...ck.org
Subject: Re: [PATCH RFC 12/13] mm/gup: trigger FAULT_FLAG_UNSHARE when
 R/O-pinning a possibly shared anonymous page

On 03.03.22 09:06, David Hildenbrand wrote:
> On 03.03.22 02:47, John Hubbard wrote:
>> On 3/2/22 12:38, David Hildenbrand wrote:
>> ...
>>> BUT, once we actually write to the private mapping via the page table,
>>> the GUP pin would go out of sync with the now-anonymous page mapped into
>>> the page table. However, I'm having a hard time answering what's
>>> actually expected?
>>>
>>> It's really hard to tell what the user wants with MAP_PRIVATE file
>>> mappings and stumbles over a !anon page (no modifications so far):
>>>
>>> (a) I want a R/O pin to observe file modifications.
>>> (b) I want the R/O pin to *not* observe file modifications but observe
>>>      my (eventual? if any) private modifications,
>>>
>>
>> On this aspect, I think it is easier than trying to discern user
>> intentions. Because it is less a question of what the user wants, and
>> more a question of how mmap(2) is specified. And the man page clearly
>> indicates that the user has no right to expect to see file
>> modifications. Here's the excerpt:
>>
>> "MAP_PRIVATE
>> 	
>> Create  a private copy-on-write mapping.  Updates to the mapping are not
>> visible to other processes mapping the same file, and are not carried
>> through to the underlying file.  It is unspecified whether changes  made
>> to the file after the mmap() call are visible in the mapped region.
>> "
>>
>>> Of course, if we already wrote to that page and now have an anon page,
>>> it's easy: we are already no longer following file changes.
>>
>> Yes, and in fact, I've always thought that the way this was written
>> means that it should be treated as a snapshot of the file contents,
>> and no longer reliably connected in either direction to the page(s).
> 
> Thanks John, that's extremely helpful. I forgot about these MAP_PRIVATE
> mmap() details -- they help a lot to clarify which semantics to provide.
> 
> So what we could do is:
> 
> a) Extend FAULT_FLAG_UNSHARE to also unshare an !anon page in
>    a MAP_RPIVATE mapping, replacing it with an (exclusive) anon page.
>    R/O PTE permissions are maintained, just like unsharing in the
>    context of this series.
> 
> b) Similarly trigger FAULT_FLAG_UNSHARE from GUP when trying to take a
>    R/O pin (FOLL_PIN) on a R/O-mapped !anon page in a MAP_PRIVATE
>    mapping.
> 
> c) Make R/O pins consistently use "FOLL_PIN" instead, getting rid of
>    FOLL_FORCE|FOLL_WRITE.
> 
> 
> Of course, we can't detect MAP_PRIVATE vs. MAP_SHARED in GUP-fast (no
> VMA), so we'd always have to fallback in GUP-fast in case we intend to
> FOLL_PIN a R/O-mapped !anon page. That would imply that essentially any
> R/O pins (FOLL_PIN) would have to fallback to ordinary GUP. BUT, I mean
> we require FOLL_FORCE|FOLL_WRITE right now, which is not any different,
> so ...
> 
> One optimization would be to trigger b) only for FOLL_LONGTERM. For
> !FOLL_LONGTERM there are "in theory" absolutely no guarantees which data
> will be observed if we modify concurrently to e.g., O_DIRECT IMHO. But
> that would require some more thought.
> 
> Of course, that's all material for another journey, although it should
> be mostly straight forward.
> 

Just a slight clarification after stumbling over shared zeropage code in
follow_page_pte(): we do seem to support pinning the shared zeropage at
least on the GUP-slow path. While I haven't played with it, I assume
we'd have to implement+trigger unsharing in case we'd want to take a R/O
pin on the shared zeropage.

Of course, similar to file-backed MAP_PRIVATE handling, this is out of
the scope of this series ("This change implies that whenever user space
wrote to a private mapping (IOW, we have an anonymous page mapped), that
GUP pins will
always remain consistent: reliable R/O GUP pins of anonymous pages.").

-- 
Thanks,

David / dhildenb

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ