Re: [PATCH v1] mm/gup: fix FOLL_FORCE COW security issue and remove FOLL_COW

From: David Hildenbrand
Date: Tue Aug 09 2022 - 15:22:04 EST


On 09.08.22 21:07, Linus Torvalds wrote:
> On Tue, Aug 9, 2022 at 11:48 AM Jason Gunthorpe <jgg@xxxxxxxxxx> wrote:
>>
>> It is because of all this madness with COW.
>
> Yes, yes, but we have the proper long-term pinning now with
> PG_anon_exclusive, and it actually gets the pinning right not just
> over COW, but even over a fork - which that early write never did.
>
> David, I thought all of that got properly merged? Is there something
> still missing?

The only thing to get R/O longterm pins in MAP_PRIVATE correct that's
missing is that we have to break COW when taking a R/O longterm pin when
*not* finding an anon page inside a private mapping. Regarding anon
pages I am not aware of issues (due to PG_anon_exclusive).

If anybody here wants to stare at a webpage, the following commit
explains the rough idea for MAP_PRIVATE:

https://github.com/davidhildenbrand/linux/commit/cd7989fb76d2513c86f01e6f7a74415eee5d3150

Once we have that in place, we can mostly get rid of
FOLL_FORCE|FOLL_WRITE for R/O longterm pins. There are some corner cases
though that need some additional thought which i am still working on.
FS-handled COW in MAP_SHARED mappings is just nasty (hello DAX).

(the wrong use of FOLL_GET instead of FOLL_PIN for O_DIRECT and friends
still persists, but that's a different thing to handle and it's only
problematic with concurrent fork() IIRC)

--
Thanks,

David / dhildenb